Sha256: c9131a7f23b0ffbd0813479189b63b18c5fabeff280f7f8f5cb6da98044b519a

Contents?: true

Size: 1.52 KB

Versions: 17

Compression:

Stored size: 1.52 KB

Contents

module Locomotive
  module Wagon

    class ContentTypeFieldDecorator < SimpleDelegator

      include ToHashConcern

      def initialize(entity, persisted = false)
        @persisted = persisted
        super(entity)
      end

      def __attributes__
        %i(name type label hint required localized unique position
          text_formatting select_options
          target inverse_of order_by ui_enabled default)
      end

      def type
        self[:type]
      end

      def hint
        self[:hint]
      end

      def position
        self[:position]
      end

      def text_formatting
        self[:text_formatting]
      end

      def target
        return nil unless is_relationship?
        self.target_id
      end

      def inverse_of
        return nil unless is_relationship?
        self[:inverse_of]
      end

      def order_by
        return nil unless is_relationship?
        self[:order_by]
      end

      def ui_enabled
        return nil if self[:ui_enabled].nil?
        self[:ui_enabled]
      end

      def select_options
        return nil if type.to_sym != :select || @persisted

        @_select_options ||= __getobj__.select_options.all.map { |o| SelectOptionDecorator.new(o) }
      end

      class SelectOptionDecorator < SimpleDelegator

        include ToHashConcern

        def __attributes__
          %i(name)
        end

        def name
          translations = __getobj__.name.translations
          translations.empty? ? translations[:any] : translations
        end

      end

    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
locomotivecms_wagon-2.4.1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.4.0 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.4.0.rc2 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.4.0.rc1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.3.0 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.3.0.rc1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.2.0 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.2.0.rc3 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.2.0.rc2 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.2.0.rc1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.2.0.beta1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.1.1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.1.0 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.1.0.rc5 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.1.0.rc4 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.1.0.rc3 lib/locomotive/wagon/decorators/content_type_field_decorator.rb
locomotivecms_wagon-2.0.1 lib/locomotive/wagon/decorators/content_type_field_decorator.rb