Module: Paradocs::DSL

Defined in:
lib/paradocs/dsl.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Example

class Foo
  include Paradocs::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}


26
27
28
29
# File 'lib/paradocs/dsl.rb', line 26

def self.included(base)
  base.extend(ClassMethods)
  base.schemas = {Paradocs.config.default_schema_name => Paradocs::Schema.new}
end