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.
-
#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 ⇒ 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 = { nil => proc { render_standalone(controller) } } # default format @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.
38 39 40 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 38 def (&block) @authorize_block = block 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.
45 46 47 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 45 def respond(format = nil, &block) @respond_blocks[format&.to_sym] = block end |
#to_conf ⇒ Object
For internal usage only, processes the block and returns a config hash.
25 26 27 28 29 30 31 32 |
# File 'lib/compony/component_mixins/default/standalone/verb_dsl.rb', line 25 def to_conf(&) evaluate(&) if block_given? return { verb: @verb, authorize_block: @authorize_block || proc { can?(comp_name.to_sym, family_name.to_sym) }, respond_blocks: @respond_blocks }.compact end |