Module: Tap::Support::LazyAttributes

Included in:
ConfigurableClass
Defined in:
lib/tap/support/lazy_attributes.rb

Overview

LazyAttributes adds methods to declare class-level accessors for Lazydoc attributes. The source_file for the class must be set manually.

# ConstName::key value
class ConstName
  extend LazyAttributes

  self.source_file = __FILE__
  lazy_attr :key
end

ConstName::key.subject           # => 'value'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#source_fileObject

The source_file for self. Must be set independently.



23
24
25
# File 'lib/tap/support/lazy_attributes.rb', line 23

def source_file
  @source_file
end

Instance Method Details

#lazy_attr(key, attribute = key) ⇒ Object

Creates a lazy attribute reader for the specified attribute.



33
34
35
# File 'lib/tap/support/lazy_attributes.rb', line 33

def lazy_attr(key, attribute=key)
  instance_eval %Q{def #{key}; @#{key} ||= get_lazy_attr('#{attribute}'); end}
end

#lazydoc(resolve = true) ⇒ Object

Returns the lazydoc for source_file



26
27
28
29
30
# File 'lib/tap/support/lazy_attributes.rb', line 26

def lazydoc(resolve=true)
  lazydoc = Lazydoc[source_file]
  lazydoc.resolve if resolve
  lazydoc
end