This is so that you can still use docs without AST
being the parent class.
Signed-off-by: Luke Kanies <[email protected]>
---
lib/puppet/util/inline_docs.rb | 29 +++++++++++++++++++++++++++++
spec/unit/util/inline_docs.rb | 32 ++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)
create mode 100644 lib/puppet/util/inline_docs.rb
create mode 100755 spec/unit/util/inline_docs.rb
diff --git a/lib/puppet/util/inline_docs.rb b/lib/puppet/util/inline_docs.rb
new file mode 100644
index 0000000..405b539
--- /dev/null
+++ b/lib/puppet/util/inline_docs.rb
@@ -0,0 +1,29 @@
+module Puppet::Util::InlineDocs
+ def self.included(klass)
+ klass.send(:include, InstanceMethods)
+ klass.extend ClassMethods
+ end
+
+ module ClassMethods
+ attr_accessor :use_docs
+ def associates_doc
+ self.use_docs = true
+ end
+ end
+
+ module InstanceMethods
+ attr_writer :doc
+
+ def doc
+ unless defined?(@doc) and @doc
+ @doc = ""
+ end
+ @doc
+ end
+
+ # don't fetch lexer comment by default
+ def use_docs
+ self.class.use_docs
+ end
+ end
+end
diff --git a/spec/unit/util/inline_docs.rb b/spec/unit/util/inline_docs.rb
new file mode 100755
index 0000000..c541d01
--- /dev/null
+++ b/spec/unit/util/inline_docs.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ?
require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/util/file_locking'
+
+class InlineDoccer
+ include Puppet::Util::InlineDocs
+end
+
+describe Puppet::Util::InlineDocs do
+ describe "when included" do
+ it "should create a class method for specifying that docs should be
associated" do
+ InlineDoccer.expects(:use_docs=).with true
+ InlineDoccer.associates_doc
+ end
+
+ it "should default to not associating docs" do
+ (!! InlineDoccer.use_docs).should be_false
+ end
+
+ it "should create an instance method for setting documentation" do
+ instance = InlineDoccer.new
+ instance.doc = "foo"
+ instance.doc.should == "foo"
+ end
+
+ it "should default to an empty string for docs" do
+ InlineDoccer.new.doc.should == ""
+ end
+ end
+end
--
1.6.1
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.