Class: ViewComponentContrib::StyleVariants::VariantBuilder
- Inherits:
-
Object
- Object
- ViewComponentContrib::StyleVariants::VariantBuilder
- Defined in:
- lib/view_component_contrib/style_variants.rb
Instance Attribute Summary collapse
-
#unwrap_blocks ⇒ Object
readonly
Returns the value of attribute unwrap_blocks.
Instance Method Summary collapse
- #build(&block) ⇒ Object
-
#initialize(unwrap_blocks = true) ⇒ VariantBuilder
constructor
A new instance of VariantBuilder.
- #method_missing(name, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(unwrap_blocks = true) ⇒ VariantBuilder
Returns a new instance of VariantBuilder.
48 49 50 51 |
# File 'lib/view_component_contrib/style_variants.rb', line 48 def initialize(unwrap_blocks = true) @unwrap_blocks = unwrap_blocks @variants = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/view_component_contrib/style_variants.rb', line 62 def method_missing(name, &block) return super unless block_given? @variants[name] = if unwrap_blocks VariantBuilder.new(false).build(&block) else block end end |
Instance Attribute Details
#unwrap_blocks ⇒ Object (readonly)
Returns the value of attribute unwrap_blocks.
46 47 48 |
# File 'lib/view_component_contrib/style_variants.rb', line 46 def unwrap_blocks @unwrap_blocks end |
Instance Method Details
#build(&block) ⇒ Object
53 54 55 56 |
# File 'lib/view_component_contrib/style_variants.rb', line 53 def build(&block) instance_eval(&block) @variants end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
58 59 60 |
# File 'lib/view_component_contrib/style_variants.rb', line 58 def respond_to_missing?(name, include_private = false) true end |