Class: Locomotive::Steam::ContentType
- Inherits:
-
Object
- Object
- Locomotive::Steam::ContentType
show all
- Extended by:
- Forwardable
- Includes:
- Models::Entity
- Defined in:
- lib/locomotive/steam/entities/content_type.rb
Instance Attribute Summary
#associations, #attributes, #base_url, #localized_attributes
Instance Method Summary
collapse
#[], #[]=, #_id, #change, #method_missing, #respond_to?, #serialize
#as_json, #to_hash, #to_json
#errors, #valid?
Constructor Details
#initialize(attributes = {}) ⇒ ContentType
Returns a new instance of ContentType.
14
15
16
17
18
19
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 14
def initialize(attributes = {})
super({
order_by: '_position',
order_direction: 'asc'
}.merge(attributes))
end
|
Instance Method Details
#field_label_of(name) ⇒ Object
55
56
57
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 55
def field_label_of(name)
fields_by_name[name].label.downcase
end
|
#fields ⇒ Object
21
22
23
24
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 21
def fields
self.entries_custom_fields
end
|
#fields_by_name ⇒ Object
26
27
28
29
30
31
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 26
def fields_by_name
@fields_by_name ||= (fields.all.inject({}) do |memo, field|
memo[field.name] = field
memo
end).with_indifferent_access
end
|
#label_field_name ⇒ Object
51
52
53
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 51
def label_field_name
(self[:label_field_name] || fields.first.name).to_sym
end
|
#localized? ⇒ Boolean
38
39
40
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 38
def localized?
!fields.localized_names.blank?
end
|
#localized_names ⇒ Object
33
34
35
36
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 33
def localized_names
fields.localized_names + select_fields.map(&:name)
end
|
#order_by ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 59
def order_by
name = self[:order_by] == 'manually' ? '_position' : self[:order_by]
if field = fields.find(name)
name = field.name
end
{ name.to_sym => self.order_direction.to_s }
end
|
#persisted_field_names ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/locomotive/steam/entities/content_type.rb', line 42
def persisted_field_names
[].tap do |names|
fields_by_name.each do |name, field|
_name = field.persisted_name
names << _name if _name
end
end
end
|