datamapper 0.3.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/History.txt +0 -0
  2. data/Manifest.txt +5 -0
  3. data/README.txt +11 -0
  4. data/Rakefile +70 -0
  5. data/lib/datamapper.rb +8 -0
  6. metadata +152 -319
  7. data/CHANGELOG +0 -145
  8. data/FAQ +0 -96
  9. data/MIT-LICENSE +0 -22
  10. data/QUICKLINKS +0 -12
  11. data/README +0 -105
  12. data/environment.rb +0 -62
  13. data/example.rb +0 -156
  14. data/lib/data_mapper.rb +0 -88
  15. data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
  16. data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
  17. data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
  18. data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
  19. data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
  20. data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
  21. data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
  22. data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
  23. data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
  24. data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
  25. data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
  26. data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
  27. data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
  28. data/lib/data_mapper/associations.rb +0 -106
  29. data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
  30. data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
  31. data/lib/data_mapper/associations/has_many_association.rb +0 -283
  32. data/lib/data_mapper/associations/has_n_association.rb +0 -143
  33. data/lib/data_mapper/associations/reference.rb +0 -47
  34. data/lib/data_mapper/attributes.rb +0 -73
  35. data/lib/data_mapper/auto_migrations.rb +0 -36
  36. data/lib/data_mapper/base.rb +0 -17
  37. data/lib/data_mapper/callbacks.rb +0 -107
  38. data/lib/data_mapper/context.rb +0 -112
  39. data/lib/data_mapper/database.rb +0 -234
  40. data/lib/data_mapper/dependency_queue.rb +0 -28
  41. data/lib/data_mapper/embedded_value.rb +0 -145
  42. data/lib/data_mapper/identity_map.rb +0 -47
  43. data/lib/data_mapper/is/tree.rb +0 -121
  44. data/lib/data_mapper/migration.rb +0 -155
  45. data/lib/data_mapper/persistence.rb +0 -852
  46. data/lib/data_mapper/property.rb +0 -310
  47. data/lib/data_mapper/query.rb +0 -164
  48. data/lib/data_mapper/support/blank.rb +0 -35
  49. data/lib/data_mapper/support/connection_pool.rb +0 -117
  50. data/lib/data_mapper/support/enumerable.rb +0 -35
  51. data/lib/data_mapper/support/errors.rb +0 -16
  52. data/lib/data_mapper/support/inflector.rb +0 -265
  53. data/lib/data_mapper/support/object.rb +0 -54
  54. data/lib/data_mapper/support/serialization.rb +0 -96
  55. data/lib/data_mapper/support/silence.rb +0 -10
  56. data/lib/data_mapper/support/string.rb +0 -72
  57. data/lib/data_mapper/support/struct.rb +0 -7
  58. data/lib/data_mapper/support/symbol.rb +0 -82
  59. data/lib/data_mapper/support/typed_set.rb +0 -65
  60. data/lib/data_mapper/types/base.rb +0 -44
  61. data/lib/data_mapper/types/string.rb +0 -34
  62. data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
  63. data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
  64. data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
  65. data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
  66. data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
  67. data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
  68. data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
  69. data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
  70. data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
  71. data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
  72. data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
  73. data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
  74. data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
  75. data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
  76. data/lib/data_mapper/validations.rb +0 -20
  77. data/lib/data_mapper/validations/number_validator.rb +0 -40
  78. data/lib/data_mapper/validations/string_validator.rb +0 -20
  79. data/lib/data_mapper/validations/validator.rb +0 -13
  80. data/performance.rb +0 -307
  81. data/plugins/can_has_sphinx/LICENSE +0 -23
  82. data/plugins/can_has_sphinx/README +0 -4
  83. data/plugins/can_has_sphinx/REVISION +0 -1
  84. data/plugins/can_has_sphinx/Rakefile +0 -22
  85. data/plugins/can_has_sphinx/init.rb +0 -1
  86. data/plugins/can_has_sphinx/install.rb +0 -1
  87. data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
  88. data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
  89. data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
  90. data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
  91. data/profile_data_mapper.rb +0 -40
  92. data/rakefile.rb +0 -159
  93. data/spec/acts_as_tree_spec.rb +0 -67
  94. data/spec/adapters/data_object_adapter_spec.rb +0 -31
  95. data/spec/associations/belongs_to_association_spec.rb +0 -98
  96. data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
  97. data/spec/associations/has_many_association_spec.rb +0 -337
  98. data/spec/attributes_spec.rb +0 -52
  99. data/spec/auto_migrations_spec.rb +0 -101
  100. data/spec/callbacks_spec.rb +0 -186
  101. data/spec/can_has_sphinx.rb +0 -5
  102. data/spec/coersion_spec.rb +0 -41
  103. data/spec/column_spec.rb +0 -114
  104. data/spec/count_command_spec.rb +0 -45
  105. data/spec/database_spec.rb +0 -18
  106. data/spec/dataobjects_spec.rb +0 -27
  107. data/spec/delete_command_spec.rb +0 -11
  108. data/spec/dependency_spec.rb +0 -29
  109. data/spec/embedded_value_spec.rb +0 -161
  110. data/spec/fixtures/animals.yaml +0 -33
  111. data/spec/fixtures/animals_exhibits.yaml +0 -2
  112. data/spec/fixtures/careers.yaml +0 -5
  113. data/spec/fixtures/comments.yaml +0 -1
  114. data/spec/fixtures/exhibits.yaml +0 -90
  115. data/spec/fixtures/fruit.yaml +0 -6
  116. data/spec/fixtures/people.yaml +0 -37
  117. data/spec/fixtures/posts.yaml +0 -3
  118. data/spec/fixtures/projects.yaml +0 -13
  119. data/spec/fixtures/sections.yaml +0 -5
  120. data/spec/fixtures/serializers.yaml +0 -6
  121. data/spec/fixtures/tasks.yaml +0 -6
  122. data/spec/fixtures/tasks_tasks.yaml +0 -2
  123. data/spec/fixtures/tomatoes.yaml +0 -1
  124. data/spec/fixtures/users.yaml +0 -1
  125. data/spec/fixtures/zoos.yaml +0 -24
  126. data/spec/is_a_tree_spec.rb +0 -149
  127. data/spec/legacy_spec.rb +0 -16
  128. data/spec/load_command_spec.rb +0 -322
  129. data/spec/magic_columns_spec.rb +0 -26
  130. data/spec/migration_spec.rb +0 -267
  131. data/spec/mock_adapter.rb +0 -20
  132. data/spec/models/animal.rb +0 -12
  133. data/spec/models/candidate.rb +0 -8
  134. data/spec/models/career.rb +0 -7
  135. data/spec/models/chain.rb +0 -8
  136. data/spec/models/comment.rb +0 -6
  137. data/spec/models/exhibit.rb +0 -14
  138. data/spec/models/fence.rb +0 -7
  139. data/spec/models/fruit.rb +0 -8
  140. data/spec/models/job.rb +0 -8
  141. data/spec/models/person.rb +0 -30
  142. data/spec/models/post.rb +0 -14
  143. data/spec/models/project.rb +0 -41
  144. data/spec/models/sales_person.rb +0 -5
  145. data/spec/models/section.rb +0 -8
  146. data/spec/models/serializer.rb +0 -5
  147. data/spec/models/task.rb +0 -9
  148. data/spec/models/tomato.rb +0 -27
  149. data/spec/models/user.rb +0 -12
  150. data/spec/models/zoo.rb +0 -13
  151. data/spec/natural_key_spec.rb +0 -36
  152. data/spec/paranoia_spec.rb +0 -38
  153. data/spec/persistence_spec.rb +0 -479
  154. data/spec/postgres_spec.rb +0 -96
  155. data/spec/property_spec.rb +0 -151
  156. data/spec/query_spec.rb +0 -77
  157. data/spec/save_command_spec.rb +0 -94
  158. data/spec/schema_spec.rb +0 -8
  159. data/spec/serialize_spec.rb +0 -19
  160. data/spec/single_table_inheritance_spec.rb +0 -43
  161. data/spec/spec_helper.rb +0 -45
  162. data/spec/support/blank_spec.rb +0 -8
  163. data/spec/support/inflector_spec.rb +0 -41
  164. data/spec/support/object_spec.rb +0 -9
  165. data/spec/support/serialization_spec.rb +0 -61
  166. data/spec/support/silence_spec.rb +0 -15
  167. data/spec/support/string_spec.rb +0 -7
  168. data/spec/support/struct_spec.rb +0 -12
  169. data/spec/support/typed_set_spec.rb +0 -66
  170. data/spec/symbolic_operators_spec.rb +0 -27
  171. data/spec/table_spec.rb +0 -79
  172. data/spec/types/string.rb +0 -81
  173. data/spec/validates_confirmation_of_spec.rb +0 -55
  174. data/spec/validates_format_of_spec.rb +0 -78
  175. data/spec/validates_length_of_spec.rb +0 -117
  176. data/spec/validates_uniqueness_of_spec.rb +0 -92
  177. data/spec/validations/number_validator.rb +0 -59
  178. data/spec/validations/string_validator.rb +0 -14
  179. data/spec/validations_spec.rb +0 -141
  180. data/tasks/fixtures.rb +0 -53
