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.
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 |
# 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)) 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
59 60 61 62 63 64 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 59 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
66 67 68 69 70 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 66 def get_type(slug) return nil if slug.blank? content_type_repository.by_slug(slug) end |
#logger ⇒ Object
72 73 74 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 72 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 44 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 |