Module: Volute
- Defined in:
- lib/volute.rb
Overview
TODO : insert lengthy explanation here
Defined Under Namespace
Classes: Target, VoluteArray
Constant Summary collapse
- VOLUTE_VERSION =
'0.1.1'
Class Method Summary collapse
-
.apply(object, attribute = nil, previous_value = nil, value = nil) ⇒ Object
Volute.apply is generally called from the setter of a class which include Volute, but it’s OK to call it directly, to force volute application.
-
.clear! ⇒ Object
Nukes all the top level volutes.
-
.included(target) ⇒ Object
adding class methods to target classes.
-
.register(args, block) ⇒ Object
Volute class methods.
- .top ⇒ Object
Instance Method Summary collapse
- #volute_get(key) ⇒ Object
- #volute_set(key, value) ⇒ Object
-
#vset(key, value = nil) ⇒ Object
instance methods added to target classes.
Class Method Details
.apply(object, attribute = nil, previous_value = nil, value = nil) ⇒ Object
Volute.apply is generally called from the setter of a class which include Volute, but it’s OK to call it directly, to force volute application.
class Engine
attr_accessor :state
def turn_key!
@key_turned = true
Volute.apply(self, :key_turned)
end
def
Volute.apply(self)
end
end
volute Engine do
if attribute == :key_turned
object.state = :running
else
object.state = :off
end
end
113 114 115 116 117 118 |
# File 'lib/volute.rb', line 113 def self.apply(object, attribute=nil, previous_value=nil, value=nil) target = Target.new(object, attribute, previous_value, value) top.each { |args, block| target.volute(*args, &block) } end |
.clear! ⇒ Object
Nukes all the top level volutes.
86 87 88 89 |
# File 'lib/volute.rb', line 86 def self.clear! @top = nil end |
.included(target) ⇒ Object
adding class methods to target classes
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/volute.rb', line 35 def self.included(target) target.instance_eval do alias o_attr_accessor attr_accessor end def target.attr_accessor(*args) args.each do |arg| define_method(arg) { volute_get(arg.to_s) } define_method("#{arg}=") { |value| volute_set(arg.to_s, value) } end end end |
.register(args, block) ⇒ Object
Volute class methods
79 80 81 82 |
# File 'lib/volute.rb', line 79 def self.register(args, block) top << [ args, block ] end |
.top ⇒ Object
120 121 122 123 |
# File 'lib/volute.rb', line 120 def self.top (@top ||= VoluteArray.new) end |
Instance Method Details
#volute_get(key) ⇒ Object
62 63 64 65 |
# File 'lib/volute.rb', line 62 def volute_get(key) instance_variable_get("@#{key}") end |
#volute_set(key, value) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/volute.rb', line 67 def volute_set(key, value) previous_value = volute_get(key) vset(key, value) Volute.apply(self, key, previous_value, value) value end |
#vset(key, value = nil) ⇒ Object
instance methods added to target classes
53 54 55 56 57 58 59 60 |
# File 'lib/volute.rb', line 53 def vset(key, value=nil) if key.is_a?(Hash) key.each { |k, v| instance_variable_set("@#{k}", v) } else instance_variable_set("@#{key}", value) end end |