Sha256: adaa5a0b20930fb0e6b94cd97ebe547df69a901cb80902a05ae00b0331245ac9

Contents?: true

Size: 1.33 KB

Versions: 44

Compression:

Stored size: 1.33 KB

Contents

require 'tempfile'

module Locomotive::Wagon

  class PushContentAssetsCommand < PushBaseCommand

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

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

    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

    def same?(decorated_entity, remote_entity)
      remote_entity.try(:checksum) == decorated_entity.checksum
    end

    def remote_entity(local_entity)
      remote_entities[local_entity.filename]
    end

    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

  end

end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
locomotivecms_wagon-3.2.0.alpha2 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.2.0.alpha1 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.1.1 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.1.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.1.0.beta1 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.5 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.4 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.3 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.2 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.0.rc0 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-3.0.0.beta2 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.4.1 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.4.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.4.0.rc2 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.4.0.rc1 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.3.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.3.0.rc1 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.2.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb
locomotivecms_wagon-2.2.0.rc3 lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb