Class: Locomotive::Steam::ContentEntry
- Inherits:
-
Object
- Object
- Locomotive::Steam::ContentEntry
show all
- Includes:
- Models::Entity
- Defined in:
- lib/locomotive/steam/entities/content_entry.rb
Defined Under Namespace
Classes: FileField
Instance Attribute Summary collapse
#associations, #attributes, #base_url
Instance Method Summary
collapse
#[], #[]=, #change, #respond_to?
#as_json, #to_json
#errors
Constructor Details
#initialize(attributes = {}) ⇒ ContentEntry
Returns a new instance of ContentEntry.
12
13
14
15
16
17
18
19
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 12
def initialize(attributes = {})
super({
_visible: true,
_position: 0,
created_at: Time.zone.now,
updated_at: Time.zone.now
}.merge(attributes))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 29
def method_missing(name, *args, &block)
if is_dynamic_attribute?(name)
cast_value(name)
elsif attributes.include?(name)
self[name]
else
super
end
end
|
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
10
11
12
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 10
def content_type
@content_type
end
|
Instance Method Details
#_class_name ⇒ Object
59
60
61
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 59
def _class_name
"Locomotive::ContentEntry#{content_type_id}"
end
|
#_id ⇒ Object
21
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 21
def _id; self[:_id] || self[:id]; end
|
#_label ⇒ Object
63
64
65
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 63
def _label
self[content_type.label_field_name]
end
|
#_label_of(name) ⇒ Object
67
68
69
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 67
def _label_of(name)
content_type.field_label_of(name)
end
|
#_slug ⇒ Object
Also known as:
_permalink
26
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 26
def _slug; self[:_slug]; end
|
#_visible? ⇒ Boolean
Also known as:
visible?
23
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 23
def _visible?; !!self[:_visible]; end
|
#content_type_id ⇒ Object
51
52
53
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 51
def content_type_id
@content_type.try(&:_id) || attributes[:content_type_id]
end
|
#content_type_slug ⇒ Object
55
56
57
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 55
def content_type_slug
content_type.slug
end
|
#localized_attributes ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 71
def localized_attributes
@localized_attributes.tap do |hash|
if hash && hash.has_key?(content_type.label_field_name.to_sym)
hash[:_label] = true
end
end
end
|
#serialize ⇒ Object
79
80
81
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 79
def serialize
super.merge(content_type_id: content_type_id)
end
|
#to_hash ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 83
def to_hash
hash = {}
_attributes = %i(_id _slug _visible _position content_type_slug created_at updated_at)
unless content_type.fields_by_name[content_type.label_field_name].is_relationship?
_attributes << :_label
end
_attributes += content_type.persisted_field_names
_attributes.each do |name|
hash[name.to_s] = send(name) rescue nil
end
hash['errors'] = self.errors.to_hash.stringify_keys unless self.errors.empty?
hash
end
|
#valid? ⇒ Boolean
39
40
41
42
43
44
45
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 39
def valid?
errors.clear
content_type.fields.required.each do |field|
errors.add_on_blank(field.name.to_sym)
end
errors.empty?
end
|