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.
11
12
13
14
15
16
17
18
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 11
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
28
29
30
31
32
33
34
35
36
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 28
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.
9
10
11
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 9
def content_type
@content_type
end
|
Instance Method Details
#_class_name ⇒ Object
58
59
60
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 58
def _class_name
"Locomotive::ContentEntry#{content_type_id}"
end
|
#_id ⇒ Object
20
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 20
def _id; self[:_id] || self[:id]; end
|
#_label ⇒ Object
62
63
64
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 62
def _label
self[content_type.label_field_name]
end
|
#_slug ⇒ Object
Also known as:
_permalink
25
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 25
def _slug; self[:_slug]; end
|
#_visible? ⇒ Boolean
Also known as:
visible?
22
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 22
def _visible?; !!self[:_visible]; end
|
#content_type_id ⇒ Object
50
51
52
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 50
def content_type_id
@content_type.try(&:_id) || attributes[:content_type_id]
end
|
#content_type_slug ⇒ Object
54
55
56
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 54
def content_type_slug
content_type.slug
end
|
#localized_attributes ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 66
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
74
75
76
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 74
def serialize
super.merge(content_type_id: content_type_id)
end
|
#to_hash ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 78
def to_hash
hash = {}
_attributes = %i(_id _slug _label _visible _position content_type_slug created_at updated_at)
_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
38
39
40
41
42
43
44
|
# File 'lib/locomotive/steam/entities/content_entry.rb', line 38
def valid?
errors.clear
content_type.fields.required.each do |field|
errors.add_on_blank(field.name.to_sym)
end
errors.empty?
end
|