Module: RailsAndSolid::TrickHim
- Defined in:
- lib/rails-and-solid/trick_him.rb
Instance Method Summary collapse
- #class_exists?(class_name, method) ⇒ Boolean
- #di_instantiate(type) ⇒ Object
- #method_for_action(method) ⇒ Object
-
#send_action(sym) ⇒ Object
end.
Instance Method Details
#class_exists?(class_name, method) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rails-and-solid/trick_him.rb', line 9 def class_exists?(class_name, method) # TODO cache is only for production (no reload) @exists ||= {} return @exists[class_name] if @exists.key?(class_name) # TODO solution1 klass = Module.const_get(class_name) self.class.send :define_method, method do # rails inheritance on my way (ret = super(sym)), once again... end return @exists[class_name] = klass.is_a?(Class) rescue NameError # exceptions and traces are expensive. @exists[class_name] = false return false end |
#di_instantiate(type) ⇒ Object
51 52 53 |
# File 'lib/rails-and-solid/trick_him.rb', line 51 def di_instantiate(type) type.new end |
#method_for_action(method) ⇒ Object
4 5 6 7 |
# File 'lib/rails-and-solid/trick_him.rb', line 4 def method_for_action(method) # TRICKing rails... no inheritance support method end |
#send_action(sym) ⇒ Object
end
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rails-and-solid/trick_him.rb', line 32 def send_action(sym) type = self.class.name type = type[0..type.size-4] if (class_exists?(type, sym)) type = type.constantize control = di_instantiate(type) params = extract_params_for(control.method(sym)) ret = control.send sym, *params control.instance_variables.each do |x| value = control.instance_variable_get x instance_variable_set x, value end super(sym) else params = extract_params_for(method(sym)) super(sym, *params) end end |