Module: Ruckus::StructureDefaultValues
- Included in:
- Structure
- Defined in:
- lib/ruckus/structure/defaults.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #final_initialization_hook ⇒ Object
-
#method_missing_hook(meth, args) ⇒ Object
def template_entry_added_hook(obj) obj.instance_variables.grep(/^@with_.*/).each do |v| v =~ /@with_(.*)/ var = $1 obj.send((var + “=”).intern, obj.instance_variable_get(v.intern)) end super end.
Class Method Details
.included(klass) ⇒ Object
3 4 5 |
# File 'lib/ruckus/structure/defaults.rb', line 3 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#final_initialization_hook ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/ruckus/structure/defaults.rb', line 7 def final_initialization_hook instance_variables.grep(/^@with_.*/).each do |v| v =~ /@with_(.*)/ var = $1 send((var + "=").intern, instance_variable_get(v.intern)) end super end |
#method_missing_hook(meth, args) ⇒ Object
def template_entry_added_hook(obj)
obj.instance_variables.grep(/^@with_.*/).each do |v|
v =~ /@with_(.*)/
var = $1
obj.send((var + "=").intern, obj.instance_variable_get(v.intern))
end
super
end
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruckus/structure/defaults.rb', line 26 def method_missing_hook(meth, args) m = meth.to_s setter = (m[-1].chr == "=") ? true : false m = m[0..-2] if setter if setter and (field = self[m.intern]) if(field.kind_of? Structure) if args[0].kind_of? field.class args[0].each_field do |name, f| field.value = f.value end else if((deft = field.instance_variable_get :@default_field)) field.send(deft.to_s + "=", args[0]) return false else puts "WARNING: attempt to set structure field with no default_field declared" end end end end true end |