contextr 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +5 -18
  2. data/License.txt +20 -0
  3. data/Manifest.txt +15 -19
  4. data/README.txt +2 -49
  5. data/Rakefile +55 -88
  6. data/examples/general.rb +152 -0
  7. data/examples/ordering.rb +29 -0
  8. data/lib/contextr.rb +15 -15
  9. data/lib/contextr/class_methods.rb +90 -0
  10. data/lib/contextr/core_ext.rb +2 -0
  11. data/lib/contextr/core_ext/module.rb +18 -0
  12. data/lib/contextr/core_ext/object.rb +9 -0
  13. data/lib/contextr/event_machine.rb +71 -0
  14. data/lib/contextr/layer.rb +57 -381
  15. data/lib/contextr/modules/mutex_code.rb +22 -0
  16. data/lib/contextr/modules/unique_id.rb +13 -0
  17. data/lib/contextr/public_api.rb +58 -0
  18. data/lib/contextr/version.rb +2 -2
  19. data/lib/ext/active_support_subset.rb +85 -0
  20. data/spec/contextr_spec.rb +11 -0
  21. data/spec/spec.opts +1 -0
  22. data/spec/spec_helper.rb +1 -1
  23. data/test/test_contextr.rb +11 -0
  24. data/website/index.html +23 -101
  25. data/website/index.txt +27 -95
  26. data/website/stylesheets/screen.css +9 -0
  27. data/website/template.rhtml +3 -8
  28. metadata +21 -26
  29. data/COPYING.txt +0 -340
  30. data/LICENSE.txt +0 -57
  31. data/examples/education.rb +0 -71
  32. data/examples/fibonacci.rb +0 -124
  33. data/examples/with_current_context.rb +0 -29
  34. data/lib/contextr/contextr.rb +0 -160
  35. data/lib/core_ext/class.rb +0 -29
  36. data/lib/core_ext/module.rb +0 -62
  37. data/lib/core_ext/proc.rb +0 -53
  38. data/lib/ext/method_nature.rb +0 -80
  39. data/rake/group_spec_task.rb +0 -7
  40. data/rake/specific_group_spec_task.rb +0 -7
  41. data/spec/contextr/contextr_api_spec.rb +0 -126
  42. data/spec/contextr/contextr_class_side_spec.rb +0 -77
  43. data/spec/contextr/contextr_functional_spec.rb +0 -293
  44. data/spec/core_ext/module_spec.rb +0 -101
  45. data/spec/core_ext/proc_spec.rb +0 -61
  46. data/tasks/annotations.rb +0 -107
  47. data/test/contextr/test_contextr.rb +0 -7
@@ -1,19 +1,6 @@
1
- +++ 0.0.3 2007-05-22
1
+ == 0.1.0 2007-09-07
2
2
 
3
- + 3 major changes
4
- + Added #add_context_sensor and #with_current_context
5
- + Added #activate_layers and #deactivate_layers
6
- + Added support for class side methods
7
-
8
- +++ 0.0.2 2007-05-08
9
-
10
- + 1 major change:
11
- + Changed the wrapper execution order to a hopefully more natural ordering
12
- + Added documentation
13
- + 1 minor change:
14
- + finished transition from unit tests to rspec based specification
15
-
16
- +++ 0.0.1 2007-05-08
17
-
18
- + 1 major enhancement:
19
- + Initial release
3
+ * major changes
4
+ * reimplemented the whole stack
5
+ * changed the API significantly
6
+ * no backwards compatibility at all
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 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.
@@ -1,33 +1,29 @@
1
- COPYING.txt
2
1
  History.txt
3
- LICENSE.txt
2
+ License.txt
4
3
  Manifest.txt
5
4
  README.txt
6
5
  Rakefile
7
- examples/education.rb
8
- examples/fibonacci.rb
9
- examples/with_current_context.rb
6
+ examples/general.rb
7
+ examples/ordering.rb
10
8
  lib/contextr.rb
11
- lib/contextr/contextr.rb
9
+ lib/contextr/class_methods.rb
10
+ lib/contextr/core_ext.rb
11
+ lib/contextr/core_ext/module.rb
12
+ lib/contextr/core_ext/object.rb
13
+ lib/contextr/event_machine.rb
12
14
  lib/contextr/layer.rb
15
+ lib/contextr/modules/mutex_code.rb
16
+ lib/contextr/modules/unique_id.rb
17
+ lib/contextr/public_api.rb
13
18
  lib/contextr/version.rb
