Sha256: 2e1f935a6ecfa292db8ff2029b1e6b4114b606788be25dc2480d90448154943b

Contents?: true

Size: 1.48 KB

Versions: 11

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.new 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

11 entries across 11 versions & 1 rubygems

Version Path
locomotivecms_wagon-3.2.0.alpha2 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.2.0.alpha1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.1.1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.1.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.1.0.beta1 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.0.5 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.0.4 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.0.3 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.0.2 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.0.0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb
locomotivecms_wagon-3.0.0.rc0 lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb