loggable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-04-24
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 YOUR NAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,55 @@
1
+ = Loggable
2
+
3
+ Loggable is a gem that's designed to add a logging interface to classes that don't
4
+ automatically support it.
5
+
6
+ == Installation
7
+
8
+ This code is available as a Ruby Gem:
9
+
10
+ sudo gem install loggable
11
+
12
+ == Usage
13
+
14
+ Using the Gem is easy, just include the <tt>loggable</tt> class method in your class
15
+ to enable it:
16
+
17
+ require 'rubygems'
18
+ require 'logger'
19
+ require 'loggable'
20
+
21
+ class MyClass
22
+ loggable
23
+ end
24
+
25
+ Now you can assign a logger instance to this class and have it write log messages to
26
+ the specified file:
27
+
28
+ MyClass.logger = Logger.new('debug.log')
29
+
30
+ Any class or instance methods now have access to the logger:
31
+
32
+ class MyClass
33
+ def self.do_something
34
+ logger.debug 'doing something in the class'
35
+ end
36
+
37
+ def do_something
38
+ logger.debug 'doing something in an instance'
39
+ end
40
+ end
41
+
42
+ The above code will write into the log file when called:
43
+
44
+ MyClass.do_something
45
+ MyClass.new.do_something
46
+
47
+ debug.log:
48
+
49
+ D, [2008-04-24T20:37:32.273930 #25821] DEBUG -- : doing something in the class
50
+ D, [2008-04-24T20:37:32.274062 #25821] DEBUG -- : doing something in an instance
51
+
52
+ == Credits
53
+
54
+ Copyright (c) 2008 Patrick Reagan of Viget Labs (mailto:patrick.reagan@viget.com)
55
+ Released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/version'
6
+
7
+ GEM = "loggable"
8
+ AUTHOR = "Patrick Reagan"
9
+ EMAIL = "patrick.reagan@viget.com"
10
+ HOMEPAGE = "http://viget.rubyforge.org/loggable"
11
+ SUMMARY = "A gem that provides logging capabilities to any class"
12
+
13
+ task :default => :test
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = GEM
17
+ s.version = Loggable::VERSION::STRING
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README", "LICENSE"]
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.rubyforge_project = 'viget'
27
+
28
+ s.require_path = 'lib'
29
+ s.files = %w(LICENSE README HISTORY Rakefile) + Dir.glob("{lib,test}/**/*")
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.gem_spec = spec
34
+ end
35
+
36
+ task :install => [:package] do
37
+ sh %{sudo gem install pkg/#{GEM}-#{VERSION}}
38
+ end
39
+
40
+ Rake::TestTask.new do |t|
41
+ t.libs << 'test'
42
+ t.pattern = FileList['test/examples/*_test.rb']
43
+ t.verbose = true
44
+ end
data/lib/loggable.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Loggable
2
+
3
+ module LogMethods
4
+
5
+ # Including this in your class definition will add the ability to use a logger within
6
+ # your class:
7
+ #
8
+ # class MyClass
9
+ # loggable
10
+ # end
11
+ #
12
+ # Now you can assign a logger instance to this class and have it write to the specified
13
+ # logfile. See the README for details.
14
+ #
15
+ def loggable
16
+ extend ClassMethods
17
+ include InstanceMethods
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+
23
+ @@logger = nil
24
+
25
+ def logger=(logger)
26
+ @@logger = logger
27
+ end
28
+
29
+ def logger
30
+ @@logger
31
+ end
32
+
33
+ end
34
+
35
+ module InstanceMethods
36
+ def logger
37
+ self.class.logger
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ Object.send(:extend, Loggable::LogMethods)
data/lib/version.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Loggable
2
+
3
+ module VERSION #:nodoc:
4
+ MAJOR = 0
5
+ MINOR = 0
6
+ TINY = 1
7
+
8
+ STRING = [MAJOR, MINOR, TINY].join('.')
9
+ end
10
+
11
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class MyClass; loggable; end
4
+
5
+ describe "MyClass, with loggable mix-in" do
6
+
7
+ before(:each) do
8
+ @logger = mock()
9
+ end
10
+
11
+ it "should have nothing as a logger by default" do
12
+ MyClass.logger.should.be nil
13
+ end
14
+
15
+ it "should allow the asssignment of a logger" do
16
+ MyClass.logger = @logger
17
+ MyClass.logger.should.equal @logger
18
+ end
19
+
20
+ it "should allow access to the logger from an instance" do
21
+ MyClass.logger = @logger
22
+ MyClass.new.logger.should.equal @logger
23
+ end
24
+
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'test/spec'
3
+ require 'mocha'
4
+
5
+ $TESTING=true
6
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
7
+
8
+ require 'loggable'
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loggable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Reagan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-24 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A gem that provides logging capabilities to any class
17
+ email: patrick.reagan@viget.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ files:
26
+ - LICENSE
27
+ - README
28
+ - HISTORY
29
+ - Rakefile
30
+ - lib/loggable.rb
31
+ - lib/version.rb
32
+ - test/examples
33
+ - test/examples/loggable_test.rb
34
+ - test/test_helper.rb
35
+ has_rdoc: true
36
+ homepage: http://viget.rubyforge.org/loggable
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project: viget
57
+ rubygems_version: 1.1.0
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: A gem that provides logging capabilities to any class
61
+ test_files: []
62
+