Class: Locomotive::API::Entities::ContentEntryEntity

Inherits:
BaseEntity
  • Object
show all
Defined in:
app/api/locomotive/api/entities/content_entry_entity.rb

Instance Method Summary collapse

Instance Method Details

#content_typeObject


82
83
84
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 82

def content_type
  self.object.content_type
end

#dynamic_fieldsObject


25
26
27
28
29
30
31
32
33
34
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 25

def dynamic_fields
  content_type.entries_custom_fields.inject({}) do |hash, field|
    name        = field.name.to_sym
    method_name = :"expose_#{field.type}_field"

    hash[name] = send(method_name, name) if respond_to?(method_name)

    hash
  end
end

#dynamic_value_of(name) ⇒ Object


78
79
80
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 78

def dynamic_value_of(name)
  self.object.send(name)
end

#expose_belongs_to_field(name) ⇒ Object


66
67
68
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 66

def expose_belongs_to_field(name)
  dynamic_value_of(name).try(:_slug)
end

#expose_date_time_field(name) ⇒ Object Also known as: expose_date_field


52
53
54
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 52

def expose_date_time_field(name)
  instance_exec(dynamic_value_of(name), &formatters[:iso_timestamp])
end

#expose_default_field(name) ⇒ Object Also known as: expose_string_field, expose_text_field, expose_boolean_field, expose_email_field, expose_integer_field, expose_float_field, expose_tags_field


36
37
38
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 36

def expose_default_field(name)
  dynamic_value_of(name)
end

#expose_file_field(name) ⇒ Object


58
59
60
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 58

def expose_file_field(name)
  dynamic_value_of(:"#{name}_url")
end

#expose_json_field(name) ⇒ Object


74
75
76
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 74

def expose_json_field(name)
  expose_default_field(name).try(:to_json)
end

#expose_many_to_many_field(name) ⇒ Object


70
71
72
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 70

def expose_many_to_many_field(name)
  dynamic_value_of(name).pluck_with_natural_order(:_slug)
end

#expose_money_field(name) ⇒ Object


48
49
50
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 48

def expose_money_field(name)
  dynamic_value_of(:"formatted_#{name}")
end

#expose_select_field(name) ⇒ Object


62
63
64
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 62

def expose_select_field(name)
  dynamic_value_of(name)
end

#serializable_hash(runtime_options = {}) ⇒ Object


19
20
21
22
23
# File 'app/api/locomotive/api/entities/content_entry_entity.rb', line 19

def serializable_hash(runtime_options = {})
  (super || {}).dup.tap do |hash|
    hash.merge!(hash.delete(:dynamic_fields) || hash.delete('dynamic_fields') || {})
  end
end