Class: Locomotive::ContentAssetService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Locomotive::Concerns::ActivityService

#track_activity, #without_tracking_activity

Instance Attribute Details

#accountObject

Returns the value of attribute account

Returns:

  • (Object)

    the current value of account


2
3
4
# File 'app/services/locomotive/content_asset_service.rb', line 2

def 
  @account
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of site


2
3
4
# File 'app/services/locomotive/content_asset_service.rb', line 2

def site
  @site
end

Instance Method Details

#bulk_create(list) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/locomotive/content_asset_service.rb', line 16

def bulk_create(list)
  list = list.values if list.is_a?(Hash)

  assets = list.map do |params|
    site.content_assets.create(params)
  end

  valid_assets = assets.map { |a| a.errors.empty? ? { name: a.source_filename, url: a.source.url, image: a.image?, id: a._id } : nil }.compact
  track_activity 'content_asset.created_bulk', parameters: { assets: valid_assets } unless valid_assets.empty?

  assets
end

#destroy(asset) ⇒ Object


29
30
31
32
33
# File 'app/services/locomotive/content_asset_service.rb', line 29

def destroy(asset)
  asset.destroy.tap do
    track_activity 'content_asset.destroyed', parameters: { name: asset.source_filename }
  end
end

#list(options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'app/services/locomotive/content_asset_service.rb', line 6

def list(options = {})
  options[:per_page] ||= Locomotive.config.ui[:per_page]

  site.content_assets
    .ordered
    .by_content_types(options[:types])
    .by_filename(options[:query])
    .page(options[:page] || 1).per(options[:per_page])
end