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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
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.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/usable/mod_extender.rb', line 6 def initialize(mod, config = OpenStruct.new) @mod = mod if has_spec? @copy = mod.const_get(:UsableSpec).dup @name = "#{mod.name}UsableSpec" else @copy = mod.dup @name = mod.name end @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/usable/mod_extender.rb', line 4 def config @config end |
#copy ⇒ Object
Returns the value of attribute copy.
4 5 6 |
# File 'lib/usable/mod_extender.rb', line 4 def copy @copy end |
#mod ⇒ Object
Returns the value of attribute mod.
4 5 6 |
# File 'lib/usable/mod_extender.rb', line 4 def mod @mod end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/usable/mod_extender.rb', line 3 def name @name end |
Instance Method Details
#call ⇒ Object
Note:
Destructive
19 20 21 22 |
# File 'lib/usable/mod_extender.rb', line 19 def call override copy end |
#has_spec? ⇒ Boolean
31 32 33 |
# File 'lib/usable/mod_extender.rb', line 31 def has_spec? mod.const_defined?(:UsableSpec) end |
#override ⇒ Object
24 25 26 27 28 29 |
# File 'lib/usable/mod_extender.rb', line 24 def override unwanted = config.only ? copy.instance_methods - Array(config.only) : [] unwanted.each do |method_name| copy.send :remove_method, method_name end end |