Class: BusinessFlow::DSL::UsesField

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

Overview

Responsible for declaring fields which will be memoized and validated when first set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, retriever) ⇒ UsesField

Returns a new instance of UsesField.



474
475
476
477
478
479
# File 'lib/business_flow/dsl.rb', line 474

def initialize(field, retriever)
  @name = field
  @retriever = retriever
  @field = MemoizedField.new(field, retriever_method_name,
                             Field.method(:setter_factory))
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



472
473
474
# File 'lib/business_flow/dsl.rb', line 472

def name
  @name
end

Instance Method Details

#add_to(klass) ⇒ Object



481
482
483
484
485
486
# File 'lib/business_flow/dsl.rb', line 481

def add_to(klass)
  klass.send(:define_method, retriever_method_name, &@retriever)
  klass.send(:private, retriever_method_name)
  @field.add_to(klass)
  klass.send(:public, @name)
end