Sha256: b3d26a42f2557e342c6cb12554910714680c2d1b83276ed2f4232ac3304acee2

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

module Granite
  module Form
    module Model
      module Attributes
        module Reflections
          class Base
            class BuildTypeDefinition
              attr_reader :owner, :reflection

              delegate :name, to: :reflection

              def initialize(owner, reflection)
                @owner = owner
                @reflection = reflection
              end

              def call
                raise "Type is not specified for `#{name}`" if type.nil?

                type_definition_for(type)
              end

              private

              def type
                reflection.options[:type]
              end

              def type_definition_for(type)
                type = type.to_s.camelize.constantize unless type.is_a?(Module)
                Granite::Form.type_for(type).new(type, reflection, owner)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
granite-form-0.6.0 lib/granite/form/model/attributes/reflections/base/build_type_definition.rb