Class: Locomotive::PageService

Inherits:
Struct
  • Object
show all
Includes:
Concerns::ActivityService
Defined in:
app/services/locomotive/page_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::ActivityService

#track_activity, #without_tracking_activity

Instance Attribute Details

#accountObject

Returns the value of attribute account

Returns:

  • (Object)

    the current value of account



3
4
5
# File 'app/services/locomotive/page_service.rb', line 3

def 
  @account
end

#localeObject

Returns the value of attribute locale

Returns:

  • (Object)

    the current value of locale



3
4
5
# File 'app/services/locomotive/page_service.rb', line 3

def locale
  @locale
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • attributes (Hash)

    The attributes of new page.

Returns:

  • (Object)

    An instance of the page.



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 =  if 

    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.

Parameters:

  • entry (Object)

    The page to update.

  • attributes (Hash)

    The attributes of new page.

Returns:

  • (Object)

    The instance of the page.



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 =  if 

    if page.save
      track_activity 'page.updated', locale: locale, parameters: { title: page.title, _id: page._id }
    end
  end
end