Class: Locomotive::ContentAssetService
Instance Attribute Summary collapse
Instance Method Summary
collapse
#track_activity, #without_tracking_activity
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account
2
3
4
|
# File 'app/services/locomotive/content_asset_service.rb', line 2
def account
@account
end
|
#site ⇒ Object
Returns the value of attribute 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
20
21
22
23
24
25
26
27
28
29
|
# File 'app/services/locomotive/content_asset_service.rb', line 20
def bulk_create(list)
list = list.values if list.is_a?(Hash)
assets = list.map { |params| create_or_update(params) }
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
|
#create(params) ⇒ Object
16
17
18
|
# File 'app/services/locomotive/content_asset_service.rb', line 16
def create(params)
create_or_update(params)
end
|
#destroy(asset) ⇒ Object
31
32
33
34
35
|
# File 'app/services/locomotive/content_asset_service.rb', line 31
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
|