lib/surrealist/builder.rb
# A method that goes recursively through the schema hash, defines the values and type-checks them.
#
# @param [Hash] schema the schema defined in the object's class.
# @param [Object] instance the instance of the object which methods from the schema are called on.
#
# @raise +Surrealist::UndefinedMethodError+ if a key defined in the schema
#   does not have a corresponding method on the object.
#
# @return [Hash] a hash that will be dumped into JSON.
A method that goes recursively through the schema hash, defines the values and type-checks them.
A method that goes recursively through the schema hash defines the values and type - checks them .
def call(schema = @schema, instance = @instance)
      schema.each do |schema_key, schema_value|
        if schema_value.is_a?(Hash)
          check_for_ar(schema, instance, schema_key, schema_value)
        else
          ValueAssigner.assign(Schema.new(schema_key, schema_value),
                               instance) { |coerced_value| schema[schema_key] = coerced_value }
        end
      end
    rescue NoMethodError => e
      Surrealist::ExceptionRaiser.raise_invalid_key!(e)
    end
def call ( schema = @schema , instance = @instance ) schema . each do | schema_key , schema_value | if schema_value . is_a? ( Hash ) check_for_ar ( schema , instance , schema_key , schema_value ) else ValueAssigner . assign ( Schema . new ( schema_key , schema_value ) , instance ) { | coerced_value | schema [ schema_key ] = coerced_value } end end rescue NoMethodError => e Surrealist :: ExceptionRaiser . raise_invalid_key! ( e ) end
A method that goes recursively through the schema hash, defines the values and type-checks them.
A method that goes recursively through the schema hash defines the values and type - checks them .
a hash that will be dumped into JSON.
a hash that will be dumped into JSON .
Hash
+Surrealist::UndefinedMethodError+ if a key defined in the schema does not have a corresponding method on the object.
+ Surrealist :: UndefinedMethodError + if a key defined in the schema does not have a corresponding method on the object .
schema
<not_specific>
instance
<not_specific>
<not_specific>
instance the instance of the object which methods from the schema are called on.
instance the instance of the object which methods from the schema are called on .