Class: Usable::ModExtender
- Inherits:
-
Object
- Object
- Usable::ModExtender
- Defined in:
- lib/usable/mod_extender.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#copy ⇒ Object
Returns the value of attribute copy.
-
#mod ⇒ Object
Returns the value of attribute mod.
Instance Method Summary collapse
- #call ⇒ Object
- #has_spec? ⇒ Boolean
-
#initialize(mod, config = OpenStruct.new) ⇒ ModExtender
constructor
A new instance of ModExtender.
- #override ⇒ Object
Constructor Details
#initialize(mod, config = OpenStruct.new) ⇒ ModExtender
Returns a new instance of ModExtender.
5 6 7 8 9 |
# File 'lib/usable/mod_extender.rb', line 5 def initialize(mod, config = OpenStruct.new) @mod = mod @copy = has_spec? ? mod.const_get(:Spec).dup : mod.dup @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/usable/mod_extender.rb', line 3 def config @config end |
#copy ⇒ Object
Returns the value of attribute copy.
3 4 5 |
# File 'lib/usable/mod_extender.rb', line 3 def copy @copy end |
#mod ⇒ Object
Returns the value of attribute mod.
3 4 5 |
# File 'lib/usable/mod_extender.rb', line 3 def mod @mod end |
Instance Method Details
#call ⇒ Object
11 12 13 |
# File 'lib/usable/mod_extender.rb', line 11 def call copy.prepend override end |
#has_spec? ⇒ Boolean
24 25 26 |
# File 'lib/usable/mod_extender.rb', line 24 def has_spec? mod.const_defined?(:Spec) end |
#override ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/usable/mod_extender.rb', line 15 def override unwanted = config.only ? copy.instance_methods - Array(config.only) : [] Module.new do unwanted.each do |method_name| define_method(method_name) { |*| } end end end |