14
- lib/core_ext/class.rb
15
- lib/core_ext/module.rb
16
- lib/core_ext/proc.rb
19
+ lib/ext/active_support_subset.rb
17
20
  lib/ext/dynamic.rb
18
- lib/ext/method_nature.rb
19
- rake/group_spec_task.rb
20
- rake/specific_group_spec_task.rb
21
21
  scripts/txt2html
22
22
  setup.rb
23
- spec/contextr/contextr_api_spec.rb
24
- spec/contextr/contextr_class_side_spec.rb
25
- spec/contextr/contextr_functional_spec.rb
26
- spec/core_ext/module_spec.rb
27
- spec/core_ext/proc_spec.rb
23
+ spec/contextr_spec.rb
24
+ spec/spec.opts
28
25
  spec/spec_helper.rb
29
- tasks/annotations.rb
30
- test/contextr/test_contextr.rb
26
+ test/test_contextr.rb
31
27
  test/test_helper.rb
32
28
  website/index.html
33
29
  website/index.txt
data/README.txt CHANGED
@@ -1,50 +1,3 @@
1
- = ContextR
1
+ README for contextr
2
+ ===================
2
3
 
3
- A context-oriented programming library for Ruby.
4
-
5
- Inspired by ContextL (Pascal Costanza) and ContextS (Robert Hirschfeld) with
6
- thanks to Christian Neukirchen for giving the name and lots of ideas.
7
-
8
- For more information see
9
- - http://contextr.rubyforge.org/
10
- - http://www.contextr.org/ or
11
- - http://www.swa.hpi.uni-potsdam.de/cop/
12
-
13
- This code is published under the same license as Ruby. See LICENSE.txt for more
14
- information.
15
-
16
- (c) 2007 - Gregor Schmidt - Berlin, Germany
17
-
18
- = Usage
19
-
20
- require 'rubygems'
21
- require 'contextr'
22
-
23
- class A
24
- def a
25
- puts "a"
26
- end
27
-
28
- layer :foo
29
-
30
- foo.post :a do | n |
31
- n.return_value += "_with_context"
32
- end
33
- end
34
-
35
- A.new.a # => "a"
36
-
37
- ContextR::with_layers( :foo ) do
38
- A.new.a # => "a_with_context"
39
- end
40
-
41
- = Starting Points
42
-
43
- For a more detailed description
44
- - visit the project homepage at RubyForge[http://contextr.rubyforge.org/]
45
- - have a look at the +examples+ folder in the ContextR distribution
46
-
47
- For detailed API descriptions have a look at the following classes and modules
48
- - Class
49
- - ContextR::LayerInClass
50
- - ContextR::ClassMethods
data/Rakefile CHANGED
@@ -8,19 +8,48 @@ require 'rake/rdoctask'
8
8
  require 'rake/contrib/rubyforgepublisher'
9
9
  require 'fileutils'
10
10
  require 'hoe'
11
+ begin
12
+ require 'spec/rake/spectask'
13
+ rescue LoadError
14
+ puts 'To use rspec for testing you must install rspec gem:'
15
+ puts '$ sudo gem install rspec'
16
+ exit
17
+ end
18
+
11
19
  include FileUtils
12
20
  require File.join(File.dirname(__FILE__), 'lib', 'contextr', 'version')
13
21
 
14
- AUTHOR = 'schmidt' # can also be an array of Authors
22
+ AUTHOR = 'Gregor Schmidt' # can also be an array of Authors
15
23
  EMAIL = "ruby@schmidtwisser.de"
16
24
  DESCRIPTION = "The goal is to equip Ruby with an API to allow context-oriented programming."
17
25
  GEM_NAME = 'contextr' # what ppl will type to install your gem
26
+
27
+ @config_file = "~/.rubyforge/user-config.yml"
28
+ @config = nil
29
+ def rubyforge_username
30
+ unless @config
31
+ begin
32
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
33
+ rescue
34
+ puts <<-EOS
35
+ ERROR: No rubyforge config file found: #{@config_file}"
36
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
37
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
38
+ EOS
39
+ exit
40
+ end
41
+ end
42
+ @rubyforge_username ||= @config["username"]
43
+ end
44
+
18
45
  RUBYFORGE_PROJECT = 'contextr' # The unix name for your project
19
46
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
47
  DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
21
48
 
22
49
  NAME = "contextr"
23
- REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
50
+ REV = nil
51
+ # UNCOMMENT IF REQUIRED:
52
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
24
53
  VERS = ContextR::VERSION::STRING + (REV ? ".#{REV}" : "")
25
54
  CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
26
55
  RDOC_OPTS = ['--quiet', '--title', 'contextr documentation',
@@ -45,7 +74,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
45
74
  p.url = HOMEPATH
46
75
  p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
47
76
  p.test_globs = ["test/**/test_*.rb"]
48
- p.clean_globs = CLEAN #An array of file patterns to delete on clean.
77
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
49
78
 
50
79
  # == Optional
51
80
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
@@ -53,6 +82,9 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
53
82
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
54
83
  end
55
84
 
85
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
86
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
87
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
56
88
 
57
89
  desc 'Generate website files'
58
90
  task :website_generate do
@@ -63,19 +95,26 @@ end
63
95
 
64
96
  desc 'Upload website files to rubyforge'
65
97
  task :website_upload do
66
- config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
67
- host = "#{config["username"]}@rubyforge.org"
68
- remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
69
- # remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
98
+ host = "#{rubyforge_username}@rubyforge.org"
99
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
70
100
  local_dir = 'website'
71
- sh %{rsync -av --exclude=".*/" #{local_dir}/ #{host}:#{remote_dir}}
101
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
72
102
  end
73
103
 
74
104
  desc 'Generate and upload website files'
75
- task :website => [:website_generate, :website_upload]
105
+ task :website => [:website_generate, :website_upload, :publish_docs]
76
106
 
77
107
  desc 'Release the website and new gem version'
78
- task :deploy => [:check_version, :website, :release]
108
+ task :deploy => [:check_version, :website, :release] do
109
+ puts "Remember to create SVN tag:"
110
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
111
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
112
+ puts "Suggested comment:"
113
+ puts "Tagging release #{CHANGES}"
114
+ end
115
+
116
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
117
+ task :local_deploy => [:website_generate, :install_gem]
79
118
 
80
119
  task :check_version do
81
120
  unless ENV['VERSION']
@@ -88,83 +127,11 @@ task :check_version do
88
127
  end
89
128
  end
90
129
 
91
- #desc 'Submit the docs HTML files to RubyForge'
92
- #task :docs_publish => [ :docs ] do
93
- # config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
94
- # host = "#{config["username"]}@rubyforge.org"
95
- # remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/api"
96
- # local_dir = 'doc'
97
- # sh %{rsync -av --delete-excluded --exclude=".*/" #{local_dir}/ #{host}:#{remote_dir}}
98
- #end
99
-
100
- # Most of this code was taken from the Rubinius Rakefile.
101
- # Thanks for the help.
102
-
103
- ROOT = File.expand_path(File.dirname(__FILE__))
104
-
105
- def load_files(files)
106
- files.each do |path|
107
- begin
108
- require(path)
109
- rescue Object => e
110
- STDERR.puts "Unable to load #{path}. #{e.message} (#{e.class})"
111
- end
112
- end
130
+ desc "Run the specs under spec/models"
131
+ Spec::Rake::SpecTask.new do |t|
132
+ t.spec_opts = ['--options', "spec/spec.opts"]
133
+ t.spec_files = FileList['spec/*_spec.rb']
113
134
  end
114
- def require_files(files)
115
- files.each do |path|
116
- begin
117
- require(path)
118
- rescue Object => e
119
- STDERR.puts "Unable to load #{path}. #{e.message} (#{e.class})"
120
- end
121
- end
122
- end
123
-
124
- begin
125
- require 'spec/rake/spectask'
126
- rescue LoadError
127
- raise <<-EOM
128
- Unable to load spec/rake/spectask. RSpec is a requirement to build Rubinius.
129
- Please install RSpec before building (http://rspec.rubyforge.org).
130
- EOM
131
- end
132
-
133
- # Task class extensions
134
- paths = Dir[ File.join(File.dirname(__FILE__), 'rake/*') ]
135
- require_files(paths)
136
- #
137
- # Other tasks
138
- paths = Dir[ File.join(File.dirname(__FILE__), 'tasks/*') ]
139
- load_files(paths)
140
-
141
- desc "Run all specs and tests"
142
- task :default => [ :spec, :test ]
143
-
144
- task :spec => 'spec:all'
145
-
146
- # Generate all the spec tasks
147
- namespace :spec do
148
-
149
- spec_targets = %w(contextr core_ext)
150
-
151
- spec_targets.each do | group |
152
- spec_files = Dir[ File.join( File.dirname(__FILE__),
153
- "spec/#{group}/*_spec.rb") ]
154
-
155
- GroupSpecTask.new( group )
156
-
157
- namespace group do
158
- spec_files.each do | file |
159
- SpecificGroupSpecTask.new( File.basename( file, '_spec.rb'), group )
160
- end
161
- end
162
- end
163
-
164
- desc "Run all specs."
165
- task :all => spec_targets.collect! { | group | 'spec:' << group }
166
- end
167
-
168
- desc "Run all benchmarks - currently none"
169
- task :benchmark
170
135
 
136
+ desc "Run specs and tests by default"
137
+ task :default => [:spec, :test]
@@ -0,0 +1,152 @@
1
+ require File.dirname(__FILE__) + "/../lib/contextr.rb"
2
+
3
+ module Common
4
+ module AddressMethods
5
+ def to_s
6
+ [yield(:next), yield(:receiver).address].join("; ")
7
+ end
8
+ end
9
+ end
10
+
11
+ class Student < Struct.new(:first_name, :last_name, :address, :university)
12
+ def to_s
13
+ [first_name, last_name].join(" ")
14
+ end
15
+
16
+ module EducationMethods
17
+ def to_s
18
+ [yield(:next), yield(:receiver).university].join("; ")
19
+ end
20
+ end
21
+
22
+ include Common
23
+ include EducationMethods => :education
24
+ include AddressMethods => :address
25
+ end
26
+
27
+ class University < Struct.new(:name, :address)
28
+ def to_s
29
+ name
30
+ end
31
+
32
+ include Common
33
+ include AddressMethods => :address
34
+ end
35
+
36
+ module Fibonacci
37
+ module ClassMethods
38
+ def compute(fixnum)
39
+ if fixnum == 1 or fixnum == 0
40
+ fixnum
41
+ elsif fixnum < 0
42
+ raise ArgumentError, "Fibonacci not defined for negative numbers"
43
+ else
44
+ compute(fixnum - 1) + compute(fixnum - 2)
45
+ end
46
+ end
47
+
48
+ module LoggingMethods
49
+ def compute(fixnum)
50
+ print "."
51
+ yield(:next, fixnum)
52
+ end
53
+ end
54
+
55
+ module CacheMethods
56
+ def cache
57
+ @cache ||={}
58
+ end
59
+
60
+ def compute(fixnum)
61
+ cache[fixnum] ||= yield(:next, fixnum)
62
+ end
63
+ end
64
+ end
65
+
66
+ self.extend(ClassMethods)
67
+ include :class_side => true,
68
+ ClassMethods::CacheMethods => :cache,
69
+ ClassMethods::LoggingMethods => :logging
70
+ end
71
+
72
+ puts
73
+ puts "Example on Instance Side"
74
+ module Example
75
+ module ClassMethods
76
+ def show
77
+ me = Student.new("Gregor", "Schmidt", "Berlin")
78
+ hpi = University.new("HPI", "Potsdam")
79
+ me.university = hpi
80
+ print(me)
81
+ end
82
+
83
+ def print(me)
84
+ puts me
85
+ with_addresses do
86
+ puts me
87
+ end
88
+ with_education do
89
+ puts me
90
+ end
91
+ with_education do
92
+ with_addresses do
93
+ puts me
94
+ end
95
+ end
96
+ end
97
+
98
+ def with_addresses
99
+ ContextR::with_layers :address do
100
+ yield
101
+ end
102
+ end
103
+
104
+ def with_education
105
+ ContextR::with_layers :education do
106
+ yield
107
+ end
108
+ end
109
+ end
110
+ self.extend(ClassMethods)
111
+ end
112
+ Example.show
113
+
114
+ puts
115
+ puts "Example with changed instance methods after behaviour registration"
116
+ class Student
117
+ def to_s
118
+ [first_name, last_name].reverse.join(", ")
119
+ end
120
+ end
121
+ Example.show
122
+
123
+ puts
124
+ puts "Example with changed behaviour methods after their registration"
125
+ module Student::EducationMethods
126
+ def to_s
127
+ [yield(:next), yield(:receiver).university].join("\n - ")
128
+ end
129
+ end
130
+ Example.show
131
+
132
+ puts
133
+ puts "Example on Class Side"
134
+ class ExampleClassSide
135
+ module ClassMethods
136
+ def show(int = 3)
137
+ puts Fibonacci.compute(int)
138
+ ContextR::with_layers :cache do
139
+ puts Fibonacci.compute(int)
140
+ end
141
+ ContextR::with_layers :logging do
142
+ puts Fibonacci.compute(2 * int)
143
+
144
+ ContextR::with_layers :cache do
145
+ puts Fibonacci.compute(2 * int)
146
+ end
147
+ end
148
+ end
149
+ end
150
+ self.extend(ClassMethods)
151
+ end
152
+ ExampleClassSide.show