Sha256: 7f5637be6eca9449812d2d5e824e79beee672ebc512f55fa6f43ea6bd3c38655

Contents?: true

Size: 1.48 KB

Versions: 31

Compression:

Stored size: 1.48 KB

Contents

module Locomotive::Wagon

  class PushContentTypesCommand < PushBaseCommand

    attr_reader :step

    alias_method :default_push, :_push

    def _push
      %i(without_relationships only_relationships).each do |step|
        @step = step
        default_push
      end
    end

    def entities
      repositories.content_type.all
    end

    def decorate(entity)
      if without_relationships?
        ContentTypeDecorator.new(entity, remote_fields_for(entity.slug))
      else
        ContentTypeWithOnlyRelationshipsDecorator.new(entity)
      end
    end

    def persist(decorated_entity)
      raise SkipPersistingException if only_relationships? && !decorated_entity.with_relationships?

      api_client.content_types.update(decorated_entity.slug, decorated_entity.to_hash)
    end

    def label_for(decorated_entity)
      name = decorated_entity.name

      if without_relationships?
        name
      else
        "#{name} with relationships"
      end
    end

    private

    def remote_fields_for(slug)
      (remote_entities[slug].try(:fields) || []).map { |f| f['name'] }
    end

    def remote_entities
      return @remote_entities if @remote_entities

      @remote_entities = {}.tap do |hash|
        api_client.content_types.all.each do |entity|
          hash[entity.slug] = entity
        end
      end
    end

    def without_relationships?
      self.step == :without_relationships
    end

    def only_relationships?
      self.step == :only_relationships
    end

  end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
locomotivecms_wagon-3.0.0.beta2 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.4.1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.4.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.4.0.rc2 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.4.0.rc1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.3.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.3.0.rc1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.2.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.2.0.rc3 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.2.0.rc2 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.2.0.rc1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.2.0.beta1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.1.1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.1.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.1.0.rc5 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.1.0.rc4 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.1.0.rc3 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.0.1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.0.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-2.0.0.rc8 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb