Class: BusinessFlow::DSL::MemoizedField

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

Overview

Helper class around memoized fields

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, retriever, setter_factory) ⇒ MemoizedField

Returns a new instance of MemoizedField.



430
431
432
433
434
# File 'lib/business_flow/dsl.rb', line 430

def initialize(field, retriever, setter_factory)
  @field = field
  @retriever = retriever
  @setter_factory = setter_factory
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



428
429
430
# File 'lib/business_flow/dsl.rb', line 428

def field
  @field
end

Instance Method Details

#add_to(klass) ⇒ Object



436
437
438
439
440
441
# File 'lib/business_flow/dsl.rb', line 436

def add_to(klass)
  setter = setter_factory.call(field, safe_ivar_name)
  Field.unsafe_eval_method(
    klass, field, memoized(safe_ivar_name, setter, retriever)
  )
end

#nameObject



443
444
445
# File 'lib/business_flow/dsl.rb', line 443

def name
  field
end