Class: ActForm::Schema::Base
- Inherits:
- 
      Object
      
        - Object
- ActForm::Schema::Base
 
- Defined in:
- lib/act_form/schema/base.rb
Overview
rubocop:disable Style/Documentation
Instance Attribute Summary collapse
- 
  
    
      #ins  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute ins. 
Instance Method Summary collapse
- 
  
    
      #each  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    rubocop:disable Metrics/AbcSize. 
- 
  
    
      #initialize(*parents, &block)  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Base. 
- #validate(attrs) ⇒ Object
Constructor Details
#initialize(*parents, &block) ⇒ Base
Returns a new instance of Base.
| 8 9 10 11 12 13 14 | # File 'lib/act_form/schema/base.rb', line 8 def initialize(*parents, &block) parent_arr = parents.map(&:contract) @ins = ::Dry::Schema.Params(parent: parent_arr, &block) @json = @ins.json_schema(loose: true) @defaults = @ins.schema_dsl.defaults @descriptions = @ins.schema_dsl.descriptions end | 
Instance Attribute Details
#ins ⇒ Object (readonly)
Returns the value of attribute ins.
| 6 7 8 | # File 'lib/act_form/schema/base.rb', line 6 def ins @ins end | 
Instance Method Details
#each ⇒ Object
rubocop:disable Metrics/AbcSize
| 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # File 'lib/act_form/schema/base.rb', line 16 def each # rubocop:disable Metrics/AbcSize @ins.key_map.each do |key| name = key.name.to_sym opts = { required: @json[:required].include?(key.name) } opts[:default] = @defaults[name] if @defaults.key?(name) t = @json[:properties].dig(name, :type) t = if t.is_a?(Array) :object else t ? t.to_sym : :object end opts[:type] = t yield name, opts end end | 
#validate(attrs) ⇒ Object
| 34 35 36 37 38 | # File 'lib/act_form/schema/base.rb', line 34 def validate(attrs) _attrs = {}.merge!(attrs) _attrs.merge!(@defaults) @ins.call(_attrs) end |