Module: Apimaster::Generators::Options::ClassMethods
- Defined in:
- lib/apimaster/generators/options.rb
Constant Summary collapse
- EMPTY_INHERITABLE_ATTRIBUTES =
{}.freeze
Instance Method Summary collapse
- #default_options(options = nil) ⇒ Object
-
#full_options(runtime_options = {}) ⇒ Object
Merge together our class options.
- #inheritable_attributes ⇒ Object
- #inherited_with_options(sub) ⇒ Object
- #mandatory_options(options = nil) ⇒ Object
- #read_inheritable_attribute(key) ⇒ Object
- #write_inheritable_attribute(key, value) ⇒ Object
Instance Method Details
#default_options(options = nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/apimaster/generators/options.rb', line 32 def ( = nil) if write_inheritable_attribute(:default_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:
(class default )
(provided as argument)
(class mandatory )
59 60 61 |
# File 'lib/apimaster/generators/options.rb', line 59 def ( = {}) .merge().merge() end |
#inheritable_attributes ⇒ Object
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 (sub) (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 ( = nil) if write_inheritable_attribute(:mandatory_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 |