lib/tap/support/configurable_class.rb in bahuvrihi-tap-0.10.0 vs lib/tap/support/configurable_class.rb in bahuvrihi-tap-0.10.1

- old
+ new

@@ -1,8 +1,8 @@ require 'tap/support/class_configuration' require 'tap/support/validation' -require 'tap/support/lazydoc' +require 'tap/support/lazy_attributes' module Tap module Support autoload(:Templater, 'tap/support/templater') @@ -45,17 +45,14 @@ # ac = YetAnotherConfigurableClass.new # ac.one = 'value' # ac.one # => 'eulav' # module ConfigurableClass + include Tap::Support::LazyAttributes # A ClassConfiguration holding the class configurations. attr_reader :configurations - - # The source_file for self. By default the first file - # to define the class inheriting ConfigurableClass. - attr_accessor :source_file # Sets the source_file for base and initializes base.configurations. def self.extended(base) caller.each_with_index do |line, index| case line @@ -80,20 +77,19 @@ child.instance_variable_set(:@configurations, ClassConfiguration.new(child, @configurations)) super end - # Returns the lazydoc for source_file - def lazydoc(resolve=false) - Lazydoc.resolve(configurations.code_comments) if resolve - Lazydoc[source_file] + def lazydoc(resolve=true) + Lazydoc.resolve_comments(configurations.code_comments) if resolve + super end # Loads the contents of path as YAML. Returns an empty hash if the path # is empty, does not exist, or is not a file. def load_config(path) - return {} if path == nil || !File.exists?(path) || File.directory?(path) + return {} if path == nil || !File.file?(path) YAML.load_file(path) || {} end protected @@ -211,13 +207,14 @@ # alt.config[:sym] # => :two # # Idiosyncratically, true, false, and nil may also be provided as # reader/writer options. Specifying true is the same as using the # default. Specifying false or nil prevents config_attr from - # defining accessors, but the configuration still expects to use - # the default reader/writer methods (ie <tt>key</tt> and <tt>key=</tt>) - # which must be defined elsewhere. + # defining accessors; false sets the configuration to use + # the default reader/writer methods (ie <tt>key</tt> and <tt>key=</tt>, + # which must be defined elsewhere) while nil prevents read/write + # mapping of the config to a method. def config_attr(key, value=nil, options={}, &block) # add arg_type implied by block, if necessary options[:arg_type] = arg_type(block) if block_given? && options[:arg_type] == nil options[:arg_name] = arg_name(block) if block_given? && options[:arg_name] == nil @@ -229,29 +226,29 @@ end # define the public writer method case when options.has_key?(:writer) && options[:writer] != true - raise ArgumentError.new("block may not be specified with writer") if block_given? + raise(ArgumentError, "a block may not be specified with writer option") if block_given? when block_given? define_method("#{key}=", &block) public "#{key}=" else attr_writer(key) public "#{key}=" end - # remove any true, false, nil reader/writer declarations... + # remove any true, false reader/writer declarations... # implicitly reverting the option to the default reader # and writer methods [:reader, :writer].each do |option| case options[option] - when true, false, nil then options.delete(option) + when true, false then options.delete(option) end end - # register with TDoc so that all extra documentation can be extracted - caller.each_with_index do |line, index| + # register with Lazydoc so that all extra documentation can be extracted + caller.each do |line| case line when /in .config.$/ then next when /^(([A-z]:)?[^:]+):(\d+)/ options[:desc] = Lazydoc.register($1, $3.to_i - 1) break \ No newline at end of file