Sha256: 5e5e5d45405b92e011853903d519ee17a2831d7517f7e4da632e03b4b2af0f8e

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

module Locomotive::Steam

  class ContentTypeField

    include Locomotive::Steam::Models::Entity

    attr_accessor :content_type

    def initialize(attributes = {})
      super({
        type:       :string,
        localized:  false,
        required:   false,
        unique:     false
      }.merge(attributes))
    end

    def type
      self[:type].try(:to_sym)
    end

    def class_name
      self[:class_name] || self[:target]
    end

    def order_by
      if (order_by = self[:order_by]).present?
        name, direction = order_by.split
        { name.to_sym => direction || 'asc' }
      else
        type == :has_many ? { :"position_in_#{self[:inverse_of]}" => 'asc' } : nil
      end
    end

    alias :target :class_name

    def target_id
      return @target_id if @target_id

      @target_id = if self.target =~ Locomotive::Steam::CONTENT_ENTRY_ENGINE_CLASS_NAME
        $1
      else
        self.target
      end
    end

    def required?; self[:required]; end
    def localized?; self[:localized]; end

    def association_options
      {
        target_id:  target_id,
        inverse_of: self[:inverse_of],
        order_by:   order_by
      }
    end

    def is_relationship?
      %i(belongs_to has_many many_to_many).include?(self.type)
    end

    class SelectOption

      include Locomotive::Steam::Models::Entity

      attr_accessor :field

      def name
        self[:name]
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/entities/content_type_field.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/entities/content_type_field.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/entities/content_type_field.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/entities/content_type_field.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/entities/content_type_field.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/entities/content_type_field.rb