Module: Parametric::DSL

Defined in:
lib/parametric/dsl.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Example

class Foo
  include Parametric::DSL

  schema do
    field(:title).type(:string).present
    field(:age).type(:integer).default(20)
  end

   attr_reader :params

   def initialize(input)
     @params = self.class.schema.resolve(input)
   end
end

foo = Foo.new(title: "A title", nope: "hello")

foo.params # => {title: "A title", age: 20}


25
26
27
28
# File 'lib/parametric/dsl.rb', line 25

def self.included(base)
  base.extend(ClassMethods)
  base.schema = Parametric::Schema.new
end