Class: Locomotive::Steam::ContentEntryService
- Inherits:
-
Object
- Object
- Locomotive::Steam::ContentEntryService
- Includes:
- Services::Concerns::Decorator
- Defined in:
- lib/locomotive/steam/services/content_entry_service.rb
Instance Method Summary collapse
- #all(type_slug, conditions = {}, as_json = false) ⇒ Object
-
#create(type_slug, attributes, as_json = false) ⇒ Object
Warning: do not work with localized and file fields.
- #delete(type_slug, id_or_slug) ⇒ Object
- #find(type_slug, id_or_slug, as_json = false) ⇒ Object
- #get_type(slug) ⇒ Object
- #logger ⇒ Object
-
#update(type_slug, id_or_slug, attributes, as_json = false) ⇒ Object
Warning: do not work with localized and file fields.
- #update_decorated_entry(decorated_entry, attributes) ⇒ Object
Instance Method Details
#all(type_slug, conditions = {}, as_json = false) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 12 def all(type_slug, conditions = {}, as_json = false) with_repository(type_slug) do |_repository| _repository.all(conditions).map do |entry| _decorate(entry, as_json) end end end |
#create(type_slug, attributes, as_json = false) ⇒ Object
Warning: do not work with localized and file fields
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 28 def create(type_slug, attributes, as_json = false) with_repository(type_slug) do |_repository| entry = _repository.build(clean_attributes(attributes)) yield(entry) if block_given? decorated_entry = i18n_decorate { entry } if validate(_repository, decorated_entry) _repository.create(entry) end logEntryOperation(type_slug, decorated_entry) _json_decorate(decorated_entry, as_json) end end |
#delete(type_slug, id_or_slug) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 76 def delete(type_slug, id_or_slug) with_repository(type_slug) do |_repository| entry = _repository.by_slug(id_or_slug) || _repository.find(id_or_slug) _repository.delete(entry) end end |
#find(type_slug, id_or_slug, as_json = false) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 20 def find(type_slug, id_or_slug, as_json = false) with_repository(type_slug) do |_repository| entry = _repository.by_slug(id_or_slug) || _repository.find(id_or_slug) _decorate(entry, as_json) end end |
#get_type(slug) ⇒ Object
83 84 85 86 87 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 83 def get_type(slug) return nil if slug.blank? content_type_repository.by_slug(slug) end |
#logger ⇒ Object
89 90 91 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 89 def logger Locomotive::Common::Logger end |
#update(type_slug, id_or_slug, attributes, as_json = false) ⇒ Object
Warning: do not work with localized and file fields
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 47 def update(type_slug, id_or_slug, attributes, as_json = false) with_repository(type_slug) do |_repository| entry = _repository.by_slug(id_or_slug) || _repository.find(id_or_slug) decorated_entry = i18n_decorate { entry.change(clean_attributes(attributes)) } if validate(_repository, decorated_entry) _repository.update(entry) end logEntryOperation(type_slug, decorated_entry) _json_decorate(decorated_entry, as_json) end end |
#update_decorated_entry(decorated_entry, attributes) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 62 def update_decorated_entry(decorated_entry, attributes) with_repository(decorated_entry.content_type) do |_repository| entry = decorated_entry.__getobj__ entry.change(clean_attributes(attributes)) _repository.update(entry) logEntryOperation(decorated_entry.content_type.slug, decorated_entry) decorated_entry end end |