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
- #build(type_slug, attributes) ⇒ 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 |
#build(type_slug, attributes) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 27 def build(type_slug, attributes) with_repository(type_slug) do |_repository| _attributes = prepare_attributes(_repository.content_type, attributes) entry = _repository.build(_attributes) i18n_decorate { entry } end end |
#create(type_slug, attributes, as_json = false) ⇒ Object
Warning: do not work with localized and file fields
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 38 def create(type_slug, attributes, as_json = false) with_repository(type_slug) do |_repository| _attributes = prepare_attributes(_repository.content_type, attributes) entry = _repository.build(_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
91 92 93 94 95 96 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 91 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
98 99 100 101 102 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 98 def get_type(slug) return nil if slug.blank? content_type_repository.by_slug(slug) end |
#logger ⇒ Object
104 105 106 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 104 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 59 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) _attributes = prepare_attributes(_repository.content_type, attributes) decorated_entry = i18n_decorate { entry.change(_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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/locomotive/steam/services/content_entry_service.rb', line 76 def update_decorated_entry(decorated_entry, attributes) with_repository(decorated_entry.content_type) do |_repository| entry = decorated_entry.__getobj__ _attributes = prepare_attributes(_repository.content_type, attributes) entry.change(_attributes) _repository.update(entry) logEntryOperation(decorated_entry.content_type.slug, decorated_entry) decorated_entry end end |