Module: Parametric::DSL::ClassMethods
- Defined in:
- lib/parametric/dsl.rb
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
- #parametric_after_define_schema(sc) ⇒ Object
- #schema(*args, &block) ⇒ Object
- #schema=(sc) ⇒ Object
- #schemas=(sc) ⇒ Object
Instance Method Details
#inherited(subclass) ⇒ Object
41 42 43 44 45 |
# File 'lib/parametric/dsl.rb', line 41 def inherited(subclass) subclass.schemas = @schemas.each_with_object({}) do |(key, sc), hash| hash[key] = sc.merge(Parametric::Schema.new) end end |
#parametric_after_define_schema(sc) ⇒ Object
63 64 65 |
# File 'lib/parametric/dsl.rb', line 63 def parametric_after_define_schema(sc) # noop hook end |
#schema(*args, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/parametric/dsl.rb', line 47 def schema(*args, &block) = args.last.is_a?(Hash) ? args.last : {} key = args.first.is_a?(Symbol) ? args.first : DEFAULT_SCHEMA_NAME current_schema = @schemas.fetch(key) { Parametric::Schema.new } new_schema = if block_given? || .any? Parametric::Schema.new(, &block) elsif args.first.respond_to?(:schema) args.first end return current_schema unless new_schema @schemas[key] = current_schema ? current_schema.merge(new_schema) : new_schema parametric_after_define_schema(@schemas[key]) end |
#schema=(sc) ⇒ Object
33 34 35 |
# File 'lib/parametric/dsl.rb', line 33 def schema=(sc) @schemas[DEFAULT_SCHEMA_NAME] = sc end |
#schemas=(sc) ⇒ Object
37 38 39 |
# File 'lib/parametric/dsl.rb', line 37 def schemas=(sc) @schemas = sc end |