Module: Tap::Support::Lazydoc::Attributes

Included in:
ConfigurableClass
Defined in:
lib/tap/support/lazydoc/attributes.rb

Overview

Attributes 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
  class << self
    include Lazydoc::Attributes
  end

  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.



25
26
27
# File 'lib/tap/support/lazydoc/attributes.rb', line 25

def source_file
  @source_file
end

Instance Method Details

#lazy_attr(key, attribute = key) ⇒ Object

Creates a lazy attribute accessor for the specified attribute.



35
36
37
38
39
40
41
42
43
44
# File 'lib/tap/support/lazydoc/attributes.rb', line 35

def lazy_attr(key, attribute=key)
  instance_eval %Q{
  def #{key}
    lazydoc[to_s]['#{attribute}'] ||= Lazydoc::Comment.new
  end

  def #{key}=(comment)
    Lazydoc[source_file][to_s]['#{attribute}'] = comment
  end}
end

#lazydoc(resolve = true) ⇒ Object

Returns the lazydoc for source_file



28
29
30
31
32
# File 'lib/tap/support/lazydoc/attributes.rb', line 28

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