@@ -1,54 +0,0 @@
1
- module DataMapper
2
- module Support
3
- module Object
4
-
5
- def self.included(base)
6
-
7
- nested_constants = Hash.new do |h,k|
8
- klass = Object
9
- k.split('::').each do |c|
10
- klass = klass.const_get(c)
11
- end
12
- h[k] = klass
13
- end
14
-
15
- base.instance_variable_set("@nested_constants", nested_constants)
16
- base.send(:include, ClassMethods)
17
- end
18
-
19
- module ClassMethods
20
- def recursive_const_get(nested_name)
21
- @nested_constants[nested_name]
22
- end
23
- end
24
- end
25
- end
26
- end
27
-
28
- class Object #:nodoc:
29
- include DataMapper::Support::Object
30
- end
31
-
32
- # require 'benchmark'
33
- #
34
- # N = 1_000_000
35
- #
36
- # puts Benchmark.measure {
37
- # N.times { Object.recursive_const_get('DataMapper::Support::Object') }
38
- # }
39
- #
40
- # puts Benchmark.measure {
41
- # N.times {
42
- # klass = Object
43
- # 'DataMapper::Support::Object'.split('::').each do |c|
44
- # klass = klass.const_get(c)
45
- # end
46
- # klass
47
- # }
48
- # }
49
- #
50
- # __END__
51
- # >>> object.rb
52
- #
53
- # 0.910000 0.000000 0.910000 ( 0.916914)
54
- # 6.140000 0.010000 6.150000 ( 6.151984)
@@ -1,96 +0,0 @@
1
- require 'rexml/document'
2
-
3
- begin
4
- require 'faster_csv'
5
- rescue LoadError
6
- nil
7
- end
8
-
9
- begin
10
- require 'json/ext'
11
- rescue LoadError
12
- require 'json/pure'
13
- end
14
-
15
- module DataMapper
16
- module Support
17
- module Serialization
18
-
19
- def to_yaml(opts = {})
20
-
21
- YAML::quick_emit( object_id, opts ) do |out|
22
- out.map(nil, to_yaml_style ) do |map|
23
- database_context.table(self).columns.each do |column|
24
- lazy_load!(column.name) if column.lazy?
25
- value = get_value_for_column(column)
26
- map.add(column.to_s, value.is_a?(Class) ? value.to_s : value)
27
- end
28
- (self.instance_variable_get("@yaml_added") || []).each do |k,v|
29
- map.add(k.to_s, v)
30
- end
31
- end
32
- end
33
-
34
- end
35
-
36
- def to_xml
37
- to_xml_document.to_s
38
- end
39
-
40
- def xml_element_name ## overloadable
41
- Inflector.underscore(self.class.name)
42
- end
43
-
44
- def to_xml_document
45
- doc = REXML::Document.new
46
-
47
- table = database_context.table(self.class)
48
- # root = doc.add_element(Inflector.underscore(self.class.name))
49
- root = doc.add_element(xml_element_name)
50
-
51
- key_attribute = root.attributes << REXML::Attribute.new(table.key.to_s, key)
52
-
53
- # Single-quoted attributes are ugly. :p
54
- # NOTE: I don't want to break existing REXML specs for everyone, so I'm
55
- # overwriting REXML::Attribute#to_string just for this instance.
56
- def key_attribute.to_string
57
- %Q[#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"]
58
- end
59
-
60
- table.columns.each do |column|
61
- next if column.key?
62
- value = get_value_for_column(column)
63
- node = root.add_element(column.to_s)
64
- node << REXML::Text.new(value.to_s) unless value.nil?
65
- end
66
-
67
- doc
68
- end
69
-
70
- def to_json(*a)
71
- table = database_context.table(self.class)
72
-
73
- result = '{ '
74
-
75
- result << table.columns.map do |column|
76
- "#{column.name.to_json}: #{get_value_for_column(column).to_json(*a)}"
77
- end.join(', ')
78
-
79
- result << ' }'
80
- result
81
- end
82
-
83
- def to_csv(writer = "")
84
- FasterCSV.generate(writer) do |csv|
85
- csv << database_context.table(self.class).columns.map { |column| get_value_for_column(column) }
86
- end
87
- return writer
88
- end
89
-
90
- def get_value_for_column(column)
91
- send(column.type == :boolean ? column.name.to_s.ensure_ends_with('?') : column.name)
92
- end
93
-
94
- end
95
- end # module Support
96
- end # module DataMapper
@@ -1,10 +0,0 @@
1
- module Kernel
2
- def silence_warnings
3
- old_verbose, $VERBOSE = $VERBOSE, nil
4
- begin
5
- yield
6
- ensure
7
- $VERBOSE = old_verbose
8
- end
9
- end
10
- end
@@ -1,72 +0,0 @@
1
- module DataMapper
2
- module Support
3
- module String
4
-
5
- # I set the constant on the String itself to avoid inheritance chain lookups.
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- end
9
-
10
- module ClassMethods
11
- # Overwrite this method to provide your own translations.
12
- def translate(value)
13
- translations[value] || value
14
- end
15
-
16
- def translations
17
- @translations || @translations = {}
18
- end
19
- end
20
-
21
- def ensure_starts_with(part)
22
- [0,1] == part ? self : (part + self)
23
- end
24
-
25
- def ensure_ends_with(part)
26
- [-1,1] == part ? self : (self + part)
27
- end
28
-
29
- def ensure_wrapped_with(a, b = nil)
30
- ensure_starts_with(a).ensure_ends_with(b || a)
31
- end
32
-
33
- # Matches any whitespace (including newline) and replaces with a single space
34
- # EXAMPLE:
35
- # <<QUERY.compress_lines
36
- # SELECT name
37
- # FROM users
38
- # QUERY
39
- # => "SELECT name FROM users"
40
- def compress_lines(spaced = true)
41
- split($/).map { |line| line.strip }.join(spaced ? ' ' : '')
42
- end
43
-
44
- # Useful for heredocs - removes whitespace margin.
45
- def margin(indicator = nil)
46
- lines = self.dup.split($/)
47
-
48
- min_margin = 0
49
- lines.each do |line|
50
- if line =~ /^(\s+)/ && (min_margin == 0 || $1.size < min_margin)
51
- min_margin = $1.size
52
- end
53
- end
54
- lines.map { |line| line.sub(/^\s{#{min_margin}}/, '') }.join($/)
55
- end
56
-
57
- # Formats String for easy translation. Replaces an arbitrary number of
58
- # values using numeric identifier replacement.
59
- #
60
- # "%s %s %s" % %w(one two three) #=> "one two three"
61
- # "%3$s %2$s %1$s" % %w(one two three) #=> "three two one"
62
- def t(*values)
63
- self.class::translate(self) % values
64
- end
65
-
66
- end # module String
67
- end # module Support
68
- end # module DataMapper
69
-
70
- class String #:nodoc:
71
- include DataMapper::Support::String
72
- end
@@ -1,7 +0,0 @@
1
- class Struct
2
- def attributes
3
- h = {}
4
- each_pair { |k,v| h[k] = v }
5
- h
6
- end
7
- end
@@ -1,82 +0,0 @@
1
- module DataMapper
2
- module Support
3
-
4
- # Extends
5
- module Symbol
6
-
7
- class Operator
8
-
9
- attr_reader :value, :type, :options
10
-
11
- def initialize(value, type, options = nil)
12
- @value, @type, @options = value, type, options
13
- end
14
-
15
- def to_sym
16
- @value
17
- end
18
- end
19
-
20
- def gt
21
- Operator.new(self, :gt)
22
- end
23
-
24
- def gte
25
- Operator.new(self, :gte)
26
- end
27
-
28
- def lt
29
- Operator.new(self, :lt)
30
- end
31
-
32
- def lte
33
- Operator.new(self, :lte)
34
- end
35
-
36
- def not
37
- Operator.new(self, :not)
38
- end
39
-
40
- def eql
41
- Operator.new(self, :eql)
42
- end
43
-
44
- def like
45
- Operator.new(self, :like)
46
- end
47
-
48
- def in
49
- Operator.new(self, :in)
50
- end
51
-
52
- def to_proc
53
- lambda { |value| value.send(self) }
54
- end
55
-
56
- # Calculations:
57
-
58
- def count
59
- Operator.new(self, :count)
60
- end
61
-
62
- def max
63
- Operator.new(self, :max)
64
- end
65
-
66
- def avg
67
- Operator.new(self, :avg)
68
- end
69
-
70
- alias average avg
71
-
72
- def min
73
- Operator.new(self, :min)
74
- end
75
-
76
- end # module Symbol
77
- end # module Support
78
- end # module DataMapper
79
-
80
- class Symbol #:nodoc:
81
- include DataMapper::Support::Symbol
82
- end
@@ -1,65 +0,0 @@
1
- require 'set'
2
-
3
- module DataMapper
4
- module Support
5
- class TypedSet
6
-
7
- include ::Enumerable
8
-
9
- def initialize(*types)
10
- @types = types
11
- @set = SortedSet.new
12
- end
13
-
14
- def <<(item)
15
- raise ArgumentError.new("#{item.inspect} must be a kind of: #{@types.inspect}") unless @types.any? { |type| type === item }
16
- @set << item
17
- return self
18
- end
19
-
20
- def concat(values)
21
- [*values].each { |item| self << item }
22
- self
23
- end
24
-
25
- def inspect
26
- "#<DataMapper::Support::TypedSet#{@types.inspect}: {#{entries.inspect[1...-1]}}>"
27
- end
28
-
29
- def each
30
- @set.each { |item| yield(item) }
31
- end
32
-
33
- def delete?(item)
34
- @set.delete?(item)
35
- end
36
-
37
- def size
38
- @set.size
39
- end
40
- alias length size
41
-
42
- def empty?
43
- @set.empty?
44
- end
45
- alias blank? empty?
46
-
47
- def clear
48
- @set.clear
49
- end
50
-
51
- def +(other)
52
- x = self.class.new(*@types)
53
- each { |entry| x << entry }
54
- other.each { |entry| x << entry } unless other.blank?
55
- return x
56
- end
57
- end
58
- end
59
- end
60
-
61
- class Class
62
- def <=>(other)
63
- name <=> other.name
64
- end
65
- end
@@ -1,44 +0,0 @@
1
- require 'data_mapper/validations/number_validator'
2
- require 'data_mapper/validations/string_validator'
3
-
4
- module DataMapper
5
- module Types
6
- TYPE_MAP = {}
7
-
8
- module Base
9
- module ClassMethods
10
- def context(ctx)
11
- contexts(ctx)
12
- end
13
-
14
- def contexts(*ctxs)
15
- @contexts || @contexts = %w{__all__} << ctxs.map { |c| c.to_s }
16
- end
17
- end
18
-
19
- def self.included(klass)
20
- klass.extend(ClassMethods)
21
- end
22
-
23
- def do_validations
24
- raise NotImplementedError.new
25
- end
26
-
27
- def valid?(context = "__all__")
28
- @errors = []
29
-
30
- if self.class.contexts.include?(context.to_s)
31
- do_validations
32
-
33
- @errors.empty?
34
- else
35
- true
36
- end
37
- end
38
-
39
- def errors
40
- @errors || @errors = []
41
- end
42
- end
43
- end
44
- end
@@ -1,34 +0,0 @@
1
- require 'data_mapper/types/base'
2
-
3
- module DataMapper
4
- module Types
5
- class String < ::String
6
- include Types::Base
7
-
8
- TYPE_MAP[:string] = self
9
- TYPE_MAP[::String] = self
10
-
11
- def self.length
12
- length_validator
13
- end
14
-
15
- def self.matches(regexp)
16
- match_validator.matches(regexp)
17
- end
18
-
19
- def self.length_validator
20
- @length_validator ||
21
- @length_validator = Validations::NumberValidator.new
22
- end
23
-
24
- def self.match_validator
25
- @match_validator || @match_validator = Validations::StringValidator.new
26
- end
27
-
28
- def do_validations
29
- errors.concat(self.class.length_validator.errors_for(length))
30
- errors.concat(self.class.match_validator.errors_for(self))
31
- end
32
- end
33
- end
34
- end