Class: Compony::ComponentMixins::Default::Standalone::VerbDsl
- Inherits:
-
Dslblend::Base
- Object
- Dslblend::Base
- Compony::ComponentMixins::Default::Standalone::VerbDsl
- Defined in:
- lib/compony/component_mixins/default/standalone/verb_dsl.rb
Overview
DSL for speficying verb configs within a standalone config.
Direct Known Subclasses
Constant Summary collapse
- AVAILABLE_VERBS =
%i[get head post put delete connect options trace patch].freeze
Instance Method Summary collapse
-
#authorize(&block) ⇒ Object
protected
DSL This block is expected to return true if and only if current_ability has the right to access the component over the given verb.
-
#default_config ⇒ Object
protected
Internal, do not use.
-
#initialize(component, verb) ⇒ VerbDsl
constructor
A new instance of VerbDsl.
-
#respond(format = nil, &block) ⇒ Object
protected
DSL This is the last step in the life cycle.
-
#to_conf(provide_defaults:) ⇒ Object
For internal usage only, processes the block and returns a config hash.
Constructor Details
#initialize(component, verb) ⇒ VerbDsl
Returns a new instance of VerbDsl.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 12 def initialize(component, verb) super() verb = verb.to_sym fail "Unknown HTTP verb #{verb.inspect}, use one of #{AVAILABLE_VERBS.inspect}" unless AVAILABLE_VERBS.include?(verb) @component = component @verb = verb @respond_blocks = {} @authorize_block = nil end |
Instance Method Details
#authorize(&block) ⇒ Object (protected)
DSL This block is expected to return true if and only if current_ability has the right to access the component over the given verb.
39 40 41 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 39 def (&block) @authorize_block = block end |
#default_config ⇒ Object (protected)
Internal, do not use
51 52 53 54 55 56 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 51 def default_config return { authorize_block: proc { can?(comp_name.to_sym, family_name.to_sym) }, respond_blocks: { nil => proc { render_standalone(controller) } } } end |
#respond(format = nil, &block) ⇒ Object (protected)
DSL This is the last step in the life cycle. It may redirect or render. If omitted, the default is standalone_render.
46 47 48 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 46 def respond(format = nil, &block) @respond_blocks[format&.to_sym] = block end |
#to_conf(provide_defaults:) ⇒ Object
For internal usage only, processes the block and returns a config hash.
25 26 27 28 29 30 31 32 33 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 25 def to_conf(provide_defaults:, &) evaluate(&) if block_given? base_config = provide_defaults ? default_config : {} return base_config.deep_merge({ verb: @verb, authorize_block: @authorize_block, respond_blocks: @respond_blocks }.compact) end |