Class: Toast::ConfigDSL::ViaVerb
- Inherits:
-
Object
- Object
- Toast::ConfigDSL::ViaVerb
- Includes:
- Common
- Defined in:
- lib/toast/config_dsl/via_verb.rb
Instance Method Summary collapse
Methods included from Common
#check_symbol_list, #initialize, #method_missing, #raise_config_error, #stack_push
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Toast::ConfigDSL::Common
Instance Method Details
#allow(&block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/toast/config_dsl/via_verb.rb', line 4 def allow &block stack_push 'allow' do unless block.arity.in? [3, -2, -1] raise_config_error 'Allow rule must list arguments as |*all|, |auth, *rest| or |auth, request_model, uri_params|' end @config_data. << block end end |
#handler(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/toast/config_dsl/via_verb.rb', line 15 def handler &block stack_push 'handler' do # arity check for custom handlers expected_arity = case Toast::ConfigDSL.stack[-3] when /\Asingle/ 1 when /\Acollection/ case Toast::ConfigDSL.stack[-2] when 'via_get' then 1 when 'via_post' then 2 end when /\Aassociation/ case Toast::ConfigDSL.stack[-2] when 'via_get' then 2 when /\Avia_(post|link|unlink)\z/ then 3 end when /\Aexpose/ case Toast::ConfigDSL.stack[-2] when /\Avia_(get|delete)\z/ then 2 when 'via_patch' then 3 end end if block.arity != expected_arity raise_config_error "Handler block must take exactly #{expected_arity} argument#{expected_arity==1?'':'s'}" end @config_data.handler = block end end |