Class: Locomotive::Wagon::ContentEntryDecorator
- Inherits:
-
Steam::Decorators::I18nDecorator
- Object
- Steam::Decorators::I18nDecorator
- Locomotive::Wagon::ContentEntryDecorator
show all
- Includes:
- PersistAssetsConcern, ToHashConcern
- Defined in:
- lib/locomotive/wagon/decorators/content_entry_decorator.rb
Constant Summary
collapse
- DEFAULT_ATTRIBUTES =
%i(_slug seo_title meta_keywords meta_description).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
#asset_io, #replace_with_content_assets!, #replace_with_content_assets_in_hash!
#prepare_value_for_hash
Constructor Details
#initialize(object, locale = nil, base_path, content_assets_pusher) ⇒ ContentEntryDecorator
Returns a new instance of ContentEntryDecorator.
13
14
15
16
17
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 13
def initialize(object, locale = nil, base_path, content_assets_pusher)
self.__base_path__ = base_path
self.__content_assets_pusher__ = content_assets_pusher
super(object, locale, nil)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 31
def method_missing(name, *args, &block)
if field = fields.by_name(name.to_s)
method_name = :"decorate_#{field.type}_field"
respond_to?(method_name) ? send(method_name, super) : super
else
super
end
end
|
Instance Attribute Details
#__base_path__ ⇒ Object
Returns the value of attribute base_path.
9
10
11
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 9
def __base_path__
@__base_path__
end
|
#__content_assets_pusher__ ⇒ Object
Returns the value of attribute content_assets_pusher.
9
10
11
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 9
def __content_assets_pusher__
@__content_assets_pusher__
end
|
Instance Method Details
#__attributes__ ⇒ Object
27
28
29
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 27
def __attributes__
DEFAULT_ATTRIBUTES + fields.no_associations.map { |f| f.name.to_sym }
end
|
#_id ⇒ Object
23
24
25
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 23
def _id
__getobj__[:remote_id] || self._slug
end
|
#_id=(id) ⇒ Object
19
20
21
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 19
def _id=(id)
__getobj__[:remote_id] = id
end
|
#decorate_date_field(value) ⇒ Object
54
55
56
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 54
def decorate_date_field(value)
value.try(:iso8601)
end
|
#decorate_date_time_field(value) ⇒ Object
Also known as:
decorate_time_field
49
50
51
52
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 49
def decorate_date_time_field(value)
return nil if value.nil?
value.utc.try(:iso8601)
end
|
#decorate_file_field(value) ⇒ Object
44
45
46
47
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 44
def decorate_file_field(value)
return nil if value.nil? || value.filename.blank?
asset_io(File.join(value.base, value.filename))
end
|
#decorate_json_field(value) ⇒ Object
58
59
60
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 58
def decorate_json_field(value)
value.to_json
end
|
#decorate_text_field(value) ⇒ Object
40
41
42
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 40
def decorate_text_field(value)
replace_with_content_assets!(value)
end
|
#to_hash ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/locomotive/wagon/decorators/content_entry_decorator.rb', line 64
def to_hash
if (hash = super).keys == DEFAULT_ATTRIBUTES
{}
else
hash
end
end
|