Module: Lev::Handler::ClassMethods
- Defined in:
- lib/lev/handler.rb
Instance Method Summary collapse
- #handle(options = {}) ⇒ Object
- #paramify(group, options = {}, &block) ⇒ Object
- #paramify_classes ⇒ Object
- #paramify_methods ⇒ Object
Instance Method Details
#handle(options = {}) ⇒ Object
121 122 123 |
# File 'lib/lev/handler.rb', line 121 def handle(={}) call() end |
#paramify(group, options = {}, &block) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/lev/handler.rb', line 125 def paramify(group, ={}, &block) method_name = "#{group.to_s}_params" variable_sym = "@#{method_name}".to_sym # Generate the dynamic ActiveAttr class given # the paramify block; I think the caching of the class # in paramify_classes is only necessary to maintain # the name of the class set in the const_set statement if paramify_classes[group].nil? paramify_classes[group] = Class.new(Lev::Paramifier) do cattr_accessor :group end # Attach a name to this dynamic class const_set("#{group.to_s.capitalize}Paramifier", paramify_classes[group]) paramify_classes[group].class_eval(&block) paramify_classes[group].group = group end # Define the "#{group}_params" method to get the paramifier # instance wrapping the params define_method method_name.to_sym do if !instance_variable_get(variable_sym) instance_variable_set(variable_sym, self.class.paramify_classes[group].new(params[group])) end instance_variable_get(variable_sym) end # Keep track of the accessor for the params so we can check # errors in it later paramify_methods.push(method_name.to_sym) end |
#paramify_classes ⇒ Object
166 167 168 |
# File 'lib/lev/handler.rb', line 166 def paramify_classes @paramify_classes ||= {} end |
#paramify_methods ⇒ Object
162 163 164 |
# File 'lib/lev/handler.rb', line 162 def paramify_methods @paramify_methods ||= [] end |