lib/surrealist/class_methods.rb
# A DSL method to delegate schema in a declarative style. Must reference a valid
# class that includes Surrealist
#
# @param [Class] klass
#
# @example DSL usage example
#   class Host
#     include Surrealist
#
#     json_schema do
#       { name: String }
#     end
#
#     def name
#       'Parent'
#     end
#   end
#
#   class Guest < Host
#     delegate_surrealization_to Host
#
#     def name
#       'Child'
#     end
#   end
#
#   Guest.new.surrealize
#   # => "{\"name\":\"Child\"}"
#   # For more examples see README
A DSL method to delegate schema in a declarative style. Must reference a valid
class that includes Surrealist
A DSL method to delegate schema in a declarative style . Must reference a valid class that includes Surrealist
def delegate_surrealization_to(klass)
      raise TypeError, "Expected type of Class got #{klass.class} instead" unless klass.is_a?(Class)
      Surrealist::ExceptionRaiser.raise_invalid_schema_delegation! unless Helper.surrealist?(klass)
      hash = Surrealist::VarsHelper.find_schema(klass)
      Surrealist::VarsHelper.set_schema(self, hash)
    end
def delegate_surrealization_to ( klass ) raise TypeError , "Expected type of Class got #{klass.class} instead" unless klass . is_a? ( Class ) Surrealist :: ExceptionRaiser . raise_invalid_schema_delegation! unless Helper . surrealist? ( klass ) hash = Surrealist :: VarsHelper . find_schema ( klass ) Surrealist :: VarsHelper . set_schema ( self , hash ) end
A DSL method to delegate schema in a declarative style.
A DSL method to delegate schema in a declarative style .
klass
<not_specific>
<not_specific>
None
example
DSL usage example class Host include Surrealist json_schema do { name: String } end def name 'Parent' end end class Guest < Host delegate_surrealization_to Host def name 'Child' end end Guest.new.surrealize # => "{\"name\":\"Child\"}" # For more examples see README
DSL usage example class Host include Surrealist json_schema do { name : String } end def name ' Parent ' end end class Guest < Host delegate_surrealization_to Host def name ' Child ' end end Guest . new . surrealize # = > " { \ " name \ " : \ " Child \ " } " # For more examples see README