og 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/CHANGELOG +27 -0
  2. data/INSTALL +56 -0
  3. data/{README.og → README} +3 -3
  4. data/Rakefile +7 -73
  5. data/benchmark/bench.rb +75 -0
  6. data/benchmark/sqlite-no-prepare.1.txt +13 -0
  7. data/benchmark/sqlite-no-prepare.2.txt +13 -0
  8. data/benchmark/sqlite-prepare.1.txt +13 -0
  9. data/benchmark/sqlite-prepare.2.txt +13 -0
  10. data/doc/AUTHORS +0 -9
  11. data/{RELEASES.og → doc/RELEASES} +15 -0
  12. data/doc/config.txt +35 -0
  13. data/doc/tutorial.txt +595 -0
  14. data/examples/{og/README → README} +1 -1
  15. data/examples/{og/mock_example.rb → mock_example.rb} +1 -1
  16. data/examples/{og/mysql_to_psql.rb → mysql_to_psql.rb} +1 -1
  17. data/examples/{og/run.rb → run.rb} +1 -1
  18. data/install.rb +8 -5
  19. data/lib/og.rb +13 -8
  20. data/lib/og/adapter.rb +1 -1
  21. data/lib/og/adapters/filesys.rb +1 -1
  22. data/lib/og/adapters/mysql.rb +4 -3
  23. data/lib/og/adapters/oracle.rb +1 -1
  24. data/lib/og/adapters/psql.rb +4 -3
  25. data/lib/og/adapters/sqlite.rb +1 -1
  26. data/lib/og/backend.rb +1 -1
  27. data/lib/og/connection.rb +1 -1
  28. data/lib/og/database.rb +1 -1
  29. data/lib/og/meta.rb +13 -2
  30. data/lib/og/observer.rb +1 -1
  31. data/lib/og/typemacros.rb +1 -1
  32. data/lib/og/validation.rb +81 -0
  33. data/test/og/tc_validation.rb +89 -0
  34. metadata +33 -65
  35. data/ChangeLog +0 -1549
  36. data/lib/glue.rb +0 -55
  37. data/lib/glue/array.rb +0 -61
  38. data/lib/glue/attribute.rb +0 -83
  39. data/lib/glue/cache.rb +0 -138
  40. data/lib/glue/flexob.rb +0 -12
  41. data/lib/glue/hash.rb +0 -122
  42. data/lib/glue/inflector.rb +0 -91
  43. data/lib/glue/logger.rb +0 -147
  44. data/lib/glue/misc.rb +0 -14
  45. data/lib/glue/mixins.rb +0 -36
  46. data/lib/glue/number.rb +0 -24
  47. data/lib/glue/object.rb +0 -32
  48. data/lib/glue/pool.rb +0 -60
  49. data/lib/glue/property.rb +0 -408
  50. data/lib/glue/string.rb +0 -162
  51. data/lib/glue/time.rb +0 -85
  52. data/lib/glue/validation.rb +0 -394
  53. data/vendor/extensions/_base.rb +0 -153
  54. data/vendor/extensions/_template.rb +0 -36
  55. data/vendor/extensions/all.rb +0 -21
  56. data/vendor/extensions/array.rb +0 -68
  57. data/vendor/extensions/binding.rb +0 -224
  58. data/vendor/extensions/class.rb +0 -50
  59. data/vendor/extensions/continuation.rb +0 -71
  60. data/vendor/extensions/enumerable.rb +0 -250
  61. data/vendor/extensions/hash.rb +0 -23
  62. data/vendor/extensions/io.rb +0 -58
  63. data/vendor/extensions/kernel.rb +0 -42
  64. data/vendor/extensions/module.rb +0 -114
  65. data/vendor/extensions/numeric.rb +0 -230
  66. data/vendor/extensions/object.rb +0 -164
  67. data/vendor/extensions/ostruct.rb +0 -41
  68. data/vendor/extensions/string.rb +0 -316
  69. data/vendor/extensions/symbol.rb +0 -28
