structured_warnings 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig ADDED
Binary file
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 0.1.0 2008-02-21
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+ * No documentation yet
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full 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/Manifest.txt ADDED
@@ -0,0 +1,32 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/structured_warnings.rb
9
+ lib/structured_warnings/dynamic.rb
10
+ lib/structured_warnings/kernel.rb
11
+ lib/structured_warnings/test.rb
12
+ lib/structured_warnings/test/assertions.rb
13
+ lib/structured_warnings/test/warner.rb
14
+ lib/structured_warnings/version.rb
15
+ lib/structured_warnings/warner.rb
16
+ lib/structured_warnings/warning.rb
17
+ lib/structured_warnings/warnings.rb
18
+ log/debug.log
19
+ script/destroy
20
+ script/generate
21
+ script/txt2html
22
+ setup.rb
23
+ tasks/deployment.rake
24
+ tasks/environment.rake
25
+ tasks/website.rake
26
+ test/test_helper.rb
27
+ test/test_structured_warnings.rb
28
+ website/index.html
29
+ website/index.txt
30
+ website/javascripts/rounded_corners_lite.inc.js
31
+ website/stylesheets/screen.css
32
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,4 @@
1
+ = Structured warnings
2
+
3
+ See the projects website on http://rug-b.rubyforge.org/structured_warnings or
4
+ the inspiring article at http://www.oreillynet.com/ruby/blog/2008/02/structured_warnings_now.html.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'structured_warnings/version'
2
+
3
+ AUTHOR = 'Gregor Schmidt' # can also be an array of Authors
4
+ EMAIL = "ruby@schmidtwisser.de"
5
+ DESCRIPTION = "Provides structured warnings"
6
+ GEM_NAME = 'structured_warnings' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'rug-b' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org/#{GEM_NAME}"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = StructuredWarnings::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'structured_warnings documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'structured_warnings'
@@ -0,0 +1,23 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require "structured_warnings/dynamic"
3
+ require "structured_warnings/kernel"
4
+ require "structured_warnings/warner"
5
+ require "structured_warnings/warning"
6
+
7
+ module StructuredWarnings
8
+ def self.init
9
+ Object.send(:include, Kernel)
10
+ unless Dynamic.variables.include?(:disabled_warnings)
11
+ Dynamic[:disabled_warnings] = []
12
+ Dynamic[:warner] = StructuredWarnings::Warner.new
13
+ end
14
+ init_test if defined? ::Test
15
+ end
16
+
17
+ def self.init_test
18
+ require "structured_warnings/test.rb"
19
+ ::Test::Unit::TestCase.send(:include, StructuredWarnings::Test::Assertions)
20
+ end
21
+ end
22
+
23
+ StructuredWarnings.init
@@ -0,0 +1,84 @@
1
+ # This library was created by Christian Neukirchen in the context of
2
+ # EuRuKo 2005 and is licensed under the same terms as Ruby.
3
+ #
4
+ # It provides dynamically scoped variables. It is used within ContextR to
5
+ # store the current, thread-wide activated layers.
6
+ #
7
+ # For more information see the corresponding slides at
8
+ # http://chneukirchen.org/talks/euruko-2005/chneukirchen-euruko2005-contextr.pdf
9
+ #
10
+ # (c) 2005 - Christian Neukirchen - http://chneukirchen.org
11
+ module Dynamic
12
+ module ClassMethods #:nodoc:
13
+ Thread.main[:DYNAMIC] = Hash.new { |hash, key|
14
+ raise NameError, "no such dynamic variable: #{key}"
15
+ }
16
+
17
+ def here!
18
+ Thread.current[:DYNAMIC] = Hash.new { |hash, key|
19
+ raise NameError, "no such dynamic variable: #{key}"
20
+ }.update Thread.main[:DYNAMIC]
21
+ end
22
+
23
+ def variables
24
+ Thread.current[:DYNAMIC] or here!
25
+ end
26
+
27
+ def variable(definition)
28
+ case definition
29
+ when Symbol
30
+ if variables.has_key? definition
31
+ raise NameError, "dynamic variable `#{definition}' already exists"
32
+ end
33
+ variables[definition] = nil
34
+ when Hash
35
+ definition.each { |key, value|
36
+ if variables.has_key? key
37
+ raise NameError, "dynamic variable `#{key}' already exists"
38
+ end
39
+ variables[key] = value
40
+ }
41
+ else
42
+ raise ArgumentError,
43
+ "can't create a new dynamic variable from #{definition.class}"
44
+ end
45
+ end
46
+
47
+ def [](key)
48
+ variables[key]
49
+ end
50
+
51
+ def []=(key, value)
52
+ variables[key] = value
53
+ end
54
+
55
+ def undefine(*keys)
56
+ keys.each { |key|
57
+ self[key]
58
+ variables.delete key
59
+ }
60
+ end
61
+
62
+ def let(bindings, &block)
63
+ save = {}
64
+ bindings.to_hash.collect { |key, value|
65
+ save[key] = self[key]
66
+ self[key] = value
67
+ }
68
+ block.call
69
+ ensure
70
+ variables.update save
71
+ end
72
+
73
+ def method_missing(name, *args)
74
+ if match = /=\Z/.match(name.to_s) # setter?
75
+ raise ArgumentError, "invalid setter call" unless args.size == 1
76
+ self[match.pre_match.intern] = args.first
77
+ else
78
+ raise ArgumentError, "invalid getter call" unless args.empty?
79
+ self[name]
80
+ end
81
+ end
82
+ end
83
+ extend ClassMethods
84
+ end
@@ -0,0 +1,38 @@
1
+ module StructuredWarnings
2
+ module Kernel
3
+ def warn(*args)
4
+ first = args.shift
5
+ if first.is_a? Class and first < Warning
6
+ warning = first
7
+ message = args.shift
8
+
9
+ elsif first.is_a? Warning
10
+ warning = first.class
11
+ message = first.message
12
+
13
+ else
14
+ warning = Warning
15
+ message = first.to_s
16
+ end
17
+
18
+ unless args.empty?
19
+ raise ArgumentError,
20
+ "wrong number of arguments (#{args.size + 2} for 2)"
21
+ end
22
+
23
+ if warning.active?
24
+ output = Kernel.warner.format(warning, message, caller[1..-1])
25
+ super(output) unless output.nil? or output.to_s.empty?
26
+ end
27
+ end
28
+
29
+ def self.warner
30
+ Dynamic[:warner]
31
+ end
32
+
33
+ protected
34
+ def structured_warn(warning, message)
35
+ nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ require "structured_warnings/test/warner.rb"
2
+ require "structured_warnings/test/assertions.rb"
@@ -0,0 +1,22 @@
1
+ module StructuredWarnings
2
+ module Test
3
+ module Assertions
4
+ def assert_no_warn(warning = Warning)
5
+ w = StructuredWarnings::Test::Warner.new
6
+ Dynamic.let(:warner => w) do
7
+ yield
8
+ end
9
+ assert !w.warned?(warning), "#{warning} has been emitted."
10
+ end
11
+
12
+ def assert_warn(warning = Warning)
13
+ w = StructuredWarnings::Test::Warner.new
14
+ Dynamic.let(:warner => w) do
15
+ yield
16
+ end
17
+ assert w.warned?(warning), "#{warning} has not been emitted."
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,18 @@
1
+ module StructuredWarnings
2
+ module Test
3
+ class Warner < StructuredWarnings::Warner
4
+ def format(warning, message, call_stack)
5
+ given_warnings << warning
6
+ nil
7
+ end
8
+
9
+ def warned?(warning)
10
+ given_warnings.any? {|w| (w <= warning)}
11
+ end
12
+
13
+ def given_warnings
14
+ @given_warnings ||= []
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module StructuredWarnings #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module StructuredWarnings
2
+ class Warner
3
+ def format(warning, message, stack)
4
+ "#{stack.shift} : #{message} (#{warning})"
5
+ end
6
+
7
+ # formats an exception like stack frame
8
+ # def collect_frame(stack)
9
+ # stack.collect { |frame| " from #{frame}" }.join("\n")
10
+ # end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ class Warning
2
+ attr_accessor :message
3
+
4
+ def initialize(message)
5
+ self.message = message
6
+ end
7
+
8
+ module ClassMethods
9
+ def active?
10
+ disabled_warnings.all? {|w| !(w >= self)}
11
+ end
12
+
13
+ def disable
14
+ if block_given?
15
+ Dynamic.let(:disabled_warnings => disabled_warnings + [self]) do
16
+ yield
17
+ end
18
+ else
19
+ self.disabled_warnings += [self]
20
+ end
21
+ end
22
+
23
+ def enable
24
+ if block_given?
25
+ Dynamic.let(:disabled_warnings => disabled_warnings - [self]) do
26
+ yield
27
+ end
28
+ else
29
+ self.disabled_warnings -= [self]
30
+ end
31
+ end
32
+
33
+ protected
34
+ def disabled_warnings
35
+ Dynamic[:disabled_warnings]
36
+ end
37
+ def disabled_warnings=(new)
38
+ Dynamic[:disabled_warnings] = new
39
+ end
40
+ end
41
+
42
+ extend ClassMethods
43
+ end
44
+
45
+ class DeprecationWarning < Warning; end
46
+ class DeprecatedMethodWarning < DeprecationWarning; end
47
+ class DeprecatedSignatureWarning < DeprecationWarning; end
@@ -0,0 +1,3 @@
1
+ class DeprecationWarning < Warning; end
2
+ class DeprecatedMethodWarning < DeprecationWarning; end
3
+ class DeprecatedSignatureWarning < DeprecationWarning; end
data/log/debug.log ADDED
File without changes