Class: Schematist::DSL::ConditionalContext

Inherits:
Object
  • Object
show all
Defined in:
lib/schematist/dsl/conditional_context.rb

Instance Method Summary collapse

Constructor Details

#initialize(then_builder, else_builder) ⇒ ConditionalContext

Returns a new instance of ConditionalContext.



6
7
8
9
# File 'lib/schematist/dsl/conditional_context.rb', line 6

def initialize(then_builder, else_builder)
  @then_builder = then_builder
  @else_builder = else_builder
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

Everything else describes the then branch



16
17
18
19
20
# File 'lib/schematist/dsl/conditional_context.rb', line 16

def method_missing(name, ...)
  return super unless @then_builder.respond_to?(name)

  @then_builder.public_send(name, ...)
end

Instance Method Details

#otherwise(&block) ⇒ Object



11
12
13
# File 'lib/schematist/dsl/conditional_context.rb', line 11

def otherwise(&block)
  @else_builder.instance_eval(&block)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/schematist/dsl/conditional_context.rb', line 22

def respond_to_missing?(name, include_private = false)
  @then_builder.respond_to?(name) || super
end