@@ -1,153 +0,0 @@
1
-
2
- #
3
- # This file is 'required' by all files that implement standard class
4
- # extensions as part of the "Ruby/Extensions" project.
5
- #
6
- # The "Extensions" project requires 1.8.0 or greater to run, as it is too
7
- # much hassle at the moment to consider supporting older versions. That may
8
- # one day be implemented if demand is there. One option would be to require
9
- # "shim", so that we can assume all 1.8 library methods are implemented.
10
- #
11
- # This file is only of interest to developers of the package, so no detailed
12
- # documentation is included here. However, by way of introduction, this is what
13
- # it's all about. Each method that is implemented as part of this package is
14
- # done so through a framework implemented in this file. Take the following
15
- # simple example:
16
- #
17
- # ExtensionsProject.implement(Integer, :even?, :instance) do
18
- # class Integer
19
- # #
20
- # # RDoc comments.
21
- # #
22
- # def even?
23
- # self % 2 == 0
24
- # end
25
- # end
26
- # end
27
- #
28
- # This purposes of this are as follows:
29
- # - if the intended method (in this case IO.write) is already defined,
30
- # we don't want to overwrite it (we issue a warning and move on)
31
- # - if the intended method is _not_ implemented as a result of the block,
32
- # we have not done as we said, and an error is raised
33
- # - the ExtensionsProject class gathers information on which methods have
34
- # been implemented, making for a very handy command-line reference (+rbxtm+)
35
- #
36
- # The <tt>ExtensionsProject.implement</tt> method is responsible for ensuring
37
- # these are so. It gives us documentation, and some assurance that the
38
- # extensions are doing what we say they are doing.
39
- #
40
-
41
- # :enddoc:
42
-
43
- #
44
- # For what reason does Ruby define Module#methods, Module#instance_methods,
45
- # and Module#method_defined?, but not Module#instance_method_defined? ?
46
- #
47
- # No matter, extending standard classes is the name of the game here.
48
- #
49
- class Module
50
- if Module.method_defined?(:instance_method_defined?)
51
- STDERR.puts "Warning: Module#instance_method_defined? already defined; not overwriting"
52
- else
53
- def instance_method_defined?(_method)
54
- instance_methods(true).find { |m| m == _method.to_s }
55
- end
56
- end
57
-
58
- if Module.method_defined?(:module_method_defined?)
59
- STDERR.puts "Warning: Module#module_method_defined? already defined; not overwriting"
60
- else
61
- def module_method_defined?(_method)
62
- singleton_methods(true).find { |m| m == _method.to_s }
63
- end
64
- end
65
- end
66
-
67
-
68
- class ExtensionsProject
69
-
70
- class << ExtensionsProject
71
- @@extension_methods = []
72
-
73
- #
74
- # The list of methods implemented in this project.
75
- #
76
- def extension_methods
77
- @@extension_methods
78
- end
79
-
80
- #
81
- # Return the name of the project. To be used in error messages, etc., for
82
- # consistency.
83
- #
84
- def project_name
85
- "Ruby/Extensions"
86
- end
87
-
88
- #
89
- # Wraps around the implementation of a method, emitting a warning if the
90
- # method is already defined. Returns true to indicate - false to indicate
91
- # failure (i.e. method is already defined). Raises an error if the
92
- # specified method is not actually implemented by the block.
93
- #
94
- def implement(_module, _method, _type=:instance)
95
- raise "Internal error: #{__FILE__}:#{__LINE__}" unless
96
- _module.is_a? Module and
97
- _method.is_a? Symbol and
98
- _type == :instance or _type == :class or _type == :module
99
-
100
- fullname = _module.to_s + string_rep(_type) + _method.to_s
101
-
102
- if _defined?(_module, _method, _type)
103
- STDERR.puts "#{project_name}: #{fullname} is already defined; not overwriting"
104
- return false
105
- else
106
- yield # Perform the block; presumably a method implementation.
107
- if _method == :initialize and _type == :instance
108
- # Special case; we can't verify this.
109
- @@extension_methods<< "#{_module}::new"
110
- else
111
- unless _defined?(_module, _method, _type)
112
- raise "#{project_name}: internal error: was supposed to implement " +
113
- "#{fullname}, but it didn't!"
114
- end
115
- @@extension_methods << fullname
116
- end
117
- return true
118
- end
119
- end
120
-
121
-
122
- # See whether the given module implements the given method, taking account
123
- # of the type (class/instance) required.
124
- def _defined?(_module, _method, _type)
125
- case _type
126
- when :instance
127
- _module.instance_method_defined?(_method) # See definition above.
128
- when :class, :module
129
- _module.module_method_defined?(_method) # See definition above.
130
- end
131
- end
132
- private :_defined?
133
-
134
-
135
- # Return the string representation of the given method type.
136
- def string_rep(method_type)
137
- case method_type
138
- when :instance then "#"
139
- when :class then "."
140
- when :module then "."
141
- else
142
- nil
143
- end
144
- end
145
- private :string_rep
146
- end
147
- end # class ExtensionsProject
148
-
149
-
150
- if VERSION < "1.8.0"
151
- raise "#{ExtensionsProject.project_name} requires Ruby 1.8.0 at least (for now)"
152
- end
153
-
@@ -1,36 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
- # A template for new files in the project; of no interest to end users. An
3
- # error will be raised if you +require+ it.
4
- #--
5
- # :enddoc:
6
- #
7
- # == extensions/XXX.rb
8
- #
9
- # Adds methods to the builtin XXX class.
10
- #
11
-
12
- raise "Do not load this file!"
13
-
14
- require "extensions/_base"
15
-
16
- #
17
- # * Enumerable#build_hash
18
- #
19
- ExtensionsProject.implement(Enumerable, :build_hash) do
20
- module Enumerable
21
- #
22
- # Like #map/#collect, but it generates a Hash.
23
- #
24
- # [1,5,11].build_hash { |x| [x, x**2] }
25
- # => { 1 => 2, 5 => 25, 11 => 121 }
26
- #
27
- def build_hash
28
- result = {}
29
- self.each do |elt|
30
- key, value = yield elt
31
- result[key] = value
32
- end
33
- result
34
- end
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- #
2
- # == extensions/all.rb
3
- #
4
- # Require this file in order to access all of the standard class extensions
5
- # available, or require individual extension files to narrow the selection.
6
- #
7
-
8
- require 'extensions/array.rb'
9
- require 'extensions/binding.rb'
10
- require 'extensions/class.rb'
11
- require 'extensions/continuation.rb'
12
- require 'extensions/enumerable.rb'
13
- require 'extensions/hash.rb'
14
- require 'extensions/io.rb'
15
- require 'extensions/kernel.rb'
16
- require 'extensions/module.rb'
17
- require 'extensions/numeric.rb'
18
- require 'extensions/object.rb'
19
- require 'extensions/ostruct.rb'
20
- require 'extensions/string.rb'
21
- require 'extensions/symbol.rb'
@@ -1,68 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
- #
3
- # == extensions/array.rb
4
- #
5
- # Adds methods to the builtin Array class.
6
- #
7
-
8
- require "extensions/_base"
9
-
10
- #
11
- # * Array#select!
12
- #
13
- ExtensionsProject.implement(Array, :select!) do
14
- class Array
15
- #
16
- # In-place version of Array#select. (Counterpart to, and opposite of, the
17
- # built-in #reject!)
18
- #
19
- def select!
20
- reject! { |e| not yield(e) }
21
- end
22
- end
23
- end
24
-
25
-
26
- #
27
- # * Array#only
28
- #
29
- ExtensionsProject.implement(Array, :only) do
30
- class Array
31
- #
32
- # Returns the _only_ element in the array. Raises an IndexError if the array's size is not
33
- # 1.
34
- #
35
- # [5].only # -> 5
36
- # [1,2,3].only # -> IndexError
37
- # [].only # -> IndexError
38
- #
39
- def only
40
- unless size == 1
41
- raise IndexError, "Array#only called on non-single-element array"
42
- end
43
- first
44
- end
45
- end
46
- end
47
-
48
- #
49
- # * Array#rand
50
- #
51
- ExtensionsProject.implement(Array, :rand) do
52
- class Array
53
- #
54
- # Return a randomly-chosen (using Kernel.rand) element from the array.
55
- #
56
- # arr = [48, 71, 3, 39, 15]
57
- # arr.rand # -> 71
58
- # arr.rand # -> 39
59
- # arr.rand # -> 48
60
- # # etc.
61
- #
62
- def rand
63
- idx = Kernel.rand(size)
64
- at(idx)
65
- end
66
- end
67
- end
68
-
@@ -1,224 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
- #
3
- # == extensions/binding.rb
4
- #
5
- # Adds methods to the builtin Binding class.
6
- #
7
-
8
- require "extensions/_base"
9
- require "extensions/continuation"
10
-
11
- #
12
- # Ruby's built-in Binding class doesn't contain any methods. It is merely a "context" object
13
- # that can be used in calls to <tt>Kernel.eval</tt>, like this:
14
- #
15
- # def example(_binding)
16
- # return eval("x", _binding)
17
- # end
18
- #
19
- # x = 55
20
- # current_binding = Kernel.binding
21
- # example(current_binding) # -> 55
22
- #
23
- # The most useful method introduced to Binding by the _extensions_ package is
24
- # Binding.of_caller. It allows you to access the binding of the calling method, thus
25
- # enabling you to access local variables in that scope. The other methods are a convenient
26
- # object-oriented facade for operations that you can already do with #eval as demonstrated
27
- # above. Here is an example that showcases all of the Binding methods included in
28
- # _extensions_.
29
- #
30
- # def example
31
- # Binding.of_caller do |b|
32
- # puts "x + y = #{b.eval('x + y')}"
33
- # puts "x = #{b[:x]}"
34
- # puts "Local variables: " + b.local_variables.join(', ')
35
- # b[:y] += 1
36
- # puts "Changed value of y in calling context to #{b[:y]}"
37
- # puts "Is 'z' defined in calling context? " + (b.defined?(:z) ? 'Yes' : 'No')
38
- # end
39
- # end
40
- #
41
- # x = 5
42
- # y = 17
43
- # example
44
- # y # -> 18
45
- #
46
- # Binding.of_caller was written by Florian Gross. The other methods were written by Tom
47
- # Sawyer.
48
- #
49
- class Binding
50
- end
51
-
52
- #
53
- # * Binding.of_caller
54
- #
55
- ExtensionsProject.implement(Binding, :of_caller, :class) do
56
- class Binding
57
- #
58
- # This method returns the binding of the method that called your method, enabling you to
59
- # access its local variables. If you call it without being in a method, it will raise an
60
- # Exception.
61
- #
62
- # === Example
63
- #
64
- # def inc_counter
65
- # Binding.of_caller do |b|
66
- # eval("counter += 1", b)
67
- # end
68
- # # <--- line (A)
69
- # end
70
- # counter = 0
71
- # inc_counter
72
- # inc_counter
73
- # counter # -> 2
74
- #
75
- # === Warning
76
- #
77
- # <tt>Binding.of_caller</tt> must be the _last_ method call in the method. For example,
78
- # if you insert some code at line *A* in the example above, an Exception will be raised.
79
- # You'll get away with a simple assignment, but anything involving a method call is
80
- # trouble.
81
- #
82
- # === Explanation
83
- #
84
- # It works by installing a temporary trace_func (see Kernel.set_trace_func). This makes
85
- # available -- to the trace function -- the binding of a method after it has returned.
86
- # Using a continuation, <tt>Binding.of_caller</tt> will let _your_ method return,
87
- # retrieve the binding, and return to the <tt>of_caller</tt> call with that binding in
88
- # hand. This time it executes the block.
89
- #
90
- # Because it is actually running <tt>Binding.of_caller</tt> twice, and returning from
91
- # your method twice, any code between the <tt>of_caller</tt> call and the end of your
92
- # method will be run twice. This is obviously not desirable, so an Exception is raised
93
- # if any code is found.
94
- #
95
- # See the thread around ruby-talk:109607 for more discussion.
96
- #
97
- # === Extra Warning
98
- #
99
- # If you have a trace function in place, <tt>Binding.of_caller</tt> will destroy that.
100
- # Ruby does not allow you to access the current trace function, so it can't be restored
101
- # afterwards. XXX: will this clash with the profiler and/or debugger?
102
- #
103
- # === Credits
104
- #
105
- # <tt>Binding.of_caller</tt> was written by Florian Frank.
106
- #
107
- def Binding.of_caller(&block)
108
- old_critical = Thread.critical
109
- Thread.critical = true
110
- count = 0
111
- cc, result, error = Continuation.create(nil, nil)
112
- error.call if error
113
-
114
- tracer = lambda do |*args|
115
- type, context = args[0], args[4]
116
- if type == "return"
117
- count += 1
118
- # First this method and then calling one will return --
119
- # the trace event of the second event gets the context
120
- # of the method which called the method that called this
121
- # method.
122
- if count == 2
123
- # It would be nice if we could restore the trace_func
124
- # that was set before we swapped in our own one, but
125
- # this is impossible without overloading set_trace_func
126
- # in current Ruby.
127
- set_trace_func(nil)
128
- cc.call(eval("binding", context), nil)
129
- end
130
- elsif type != "line"
131
- set_trace_func(nil)
132
- error_msg = "Binding.of_caller used in non-method context or " +
133
- "trailing statements of method using it aren't in the block."
134
- cc.call(nil, lambda { raise(Exception, error_msg ) })
135
- end
136
- end
137
-
138
- unless result
139
- set_trace_func(tracer)
140
- return nil
141
- else
142
- Thread.critical = old_critical
143
- yield result
144
- end
145
- end
146
- end # class Binding
147
- end
148
-
149
-
150
- #
151
- # * Binding#eval
152
- #
153
- ExtensionsProject.implement(Binding, :eval, :instance) do
154
- class Binding
155
- #
156
- # Evaluates the given string in the context of this binding.
157
- #
158
- def eval(str)
159
- Kernel.eval(str, self)
160
- end
161
- end
162
- end
163
-
164
-
165
- #
166
- # * Binding#local_variables
167
- #
168
- ExtensionsProject.implement(Binding, :local_variables, :instance) do
169
- class Binding
170
- #
171
- # Returns the variables that are local to this binding.
172
- #
173
- def local_variables
174
- self.eval('local_variables')
175
- end
176
- end
177
- end
178
-
179
-
180
- #
181
- # * Binding#[]
182
- #
183
- ExtensionsProject.implement(Binding, :[], :instance) do
184
- class Binding
185
- #
186
- # Returns the value of the given variable in this binding.
187
- #
188
- def [](variable)
189
- self.eval(variable.to_s)
190
- end
191
- end
192
- end
193
-
194
-
195
- #
196
- # * Binding#[]=
197
- #
198
- ExtensionsProject.implement(Binding, :[]=, :instance) do
199
- class Binding
200
- #
201
- # Sets the given variable (in this binding) to the given value.
202
- #
203
- def []=(variable, value)
204
- self.eval("lambda { |v| #{variable} = v }").call(value)
205
- end
206
- end
207
- end
208
-
209
-
210
- #
211
- # * Binding#defined?
212
- #
213
- ExtensionsProject.implement(Binding, :defined?, :instance) do
214
- class Binding
215
- #
216
- # Evaluates <tt>defined?</tt> in this binding.
217
- #
218
- def defined?(variable)
219
- self.eval("defined?(#{variable})")
220
- end
221
- end
222
- end
223
-
224
-