Class: Locomotive::Wagon::PushContentAssetsCommand

Inherits:
PushBaseCommand
  • Object
show all
Defined in:
lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb

Instance Attribute Summary

Attributes inherited from PushBaseCommand

#api_client, #content_assets_pusher, #filter, #remote_site, #steam_services

Instance Method Summary collapse

Methods inherited from PushBaseCommand

#_push, #_push_with_timezone, #default_locale, #instrument, #locales, #only, #path, push, #push, #resource_name, #with_data, #with_data?

Constructor Details

#initialize(api_client, steam_services) ⇒ PushContentAssetsCommand

Returns a new instance of PushContentAssetsCommand.



7
8
9
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb', line 7

def initialize(api_client, steam_services)
  super(api_client, steam_services, nil)
end

Instance Method Details

#decorate(local_path) ⇒ Object



11
12
13
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb', line 11

def decorate(local_path)
  ContentAssetDecorator.new(File.join(path, 'public', local_path))
end

#persist(local_path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb', line 15

def persist(local_path)
  decorated_entity = decorate(local_path)

  if (_entity = remote_entity(decorated_entity)).nil?
    _entity = api_client.content_assets.create(decorated_entity.to_hash)

    # make sure it does not get created a second time if the same file is used in another resource
    remote_entities[decorated_entity.filename] = _entity
  else
    unless same?(decorated_entity, _entity)
      api_client.content_assets.update(_entity._id, decorated_entity.to_hash)
    end
  end

  _entity.url
end