Class: Mole::Utils::Frameworks
- Inherits:
-
Object
- Object
- Mole::Utils::Frameworks
- Defined in:
- lib/mole/utils/frameworks.rb
Class Method Summary collapse
-
.features_for(controller_class) ⇒ Object
find moleable features for a given class.
-
.flatten_params(context) ⇒ Object
compiles request parameters in a flat list.
-
.merb_actions(controller_class) ⇒ Object
retrieves the collection of callable actions from a Merb controller.
-
.moleable_features(clazz) ⇒ Object
Find moleable features on a given class ie non moled instance methods.
-
.rails_actions(controller_class) ⇒ Object
retrieves the collection of callable actions from a Rails controller.
Class Method Details
.features_for(controller_class) ⇒ Object
find moleable features for a given class
17 18 19 20 21 22 23 24 |
# File 'lib/mole/utils/frameworks.rb', line 17 def features_for( controller_class ) # Try rails first return rails_actions( controller_class ) rescue nil # Try merb return merb_actions( controller_class ) rescue nil # Otherwise returns instance methods moleable_features( controller_class ) end |
.flatten_params(context) ⇒ Object
compiles request parameters in a flat list.
11 12 13 14 |
# File 'lib/mole/utils/frameworks.rb', line 11 def flatten_params( context ) return nil unless context.respond_to? :params context.params.keys.sort{ |a,b| a.to_s <=> b.to_s }.collect{ |k| "#{k} => #{context.params[k]}" }.join( ", ") end |
.merb_actions(controller_class) ⇒ Object
retrieves the collection of callable actions from a Merb controller.
33 34 35 36 37 38 39 40 |
# File 'lib/mole/utils/frameworks.rb', line 33 def merb_actions( controller_class ) begin actions = [] controller_class.send( :callable_actions ).keys.each { |action| actions << action } rescue raise "Invalid Merb Controller class `#{controller_class}" end end |
.moleable_features(clazz) ⇒ Object
Find moleable features on a given class ie non moled instance methods
27 28 29 30 |
# File 'lib/mole/utils/frameworks.rb', line 27 def moleable_features( clazz ) features = clazz.public_instance_methods( false ) features.select { |f| f unless f.index( /_(with|without)_mole/) } end |
.rails_actions(controller_class) ⇒ Object
retrieves the collection of callable actions from a Rails controller
43 44 45 46 47 48 49 |
# File 'lib/mole/utils/frameworks.rb', line 43 def rails_actions( controller_class ) begin controller_class.send( :action_methods ) rescue raise "Invalid Rails Controller class `#{controller_class}" end end |