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) ⇒ 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.
-
#to_conf(&block) ⇒ Object
For internal usage only, processes the block and returns a config hash.
-
#verb(verb, *args, **nargs) ⇒ Object
protected
DSL call for defining a config for a verb.
Constructor Details
#initialize(component, name = nil, provide_defaults:, path: nil) ⇒ StandaloneDsl
Returns a new instance of StandaloneDsl.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 9 def initialize(component, name = nil, provide_defaults:, path: nil) super() @component = component @name = name&.to_sym @provide_defaults = provide_defaults @path = path @verbs = {} @skip_authentication = 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.
66 67 68 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 66 def layout(layout) @layout = layout.to_s end |
#skip_authentication! ⇒ Object (protected)
DSL Defines that for this component, no authentication should be performed.
58 59 60 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 58 def skip_authentication! @skip_authentication = true end |
#to_conf(&block) ⇒ Object
For internal usage only, processes the block and returns a config hash.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 21 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, 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, layout: @layout }.compact end |
#verb(verb, *args, **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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/compony/component_mixins/default/standalone/standalone_dsl.rb', line 40 def verb(verb, *args, **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, *args, **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, *args, **nargs).to_conf(provide_defaults: @provide_defaults, &) ) end end |