Module: Apimaster::Generators::Options::ClassMethods

Defined in:
lib/apimaster/generators/options.rb

Constant Summary collapse

EMPTY_INHERITABLE_ATTRIBUTES =
{}.freeze

Instance Method Summary collapse

Instance Method Details

#default_options(options = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/apimaster/generators/options.rb', line 32

def default_options(options = nil)
  if options
    write_inheritable_attribute(:default_options, options)
  else
    read_inheritable_attribute(:default_options) or write_inheritable_attribute(:default_options, {})
  end
end

#full_options(runtime_options = {}) ⇒ Object

Merge together our class options. In increasing precedence:

default_options   (class default options)
runtime_options   (provided as argument)
mandatory_options (class mandatory options)


59
60
61
# File 'lib/apimaster/generators/options.rb', line 59

def full_options(runtime_options = {})
  default_options.merge(runtime_options).merge(mandatory_options)
end

#inheritable_attributesObject



51
52
53
# File 'lib/apimaster/generators/options.rb', line 51

def inheritable_attributes
  @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES
end

#inherited_with_options(sub) ⇒ Object



19
20
21
22
# File 'lib/apimaster/generators/options.rb', line 19

def inherited_with_options(sub)
  inherited_without_options(sub) if respond_to?(:inherited_without_options)
  sub.extend(Apimaster::Generators::Options::ClassMethods)
end

#mandatory_options(options = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/apimaster/generators/options.rb', line 24

def mandatory_options(options = nil)
  if options
    write_inheritable_attribute(:mandatory_options, options)
  else
    read_inheritable_attribute(:mandatory_options) or write_inheritable_attribute(:mandatory_options, {})
  end
end

#read_inheritable_attribute(key) ⇒ Object



40
41
42
# File 'lib/apimaster/generators/options.rb', line 40

def read_inheritable_attribute(key)
  inheritable_attributes[key]
end

#write_inheritable_attribute(key, value) ⇒ Object



44
45
46
47
48
49
# File 'lib/apimaster/generators/options.rb', line 44

def write_inheritable_attribute(key, value)
  if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
    @inheritable_attributes = {}
  end
  inheritable_attributes[key] = value
end