Class: Locomotive::PageService
- Inherits:
-
Struct
- Object
- Struct
- Locomotive::PageService
- Includes:
- Concerns::ActivityService
- Defined in:
- app/services/locomotive/page_service.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#create(attributes) ⇒ Object
Create a page from the attributes passed in parameter.
- #destroy(page) ⇒ Object
-
#localize(locales, previous_default_locale) ⇒ Object
For all the pages of a site, use the slug property from the default locale for all the new locales passed as the first argument.
- #sort(page, children) ⇒ Object
-
#update(page, attributes) ⇒ Object
Update a page from the attributes passed in parameter.
Methods included from Concerns::ActivityService
#track_activity, #without_tracking_activity
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account
3 4 5 |
# File 'app/services/locomotive/page_service.rb', line 3 def account @account end |
#locale ⇒ Object
Returns the value of attribute locale
3 4 5 |
# File 'app/services/locomotive/page_service.rb', line 3 def locale @locale end |
#site ⇒ Object
Returns the value of attribute site
3 4 5 |
# File 'app/services/locomotive/page_service.rb', line 3 def site @site end |
Instance Method Details
#create(attributes) ⇒ Object
Create a page from the attributes passed in parameter. It sets the created_by column with the current account.
14 15 16 17 18 19 20 21 22 |
# File 'app/services/locomotive/page_service.rb', line 14 def create(attributes) site.pages.build(attributes).tap do |page| page.created_by = account if account if page.save track_activity 'page.created', parameters: { title: page.title, _id: page._id } end end end |
#destroy(page) ⇒ Object
49 50 51 52 53 |
# File 'app/services/locomotive/page_service.rb', line 49 def destroy(page) page.destroy.tap do track_activity 'page.destroyed', parameters: { title: page.title } end end |
#localize(locales, previous_default_locale) ⇒ Object
For all the pages of a site, use the slug property from the default locale for all the new locales passed as the first argument. Do not erase existing values in the new locales. This method is called when an user has changed the locales of a site.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/locomotive/page_service.rb', line 60 def localize(locales, previous_default_locale) parent_fullpaths = {} default_locale = previous_default_locale || site.default_locale site.pages.without_sorting.order_by(:depth.asc).each_by(50) do |page| _localize(page, locales, default_locale, parent_fullpaths) page.skip_callbacks_on_update = true page.save if page.changed? end end |
#sort(page, children) ⇒ Object
24 25 26 27 28 |
# File 'app/services/locomotive/page_service.rb', line 24 def sort(page, children) page.sort_children!(children).tap do track_activity 'page.sorted', parameters: { title: page.title, _id: page._id } end end |
#update(page, attributes) ⇒ Object
Update a page from the attributes passed in parameter. It sets the updated_by column with the current account.
38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/locomotive/page_service.rb', line 38 def update(page, attributes) page.tap do page.attributes = attributes page.updated_by = account if account if page.save track_activity 'page.updated', locale: locale, parameters: { title: page.title, _id: page._id } end end end |