Class: Hecks::Bluebook::DSL::WorldBuilder

Inherits:
Object
  • Object
show all
Includes:
WordGate
Defined in:
lib/hecks/bluebook/dsl/world_builder.rb

Constant Summary collapse

GRAMMAR_CONTEXT =
"World"

Constants included from WordGate

Hecks::Bluebook::DSL::WordGate::NOT_ADMITTED

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ WorldBuilder

Returns a new instance of WorldBuilder.



46
47
48
49
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 46

def initialize(domain)
  @domain   = domain
  @settings = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(verb, *args, **kwargs, &block) ⇒ Object



67
68
69
70
71
72
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 67

def method_missing(verb, *args, **kwargs, &block)
  result = word_gate_dispatch(verb, args, kwargs, block)
  return result unless result.equal?(WordGate::NOT_ADMITTED)

  record_binding(verb, args, kwargs, block)
end

Class Method Details

.build(domain, &block) ⇒ Object

ConstShim's resolver, the same bridge HecksagonBuilder/ BluebookBuilder already wrap their own instance_eval in (#143) — without it, Pizzas::Order.charged_by(...) raised NameError: uninitialized constant Pizzas for every .world file using the aggregate-qualified mirror form, since a bare Pizzas has no real constant to resolve to.



101
102
103
104
105
106
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 101

def self.build(domain, &block)
  builder  = new(domain)
  resolver = ->(_domain) { WorldConstProxy.namespace(builder) }
  ConstShim.with(resolver) { builder.instance_eval(&block) } if block
  builder.build
end

Instance Method Details

#buildObject



89
90
91
92
93
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 89

def build
  MetaValidator.call_world(
    World.new(domain: @domain, realm: @realm, latest: @latest, settings: @settings)
  )
end

#latest_impl(value) ⇒ Object



63
64
65
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 63

def latest_impl(value)
  @latest = required(value, "latest version")
end

#realm_impl(value) ⇒ Object

RENAMED FROM realm/latest — item #13's full metaprogrammed dispatch (slice 5). Neither bootstrap-reachable (checked directly). Reached through WordGate#method_missing's new word_gate_dispatch, called explicitly below since WorldBuilder's own class-level method_missing (the open-verb catch-all beneath this) always wins over the module's — see word_gate.rb's own header for the full mechanism.



59
60
61
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 59

def realm_impl(value)
  @realm = required(value, "realm")
end

#record_binding(verb, args, kwargs, block) ⇒ Object

EXTRACTED from the old method_missing body (#143) so WorldConstProxy's own aggregate-qualified verb calls (Pizzas::Order.charged_by(...)) write into the exact same place the bare top-level spelling (charged_by(...)) already does — one write path, two spellings.



81
82
83
84
85
86
87
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 81

def record_binding(verb, args, kwargs, block)
  collector = SettingsCollector.new
  collector.instance_eval(&block) if block
  value = { adapter: args.first.to_s }.merge(kwargs).merge(collector.to_h)
  @settings[verb.to_s] = value
  @settings["#{verb}:#{args.first.to_s.downcase}"] = value
end

#respond_to_missing?(_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


74
# File 'lib/hecks/bluebook/dsl/world_builder.rb', line 74

def respond_to_missing?(_name, _include_private = false) = true