Module: Definition::Initializer::ClassMethods

Defined in:
lib/definition/initializer.rb

Instance Method Summary collapse

Instance Method Details

#_define_attr_accessor(key) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/definition/initializer.rb', line 29

def _define_attr_accessor(key)
  define_method(key) do
    @_attributes.fetch(key, nil)
  end
  define_method("#{key}=") do |value|
    @_attributes[key] = value
  end
  protected key
  protected "#{key}="
end

#_keys_definitionObject



25
26
27
# File 'lib/definition/initializer.rb', line 25

def _keys_definition
  @_keys_definition ||= Definition.Keys {}
end

#optional(name, *args, **kwargs) ⇒ Object



20
21
22
23
# File 'lib/definition/initializer.rb', line 20

def optional(name, *args, **kwargs)
  _keys_definition.optional(name, *args, **kwargs)
  _define_attr_accessor(name)
end

#required(name, *args) ⇒ Object



15
16
17
18
# File 'lib/definition/initializer.rb', line 15

def required(name, *args)
  _keys_definition.required(name, *args)
  _define_attr_accessor(name)
end