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:
440 441 442 443 444 445 |
# File 'lib/idregistry/configuration.rb', line 440 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:
448 449 450 |
# File 'lib/idregistry/configuration.rb', line 448 def inspect # :nodoc: "#<#{self.class}:0x#{object_id.to_s(16)}>" end |
#pattern(value_ = nil) ⇒ Object
Set the pattern to add
455 456 457 458 459 460 461 |
# File 'lib/idregistry/configuration.rb', line 455 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.
488 489 490 491 492 493 494 |
# File 'lib/idregistry/configuration.rb', line 488 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.
501 502 503 504 505 506 507 |
# File 'lib/idregistry/configuration.rb', line 501 def to_generate_tuple(&block_) if block_ @gen_tuple = block_ else @gen_tuple end end |
#type(value_ = nil) ⇒ Object
Set the object type
466 467 468 469 470 471 472 |
# File 'lib/idregistry/configuration.rb', line 466 def type(value_=nil) if value_ @type = value_ else @type end end |