Module: AdequateExposure::Behavior
- Defined in:
- lib/adequate_exposure/behavior.rb
Instance Method Summary collapse
- #build(params, scope) ⇒ Object
- #build_params ⇒ Object
- #decorate(instance) ⇒ Object
- #fetch ⇒ Object
- #find(id, scope) ⇒ Object
- #id ⇒ Object
- #model ⇒ Object
- #scope(model) ⇒ Object
Instance Method Details
#build(params, scope) ⇒ Object
29 30 31 |
# File 'lib/adequate_exposure/behavior.rb', line 29 def build(params, scope) scope.new(params) end |
#build_params ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/adequate_exposure/behavior.rb', line 37 def build_params if controller.respond_to?(params_method_name, true) && !get_request? controller.send(params_method_name) else {} end end |
#decorate(instance) ⇒ Object
33 34 35 |
# File 'lib/adequate_exposure/behavior.rb', line 33 def decorate(instance) instance end |
#fetch ⇒ Object
3 4 5 6 |
# File 'lib/adequate_exposure/behavior.rb', line 3 def fetch instance = id ? find(id, computed_scope) : build(build_params, computed_scope) decorate(instance) end |
#find(id, scope) ⇒ Object
25 26 27 |
# File 'lib/adequate_exposure/behavior.rb', line 25 def find(id, scope) scope.find(id) end |
#id ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/adequate_exposure/behavior.rb', line 8 def id params_id_key_candidates.each do |key| value = params[key] return value if value.present? end nil end |
#model ⇒ Object
21 22 23 |
# File 'lib/adequate_exposure/behavior.rb', line 21 def model name.to_s.classify.constantize end |
#scope(model) ⇒ Object
17 18 19 |
# File 'lib/adequate_exposure/behavior.rb', line 17 def scope(model) model end |