Class: Inch::API::Options::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/api/options/base.rb

Direct Known Subclasses

Filter, Suggest

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options_or_hash) ⇒ Base

Returns a new instance of Base.



26
27
28
29
30
# File 'lib/inch/api/options/base.rb', line 26

def initialize(options_or_hash)
  self.class.attribute_names.each do |name|
    read options_or_hash, name
  end
end

Class Method Details

.attribute(name, default = nil) ⇒ void

This method returns an undefined value.

Creates an attribute with an optional default value

Parameters:

  • name (Symbol)

    the name of the attribute

  • default (nil) (defaults to: nil)

    the default value of the attribute



11
12
13
14
15
16
17
18
# File 'lib/inch/api/options/base.rb', line 11

def attribute(name, default = nil)
  define_method(name) do
    instance_variable_get("@#{name}") || default
  end
  @attributes ||= {}
  @attributes[to_s] ||= []
  @attributes[to_s] << name
end

.attribute_namesObject



20
21
22
23
# File 'lib/inch/api/options/base.rb', line 20

def attribute_names
  @attributes ||= {}
  @attributes[to_s] ||= []
end