Class: Attributor::HashDSLCompiler

Inherits:
DSLCompiler show all
Defined in:
lib/attributor/hash_dsl_compiler.rb

Defined Under Namespace

Classes: Requirement, RequiresDSL

Instance Attribute Summary

Attributes inherited from DSLCompiler

#options, #target

Instance Method Summary collapse

Methods inherited from DSLCompiler

#attribute, #attributes, #define, #extra, #initialize, #key, #parse

Constructor Details

This class inherits a constructor from Attributor::DSLCompiler

Instance Method Details

#_requirements_dslObject



122
123
124
# File 'lib/attributor/hash_dsl_compiler.rb', line 122

def _requirements_dsl
  @requirements_dsl ||= RequiresDSL.new(@target)
end

#requires(*spec, **opts, &block) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/attributor/hash_dsl_compiler.rb', line 126

def requires(*spec, **opts, &block)
  if spec.empty?
    _requirements_dsl.options.merge(opts) unless opts.empty?
    if block_given?
      _requirements_dsl.instance_eval(&block)
    else
      _requirements_dsl
    end
  else
    _requirements_dsl.all(*spec, opts)
  end
end