Class: Compony::ComponentMixins::Default::Standalone::StandaloneDsl
- Inherits:
-
Dslblend::Base
- Object
- Dslblend::Base
- Compony::ComponentMixins::Default::Standalone::StandaloneDsl
- Defined in:
- lib/compony/component_mixins/default/standalone/standalone_dsl.rb
Overview
Wrapper and DSL helper for component's standalone config
Pass provide_defaults
true if this is the first standalone DSL of a component. Pass false if it is a subsequent one (e.g. if subclassed comp)
Instance Method Summary collapse
-
#initialize(component, name = nil, provide_defaults:, path: nil, constraints: nil, scope: nil, scope_args: {}) ⇒ StandaloneDsl
constructor
A new instance of StandaloneDsl.
-
#layout(layout) ⇒ Object
protected
DSL Speficies the Rails layout (under
app/views/layouts
) that should be used to render this component. -
#skip_authentication! ⇒ Object
protected
DSL Defines that for this component, no authentication should be performed.
-
#skip_forgery_protection! ⇒ Object
protected
DSL Defines that for this component, no forgery protection (CSRF) should be performed.
-
#to_conf(&block) ⇒ Object
For internal usage only, processes the block and returns a config hash.
-
#verb(verb, **nargs) ⇒ Object
protected
DSL call for defining a config for a verb.
Constructor Details
#initialize(component, name = nil, provide_defaults:, path: nil, constraints: nil, scope: nil, scope_args: {}) ⇒ StandaloneDsl
Returns a new instance of StandaloneDsl.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 9 def initialize(component, name = nil, provide_defaults:, path: nil, constraints: nil, scope: nil, scope_args: {}) super() @component = component @name = name&.to_sym @provide_defaults = provide_defaults @path = path @constraints = constraints @scope = scope @scope_args = scope_args @verbs = {} @skip_authentication = false @skip_forgery_protection = false @layout = true # can be overriden by false or a string end |
Instance Method Details
#layout(layout) ⇒ Object (protected)
DSL
Speficies the Rails layout (under app/views/layouts
) that should be used to render this component.
Defaults to Rails' default (layouts/application
) if the method is never called.
80 81 82 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 80 def layout(layout) @layout = layout.to_s end |
#skip_authentication! ⇒ Object (protected)
DSL Defines that for this component, no authentication should be performed.
66 67 68 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 66 def skip_authentication! @skip_authentication = true end |
#skip_forgery_protection! ⇒ Object (protected)
DSL Defines that for this component, no forgery protection (CSRF) should be performed.
72 73 74 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 72 def skip_forgery_protection! @skip_forgery_protection = true end |
#to_conf(&block) ⇒ Object
For internal usage only, processes the block and returns a config hash.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 25 def to_conf(&block) evaluate(&block) @component = block.binding.eval('self') # Fetches the component holding this DSL call (via the block) return { name: @name, path: @path, constraints: @constraints, scope: @scope, scope_args: @scope_args, verbs: @verbs, rails_action_name: Compony.rails_action_name(comp_name, family_name, @name), path_helper_name: Compony.path_helper_name(comp_name, family_name, @name), skip_authentication: @skip_authentication, skip_forgery_protection: @skip_forgery_protection, layout: @layout }.compact end |
#verb(verb, **nargs) ⇒ Object (protected)
DSL call for defining a config for a verb. The block runs within the verb DSL, positional and named arguments are passed to the verb DSL.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 48 def verb(verb, *, **nargs, &) verb = verb.to_sym verb_dsl_class = @component.resourceful? ? ResourcefulVerbDsl : VerbDsl if @verbs[verb] @verbs[verb].deep_merge! verb_dsl_class.new(@component, verb, *, **nargs).to_conf(provide_defaults: false, &) else # Note about provide_defaults: # - We must pass false if this is the second time `standalone` was called for this component -> see @provide_defaults # - We musst pass false if this is the second time `verb` was called for this component -> handled by the if statement (other branch) # - We must pass true otherwise (handled by this branch) @verbs[verb] = Compony::MethodAccessibleHash.new( verb_dsl_class.new(@component, verb, *, **nargs).to_conf(provide_defaults: @provide_defaults, &) ) end end |