contextr 0.0.3 → 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/History.txt +5 -18
- data/License.txt +20 -0
- data/Manifest.txt +15 -19
- data/README.txt +2 -49
- data/Rakefile +55 -88
- data/examples/general.rb +152 -0
- data/examples/ordering.rb +29 -0
- data/lib/contextr.rb +15 -15
- data/lib/contextr/class_methods.rb +90 -0
- data/lib/contextr/core_ext.rb +2 -0
- data/lib/contextr/core_ext/module.rb +18 -0
- data/lib/contextr/core_ext/object.rb +9 -0
- data/lib/contextr/event_machine.rb +71 -0
- data/lib/contextr/layer.rb +57 -381
- data/lib/contextr/modules/mutex_code.rb +22 -0
- data/lib/contextr/modules/unique_id.rb +13 -0
- data/lib/contextr/public_api.rb +58 -0
- data/lib/contextr/version.rb +2 -2
- data/lib/ext/active_support_subset.rb +85 -0
- data/spec/contextr_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -1
- data/test/test_contextr.rb +11 -0
- data/website/index.html +23 -101
- data/website/index.txt +27 -95
- data/website/stylesheets/screen.css +9 -0
- data/website/template.rhtml +3 -8
- metadata +21 -26
- data/COPYING.txt +0 -340
- data/LICENSE.txt +0 -57
- data/examples/education.rb +0 -71
- data/examples/fibonacci.rb +0 -124
- data/examples/with_current_context.rb +0 -29
- data/lib/contextr/contextr.rb +0 -160
- data/lib/core_ext/class.rb +0 -29
- data/lib/core_ext/module.rb +0 -62
- data/lib/core_ext/proc.rb +0 -53
- data/lib/ext/method_nature.rb +0 -80
- data/rake/group_spec_task.rb +0 -7
- data/rake/specific_group_spec_task.rb +0 -7
- data/spec/contextr/contextr_api_spec.rb +0 -126
- data/spec/contextr/contextr_class_side_spec.rb +0 -77
- data/spec/contextr/contextr_functional_spec.rb +0 -293
- data/spec/core_ext/module_spec.rb +0 -101
- data/spec/core_ext/proc_spec.rb +0 -61
- data/tasks/annotations.rb +0 -107
- data/test/contextr/test_contextr.rb +0 -7
@@ -1,101 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe 'Each first level module' do
|
4
|
-
it 'should have the same name and namespace_free_name' do
|
5
|
-
Math.namespace_free_name.should == Math.name
|
6
|
-
Kernel.namespace_free_name.should == Kernel.name
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should have a namespace_free_name matching their constant' do
|
10
|
-
Kernel.namespace_free_name.should == Kernel.to_s
|
11
|
-
Kernel.namespace_free_name.should == "Kernel"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'Each sublevel module' do
|
16
|
-
before do
|
17
|
-
module ModuleTestA
|
18
|
-
module B
|
19
|
-
module C
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should have a namespace free namespace_free_name' do
|
26
|
-
ModuleTestA::B.namespace_free_name.should == "B"
|
27
|
-
ModuleTestA::B::C.namespace_free_name.should == "C"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "Each module" do
|
32
|
-
it "should have a attr_accessor_with_default_setter" do
|
33
|
-
lambda do
|
34
|
-
class ClassSpecA
|
35
|
-
attr_accessor_with_default_setter :miau do
|
36
|
-
{}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end.should_not raise_error
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "Each instance" do
|
44
|
-
before do
|
45
|
-
@instance = ClassSpecA.new
|
46
|
-
@instance2 = ClassSpecA.new
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should provide a getter method" do
|
50
|
-
@instance.should respond_to( :miau )
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should provide a setter method" do
|
54
|
-
@instance.should respond_to( :miau= )
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "A getter method" do
|
60
|
-
before do
|
61
|
-
@getter = ClassSpecA.instance_method( :miau )
|
62
|
-
@instance = ClassSpecA.new
|
63
|
-
@instance2 = ClassSpecA.new
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should not expect a parameter" do
|
67
|
-
@getter.arity.should == 0
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should provide the default value" do
|
71
|
-
@instance.miau.should == Hash.new
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should provide the default value also multiple times" do
|
75
|
-
@instance.miau.object_id.should == @instance.miau.object_id
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should provide the different default values for different " +
|
79
|
-
"instances" do
|
80
|
-
@instance2.miau.object_id.should_not == @instance.miau.object_id
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "A setter method" do
|
85
|
-
before do
|
86
|
-
@setter = ClassSpecA.instance_method( :miau= )
|
87
|
-
@instance = ClassSpecA.new
|
88
|
-
@instance2 = ClassSpecA.new
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should not expect a parameter" do
|
92
|
-
@setter.arity.should == 1
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should allow the setting of the corresonding instance variable" do
|
96
|
-
begin
|
97
|
-
@instance.miau = "blue"
|
98
|
-
end.should == "blue"
|
99
|
-
@instance.instance_variable_get( :@miau ).should == "blue"
|
100
|
-
end
|
101
|
-
end
|
data/spec/core_ext/proc_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
class ProcSpecFoo
|
4
|
-
def non_contextified_method
|
5
|
-
"non_contextified_method"
|
6
|
-
end
|
7
|
-
def foo
|
8
|
-
"foo"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "A Proc" do
|
13
|
-
before do
|
14
|
-
@a = lambda do @a = true; "a" end
|
15
|
-
@b = lambda do @b = true; "b" end
|
16
|
-
@foo = ProcSpecFoo.new
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should convert itself to an unbound method" do
|
20
|
-
@b.to_unbound_method( ProcSpecFoo ).should be_a_kind_of( UnboundMethod )
|
21
|
-
end
|
22
|
-
|
23
|
-
it "which should be bindable to an instance of the specified class" do
|
24
|
-
lambda do
|
25
|
-
@b.to_unbound_method( ProcSpecFoo ).bind( @foo )
|
26
|
-
end.should_not raise_error
|
27
|
-
end
|
28
|
-
|
29
|
-
it "which should execute the proc in turn" do
|
30
|
-
@b.to_unbound_method( ProcSpecFoo ).bind( @foo ).call.should == "b"
|
31
|
-
@foo.instance_variable_get( :@b ).should == true
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should respond to `+`" do
|
35
|
-
@b.should respond_to( :+ )
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should build a joined block with `self.+( other_proc)`" do
|
39
|
-
(@a + @b).should be_a_kind_of( Proc )
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "The result of `+` of two Procs" do
|
44
|
-
before do
|
45
|
-
@a = lambda do | arg |
|
46
|
-
arg || "a"
|
47
|
-
end
|
48
|
-
@b = lambda do | arg |
|
49
|
-
arg || "b"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should give the correct return value" do
|
54
|
-
(@a + @b).call( nil ).should == "b"
|
55
|
-
(@b + @a).call( nil ).should == "a"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should pass through given parameters" do
|
59
|
-
(@a + @b).call( 1 ).should == 1
|
60
|
-
end
|
61
|
-
end
|
data/tasks/annotations.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
# The following copyright applies to this File
|
2
|
-
# which we borrowed from rails.
|
3
|
-
#
|
4
|
-
# Copyright (c) 2004 David Heinemeier Hansson
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
-
# a copy of this software and associated documentation files (the
|
8
|
-
# "Software"), to deal in the Software without restriction, including
|
9
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
-
# the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be
|
15
|
-
# included in all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
-
class SourceAnnotationExtractor
|
25
|
-
class Annotation < Struct.new(:line, :tag, :text)
|
26
|
-
def to_s(options={})
|
27
|
-
s = "[%3d] " % line
|
28
|
-
s << "[#{tag}] " if options[:tag]
|
29
|
-
s << text
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.enumerate(tag, options={})
|
34
|
-
extractor = new(tag)
|
35
|
-
extractor.display(extractor.find, options)
|
36
|
-
end
|
37
|
-
|
38
|
-
attr_reader :tag
|
39
|
-
|
40
|
-
def initialize(tag)
|
41
|
-
@tag = tag
|
42
|
-
end
|
43
|
-
|
44
|
-
def find(dirs=%w(app lib test))
|
45
|
-
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
|
46
|
-
end
|
47
|
-
|
48
|
-
def find_in(dir)
|
49
|
-
results = {}
|
50
|
-
|
51
|
-
Dir.glob("#{dir}/*") do |item|
|
52
|
-
next if File.basename(item)[0] == ?.
|
53
|
-
|
54
|
-
if File.directory?(item)
|
55
|
-
results.update(find_in(item))
|
56
|
-
elsif item =~ /\.r(?:b|xml|js)$/
|
57
|
-
results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
|
58
|
-
elsif item =~ /\.rhtml$/
|
59
|
-
results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
results
|
64
|
-
end
|
65
|
-
|
66
|
-
def extract_annotations_from(file, pattern)
|
67
|
-
lineno = 0
|
68
|
-
result = File.readlines(file).inject([]) do |list, line|
|
69
|
-
lineno += 1
|
70
|
-
next list unless line =~ pattern
|
71
|
-
list << Annotation.new(lineno, $1, $2)
|
72
|
-
end
|
73
|
-
result.empty? ? {} : { file => result }
|
74
|
-
end
|
75
|
-
|
76
|
-
def display(results, options={})
|
77
|
-
results.keys.sort.each do |file|
|
78
|
-
puts "#{file}:"
|
79
|
-
results[file].each do |note|
|
80
|
-
puts " * #{note.to_s(options)}"
|
81
|
-
end
|
82
|
-
puts
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
desc "Enumerate all annotations"
|
88
|
-
task :notes do
|
89
|
-
SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
|
90
|
-
end
|
91
|
-
|
92
|
-
namespace :notes do
|
93
|
-
desc "Enumerate all OPTIMIZE annotations"
|
94
|
-
task :optimize do
|
95
|
-
SourceAnnotationExtractor.enumerate "OPTIMIZE"
|
96
|
-
end
|
97
|
-
|
98
|
-
desc "Enumerate all FIXME annotations"
|
99
|
-
task :fixme do
|
100
|
-
SourceAnnotationExtractor.enumerate "FIXME"
|
101
|
-
end
|
102
|
-
|
103
|
-
desc "Enumerate all TODO annotations"
|
104
|
-
task :todo do
|
105
|
-
SourceAnnotationExtractor.enumerate "TODO"
|
106
|
-
end
|
107
|
-
end
|