Class: ViewComponentContrib::StyleVariants::VariantBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/view_component_contrib/style_variants.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_blocksObject (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

Returns:

  • (Boolean)


58
59
60
# File 'lib/view_component_contrib/style_variants.rb', line 58

def respond_to_missing?(name, include_private = false)
  true
end