Class: Despecable::Me
- Inherits:
-
Object
- Object
- Despecable::Me
- Defined in:
- lib/despecable/me.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #despecably_strict ⇒ Object
- #doit(*args, strict: false, &blk) ⇒ Object
-
#initialize(params, supplied_params = nil) ⇒ Me
constructor
supplied_params are the params that were actually passed in by the user.
- #unspecd ⇒ Object
Constructor Details
#initialize(params, supplied_params = nil) ⇒ Me
supplied_params are the params that were actually passed in by the user. In Rails, params has some additional keys (e.g. controller, action), so you can pass in request.query_parameters (GET) and/or request.request_parameters (POST) for supplied_params to correctly get only the user-supplied parameters.
9 10 11 12 13 |
# File 'lib/despecable/me.rb', line 9 def initialize(params, supplied_params = nil) @supplied_params = (supplied_params || params).dup @params = params @specd = [] end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/despecable/me.rb', line 3 def params @params end |
Instance Method Details
#despecably_strict ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/despecable/me.rb', line 27 def despecably_strict if !unspecd.empty? list = unspecd.map{|x| "'#{x}'"}.join(", ") error = Despecable::UnrecognizedParameterError.new("Unrecognized parameters supplied: #{list}", parameters: unspecd) raise error end end |
#doit(*args, strict: false, &blk) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/despecable/me.rb', line 15 def doit(*args, strict: false, &blk) spectator = Despecable::Spectator.new(@params) spectator.instance_exec(*args, &blk) unless blk.nil? @specd += spectator.specd despecably_strict if strict return spectator.params end |
#unspecd ⇒ Object
23 24 25 |
# File 'lib/despecable/me.rb', line 23 def unspecd @supplied_params.keys.map(&:to_s) - @specd.map(&:to_s) end |