1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- class ObjectManager::Object
- attr_reader :object_name
- def initialize(object_name)
- @object_name = object_name
- end
- def attributes(user, record = nil, data_only: true, skip_permission: false)
- @attributes ||= begin
- attribute_records.each_with_object([]) do |attribute_record, result|
- element = element_class.new(
- user: user,
- attribute: attribute_record,
- record: record,
- skip_permission: skip_permission,
- )
- next if !element.visible?
- if data_only
- result.push element.data
- else
- result.push element
- end
- end
- end
- end
- private
- def attribute_records
- @attribute_records ||= begin
- Auth::RequestCache.fetch_value("ObjectManager::Object/attribute_records/#{object}") do
- ObjectManager::Attribute.where(
- object_lookup_id: object,
- active: true,
- to_create: false,
- to_delete: false,
- ).reorder('position ASC, name ASC')
- end
- end
- end
- def object
- @object ||= ObjectLookup.by_name(object_name)
- end
- def element_class
- @element_class ||= ObjectManager::Element.for_object(object_name)
- end
- end
|