lib/lazydoc/attributes.rb in lazydoc-0.1.0 vs lib/lazydoc/attributes.rb in lazydoc-0.2.0

- old
+ new

@@ -1,26 +1,32 @@ +require 'lazydoc' + module Lazydoc - # Attributes adds methods to declare class-level accessors - # for Lazydoc attributes. The source_file for the class must - # be set manually. + # Attributes adds methods to declare class-level accessors for Lazydoc + # attributes. # # # ConstName::key value # class ConstName - # class << self - # include Lazydoc::Attributes - # end + # extend Lazydoc::Attributes # - # self.source_file = __FILE__ # lazy_attr :key # end # + # ConstName.source_file # => __FILE__ # ConstName::key.subject # => 'value' # module Attributes - # The source_file for self. Must be set independently. + # The source_file for self. By default set to the file where + # Attributes extends a class (if you include Attributes, you + # must set source_file manually). attr_accessor :source_file + + def self.extended(base) # :nodoc: + caller[1] =~ CALLER_REGEXP + base.source_file ||= $1 + end # Returns the lazydoc for source_file def lazydoc(resolve=true) lazydoc = Lazydoc[source_file] lazydoc.resolve if resolve @@ -35,8 +41,13 @@ end def #{key}=(comment) Lazydoc[source_file][to_s]['#{attribute}'] = comment end} - end + end + + # Registers the next method. + def register_method___(comment_class=Method) + lazydoc(false).register___(comment_class, 1) + end end end