Module: Parametric::DSL

Defined in:
lib/parametric/dsl.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_SCHEMA_NAME =

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}
:schema

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



29
30
31
32
# File 'lib/parametric/dsl.rb', line 29

def self.included(base)
  base.extend(ClassMethods)
  base.schemas = {DEFAULT_SCHEMA_NAME => Parametric::Schema.new}
end