Sha256: 24351ac211e997c8b1018c61ec5900eb15d72fb2567b8bb86052e6c2759dad8f

Contents?: true

Size: 786 Bytes

Versions: 14

Compression:

Stored size: 786 Bytes

Contents

module Rasti
  class Form
    module Types
      class Form

        include Castable

        attr_reader :form_class

        def self.[](*args)
          new *args
        end

        def to_s
          "#{self.class}[#{form_class}]"
        end
        alias_method :inspect, :to_s

        private

        def initialize(form)
          @form_class = case
            when form.is_a?(::Hash) then Rasti::Form[form]
            when form.is_a?(Class) && form.ancestors.include?(Rasti::Form) then form
            else raise ArgumentError, "Invalid form specification: #{form.inspect}"
          end
        end

        def valid?(value)
          value.is_a? ::Hash
        end

        def transform(value)
          form_class.new value
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rasti-form-3.1.2 lib/rasti/form/types/form.rb
rasti-form-3.1.1 lib/rasti/form/types/form.rb
rasti-form-3.1.0 lib/rasti/form/types/form.rb
rasti-form-3.0.0 lib/rasti/form/types/form.rb
rasti-form-2.2.0 lib/rasti/form/types/form.rb
rasti-form-2.1.0 lib/rasti/form/types/form.rb
rasti-form-2.0.0 lib/rasti/form/types/form.rb
rasti-form-1.1.1 lib/rasti/form/types/form.rb
rasti-form-1.1.0 lib/rasti/form/types/form.rb
rasti-form-1.0.3 lib/rasti/form/types/form.rb
rasti-form-1.0.2 lib/rasti/form/types/form.rb
rasti-form-1.0.1 lib/rasti/form/types/form.rb
rasti-form-1.0.0 lib/rasti/form/types/form.rb
rasti-form-0.1.0 lib/rasti/form/types/form.rb