Class: IDRegistry::PatternAdder
- Inherits:
-
Object
- Object
- IDRegistry::PatternAdder
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/idregistry/configuration.rb
Overview
This is the DSL available within the block passed to Configuration#add_pattern.
Instance Method Summary collapse
-
#initialize(pattern_, type_, gen_obj_, gen_tuple_) ⇒ PatternAdder
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#pattern(value_ = nil) ⇒ Object
Set the pattern to add.
-
#to_generate_object(&block_) ⇒ Object
Provide a block to call to generate the appropriate object given a tuple.
-
#to_generate_tuple(&block_) ⇒ Object
Provide a block to call to generate the tuple corresponding to an object.
-
#type(value_ = nil) ⇒ Object
Set the object type.
Constructor Details
#initialize(pattern_, type_, gen_obj_, gen_tuple_) ⇒ PatternAdder
:nodoc:
436 437 438 439 440 441 |
# File 'lib/idregistry/configuration.rb', line 436 def initialize(pattern_, type_, gen_obj_, gen_tuple_) # :nodoc: @pattern = pattern_ @type = type_ @gen_obj = gen_obj_ @gen_tuple = gen_tuple_ end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
444 445 446 |
# File 'lib/idregistry/configuration.rb', line 444 def inspect # :nodoc: "#<#{self.class}:0x#{object_id.to_s(16)}>" end |
#pattern(value_ = nil) ⇒ Object
Set the pattern to add
451 452 453 454 455 456 457 |
# File 'lib/idregistry/configuration.rb', line 451 def pattern(value_=nil) if value_ @pattern = value_ else @pattern end end |
#to_generate_object(&block_) ⇒ Object
Provide a block to call to generate the appropriate object given a tuple. This block is called when the repository is asked to lookup an object given a tuple, and the provided tuple is not yet present.
The block may take up to three arguments. The first is the tuple. The second is the repository containing the object. The third is a hash of arguments passed to the repository’s lookup method.
The block should return the generated object, or nil if it is unable to generate an object for the given tuple.
484 485 486 487 488 489 490 |
# File 'lib/idregistry/configuration.rb', line 484 def to_generate_object(&block_) if block_ @gen_obj = block_ else @gen_obj end end |
#to_generate_tuple(&block_) ⇒ Object
Provide a block to call to generate the tuple corresponding to an object. The repository calls this block when an object is added, in order to generate the appropriate tuples for looking up the object.
497 498 499 500 501 502 503 |
# File 'lib/idregistry/configuration.rb', line 497 def to_generate_tuple(&block_) if block_ @gen_tuple = block_ else @gen_tuple end end |
#type(value_ = nil) ⇒ Object
Set the object type
462 463 464 465 466 467 468 |
# File 'lib/idregistry/configuration.rb', line 462 def type(value_=nil) if value_ @type = value_ else @type end end |