class Locomotive::Wagon::PushContentAssetsCommand

Public Class Methods

new(api_client, steam_services) click to toggle source
Calls superclass method
# 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

Public Instance Methods

decorate(local_path) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

remote_entities() click to toggle source
# File lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb, line 42
def remote_entities
  return @remote_entities if @remote_entities

  @remote_entities = {}.tap do |hash|
    api_client.content_assets.all.each do |entity|
      hash[entity.full_filename] = entity
    end
  end
end
remote_entity(local_entity) click to toggle source
# File lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb, line 38
def remote_entity(local_entity)
  remote_entities[local_entity.filename]
end
same?(decorated_entity, remote_entity) click to toggle source
# File lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb, line 34
def same?(decorated_entity, remote_entity)
  remote_entity.try(:checksum) == decorated_entity.checksum
end