dm-core 1.1.0.rc2 → 1.1.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +1 -8
  2. data/VERSION +1 -1
  3. data/dm-core.gemspec +24 -15
  4. data/lib/dm-core.rb +9 -48
  5. data/lib/dm-core/adapters.rb +1 -1
  6. data/lib/dm-core/adapters/abstract_adapter.rb +2 -1
  7. data/lib/dm-core/associations/many_to_many.rb +3 -3
  8. data/lib/dm-core/associations/many_to_one.rb +15 -4
  9. data/lib/dm-core/associations/one_to_many.rb +1 -1
  10. data/lib/dm-core/associations/relationship.rb +7 -6
  11. data/lib/dm-core/collection.rb +7 -2
  12. data/lib/dm-core/core_ext/pathname.rb +0 -14
  13. data/lib/dm-core/ext/array.rb +41 -0
  14. data/lib/dm-core/ext/blank.rb +24 -0
  15. data/lib/dm-core/ext/hash.rb +67 -0
  16. data/lib/dm-core/ext/module.rb +49 -0
  17. data/lib/dm-core/ext/object.rb +57 -0
  18. data/lib/dm-core/ext/singleton_class.rb +8 -0
  19. data/lib/dm-core/ext/string.rb +24 -0
  20. data/lib/dm-core/ext/try_dup.rb +12 -0
  21. data/lib/dm-core/model.rb +2 -1
  22. data/lib/dm-core/model/property.rb +3 -2
  23. data/lib/dm-core/property.rb +1 -1
  24. data/lib/dm-core/property/class.rb +1 -1
  25. data/lib/dm-core/property/date.rb +3 -3
  26. data/lib/dm-core/property/date_time.rb +3 -3
  27. data/lib/dm-core/property/time.rb +3 -3
  28. data/lib/dm-core/property/typecast/time.rb +2 -2
  29. data/lib/dm-core/property_set.rb +1 -1
  30. data/lib/dm-core/query.rb +9 -12
  31. data/lib/dm-core/resource.rb +2 -2
  32. data/lib/dm-core/spec/lib/counter_adapter.rb +1 -1
  33. data/lib/dm-core/spec/lib/spec_helper.rb +1 -1
  34. data/lib/dm-core/spec/shared/resource_spec.rb +2 -1
  35. data/lib/dm-core/support/equalizer.rb +1 -1
  36. data/lib/dm-core/support/hook.rb +0 -15
  37. data/lib/dm-core/support/inflections.rb +60 -0
  38. data/lib/dm-core/support/inflector.rb +3 -0
  39. data/lib/dm-core/support/inflector/inflections.rb +211 -0
  40. data/lib/dm-core/support/inflector/methods.rb +151 -0
  41. data/lib/dm-core/support/lazy_array.rb +4 -4
  42. data/lib/dm-core/support/mash.rb +176 -0
  43. data/lib/dm-core/support/subject.rb +1 -1
  44. data/lib/dm-core/version.rb +1 -1
  45. data/spec/public/model/relationship_spec.rb +2 -1
  46. data/spec/public/shared/collection_shared_spec.rb +5 -2
  47. data/spec/public/shared/finder_shared_spec.rb +10 -6
  48. data/spec/semipublic/adapters/in_memory_adapter_spec.rb +1 -1
  49. data/spec/semipublic/query_spec.rb +2 -2
  50. data/spec/semipublic/resource/state/immutable_spec.rb +2 -1
  51. data/spec/semipublic/resource/state_spec.rb +1 -3
  52. data/spec/semipublic/shared/resource_state_shared_spec.rb +2 -1
  53. data/spec/semipublic/shared/subject_shared_spec.rb +1 -1
  54. data/spec/support/core_ext/hash.rb +10 -0
  55. data/spec/support/core_ext/inheritable_attributes.rb +46 -0
  56. data/spec/unit/array_spec.rb +8 -20
  57. data/spec/unit/blank_spec.rb +62 -0
  58. data/spec/unit/data_mapper/ordered_set/hash_spec.rb +1 -1
  59. data/spec/unit/hash_spec.rb +8 -16
  60. data/spec/unit/lazy_array_spec.rb +3 -14
  61. data/spec/unit/mash_spec.rb +312 -0
  62. data/spec/unit/module_spec.rb +15 -15
  63. data/spec/unit/object_spec.rb +9 -9
  64. data/spec/unit/try_dup_spec.rb +8 -8
  65. metadata +32 -39
  66. data/lib/dm-core/core_ext/array.rb +0 -36
  67. data/lib/dm-core/core_ext/hash.rb +0 -30
  68. data/lib/dm-core/core_ext/module.rb +0 -46
  69. data/lib/dm-core/core_ext/object.rb +0 -31
  70. data/lib/dm-core/core_ext/string.rb +0 -22
  71. data/lib/dm-core/core_ext/try_dup.rb +0 -44
data/Gemfile CHANGED
@@ -5,17 +5,10 @@ source 'http://rubygems.org'
5
5
  SOURCE = ENV.fetch('SOURCE', :git).to_sym
6
6
  REPO_POSTFIX = SOURCE == :path ? '' : '.git'
7
7
  DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
8
- DM_VERSION = '~> 1.1.0.rc2'
8
+ DM_VERSION = '~> 1.1.0.rc3'
9
9
  DO_VERSION = '~> 0.10.2'
10
10
  DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
11
11
 
12
- if ENV['EXTLIB']
13
- gem 'extlib', '~> 0.9.15', SOURCE => "#{DATAMAPPER}/extlib#{REPO_POSTFIX}", :require => nil
14
- else
15
- gem 'activesupport', '~> 3.0.4', :require => nil
16
- gem 'i18n', '~> 0.5.0'
17
- end
18
-
19
12
  gem 'addressable', '~> 2.2.4'
20
13
 
21
14
  group :development do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.rc2
1
+ 1.1.0.rc3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-core}
8
- s.version = "1.1.0.rc2"
8
+ s.version = "1.1.0.rc3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Kubb"]
12
- s.date = %q{2011-03-01}
12
+ s.date = %q{2011-03-10}
13
13
  s.description = %q{Faster, Better, Simpler.}
14
14
  s.email = %q{dan.kubb@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -35,15 +35,17 @@ Gem::Specification.new do |s|
35
35
  "lib/dm-core/associations/one_to_one.rb",
36
36
  "lib/dm-core/associations/relationship.rb",
37
37
  "lib/dm-core/collection.rb",
38
- "lib/dm-core/core_ext/array.rb",
39
- "lib/dm-core/core_ext/hash.rb",
40
38
  "lib/dm-core/core_ext/kernel.rb",
41
- "lib/dm-core/core_ext/module.rb",
42
- "lib/dm-core/core_ext/object.rb",
43
39
  "lib/dm-core/core_ext/pathname.rb",
44
- "lib/dm-core/core_ext/string.rb",
45
40
  "lib/dm-core/core_ext/symbol.rb",
46
- "lib/dm-core/core_ext/try_dup.rb",
41
+ "lib/dm-core/ext/array.rb",
42
+ "lib/dm-core/ext/blank.rb",
43
+ "lib/dm-core/ext/hash.rb",
44
+ "lib/dm-core/ext/module.rb",
45
+ "lib/dm-core/ext/object.rb",
46
+ "lib/dm-core/ext/singleton_class.rb",
47
+ "lib/dm-core/ext/string.rb",
48
+ "lib/dm-core/ext/try_dup.rb",
47
49
  "lib/dm-core/identity_map.rb",
48
50
  "lib/dm-core/model.rb",
49
51
  "lib/dm-core/model/hook.rb",
@@ -106,9 +108,14 @@ Gem::Specification.new do |s|
106
108
  "lib/dm-core/support/descendant_set.rb",
107
109
  "lib/dm-core/support/equalizer.rb",
108
110
  "lib/dm-core/support/hook.rb",
111
+ "lib/dm-core/support/inflections.rb",
112
+ "lib/dm-core/support/inflector.rb",
113
+ "lib/dm-core/support/inflector/inflections.rb",
114
+ "lib/dm-core/support/inflector/methods.rb",
109
115
  "lib/dm-core/support/lazy_array.rb",
110
116
  "lib/dm-core/support/local_object_space.rb",
111
117
  "lib/dm-core/support/logger.rb",
118
+ "lib/dm-core/support/mash.rb",
112
119
  "lib/dm-core/support/naming_conventions.rb",
113
120
  "lib/dm-core/support/ordered_set.rb",
114
121
  "lib/dm-core/support/subject.rb",
@@ -196,8 +203,11 @@ Gem::Specification.new do |s|
196
203
  "spec/semipublic/shared/subject_shared_spec.rb",
197
204
  "spec/spec.opts",
198
205
  "spec/spec_helper.rb",
206
+ "spec/support/core_ext/hash.rb",
207
+ "spec/support/core_ext/inheritable_attributes.rb",
199
208
  "spec/support/properties/huge_integer.rb",
200
209
  "spec/unit/array_spec.rb",
210
+ "spec/unit/blank_spec.rb",
201
211
  "spec/unit/data_mapper/ordered_set/append_spec.rb",
202
212
  "spec/unit/data_mapper/ordered_set/clear_spec.rb",
203
213
  "spec/unit/data_mapper/ordered_set/delete_spec.rb",
@@ -252,6 +262,7 @@ Gem::Specification.new do |s|
252
262
  "spec/unit/hash_spec.rb",
253
263
  "spec/unit/hook_spec.rb",
254
264
  "spec/unit/lazy_array_spec.rb",
265
+ "spec/unit/mash_spec.rb",
255
266
  "spec/unit/module_spec.rb",
256
267
  "spec/unit/object_spec.rb",
257
268
  "spec/unit/try_dup_spec.rb",
@@ -263,7 +274,7 @@ Gem::Specification.new do |s|
263
274
  s.homepage = %q{http://github.com/datamapper/dm-core}
264
275
  s.require_paths = ["lib"]
265
276
  s.rubyforge_project = %q{datamapper}
266
- s.rubygems_version = %q{1.5.2}
277
+ s.rubygems_version = %q{1.6.2}
267
278
  s.summary = %q{An Object/Relational Mapper for Ruby}
268
279
  s.test_files = [
269
280
  "spec/lib/rspec_immediate_feedback_formatter.rb",
@@ -344,8 +355,11 @@ Gem::Specification.new do |s|
344
355
  "spec/semipublic/shared/resource_state_shared_spec.rb",
345
356
  "spec/semipublic/shared/subject_shared_spec.rb",
346
357
  "spec/spec_helper.rb",
358
+ "spec/support/core_ext/hash.rb",
359
+ "spec/support/core_ext/inheritable_attributes.rb",
347
360
  "spec/support/properties/huge_integer.rb",
348
361
  "spec/unit/array_spec.rb",
362
+ "spec/unit/blank_spec.rb",
349
363
  "spec/unit/data_mapper/ordered_set/append_spec.rb",
350
364
  "spec/unit/data_mapper/ordered_set/clear_spec.rb",
351
365
  "spec/unit/data_mapper/ordered_set/delete_spec.rb",
@@ -400,6 +414,7 @@ Gem::Specification.new do |s|
400
414
  "spec/unit/hash_spec.rb",
401
415
  "spec/unit/hook_spec.rb",
402
416
  "spec/unit/lazy_array_spec.rb",
417
+ "spec/unit/mash_spec.rb",
403
418
  "spec/unit/module_spec.rb",
404
419
  "spec/unit/object_spec.rb",
405
420
  "spec/unit/try_dup_spec.rb"
@@ -409,23 +424,17 @@ Gem::Specification.new do |s|
409
424
  s.specification_version = 3
410
425
 
411
426
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
412
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
413
- s.add_runtime_dependency(%q<i18n>, ["~> 0.5.0"])
414
427
  s.add_runtime_dependency(%q<addressable>, ["~> 2.2.4"])
415
428
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
416
429
  s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
417
430
  s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
418
431
  else
419
- s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
420
- s.add_dependency(%q<i18n>, ["~> 0.5.0"])
421
432
  s.add_dependency(%q<addressable>, ["~> 2.2.4"])
422
433
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
423
434
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
424
435
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
425
436
  end
426
437
  else
427
- s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
428
- s.add_dependency(%q<i18n>, ["~> 0.5.0"])
429
438
  s.add_dependency(%q<addressable>, ["~> 2.2.4"])
430
439
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
431
440
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
@@ -11,53 +11,12 @@ module DataMapper
11
11
  module Undefined; end
12
12
  end
13
13
 
14
- begin
15
-
16
- # Prefer active_support
17
-
18
- require 'active_support/core_ext/kernel/singleton_class'
19
- require 'active_support/core_ext/class/inheritable_attributes'
20
- require 'active_support/core_ext/object/blank'
21
- require 'active_support/core_ext/hash/except'
22
-
23
- require 'active_support/hash_with_indifferent_access'
24
- require 'active_support/inflector'
25
-
26
- Mash = ActiveSupport::HashWithIndifferentAccess
27
-
28
- require 'dm-core/core_ext/hash'
29
- require 'dm-core/core_ext/object'
30
- require 'dm-core/core_ext/string'
31
-
32
- module DataMapper
33
- Inflector = ActiveSupport::Inflector
34
- end
35
-
36
- rescue LoadError
14
+ require 'dm-core/ext/singleton_class'
15
+ require 'dm-core/ext/blank'
37
16
 
38
- # Default to extlib
39
-
40
- require 'extlib/inflection'
41
- require 'extlib/mash'
42
- require 'extlib/string'
43
- require 'extlib/class'
44
- require 'extlib/hash'
45
- require 'extlib/object'
46
- require 'extlib/blank'
47
-
48
- class Object
49
- unless respond_to?(:singleton_class)
50
- def singleton_class
51
- class << self; self end
52
- end
53
- end
54
- end
55
-
56
- module DataMapper
57
- Inflector = Extlib::Inflection
58
- end
59
-
60
- end
17
+ require 'dm-core/ext/hash'
18
+ require 'dm-core/ext/object'
19
+ require 'dm-core/ext/string'
61
20
 
62
21
  begin
63
22
  require 'fastthread'
@@ -66,9 +25,11 @@ rescue LoadError
66
25
  end
67
26
 
68
27
  require 'dm-core/core_ext/pathname'
69
- require 'dm-core/core_ext/module'
70
- require 'dm-core/core_ext/array'
28
+ require 'dm-core/ext/module'
29
+ require 'dm-core/ext/array'
71
30
 
31
+ require 'dm-core/support/mash'
32
+ require 'dm-core/support/inflector'
72
33
  require 'dm-core/support/chainable'
73
34
  require 'dm-core/support/deprecate'
74
35
  require 'dm-core/support/descendant_set'
@@ -76,7 +76,7 @@ module DataMapper
76
76
  #
77
77
  # @api private
78
78
  def normalize_options_hash(hash)
79
- hash.to_mash
79
+ DataMapper::Ext::Hash.to_mash(hash)
80
80
  end
81
81
 
82
82
  # Normalize Addressable::URI options into a Mash
@@ -208,7 +208,8 @@ module DataMapper
208
208
  #
209
209
  # @api semipublic
210
210
  def attributes_as_fields(attributes)
211
- attributes.map { |property, value| [ property.field, property.dump(value) ] }.to_hash
211
+ pairs = attributes.map { |property, value| [ property.field, property.dump(value) ] }
212
+ DataMapper::Ext::Array.to_hash(pairs)
212
213
  end
213
214
 
214
215
  private
@@ -87,7 +87,7 @@ module DataMapper
87
87
  repository_name = through.relative_target_repository_name
88
88
  through_model = through.target_model
89
89
  relationships = through_model.relationships(repository_name)
90
- singular_name = name.to_s.singularize.to_sym
90
+ singular_name = DataMapper::Inflector.singularize(name.to_s).to_sym
91
91
 
92
92
  @via = relationships[@via] ||
93
93
  relationships[name] ||
@@ -195,7 +195,7 @@ module DataMapper
195
195
  if anonymous_through_model?
196
196
  namespace = through_model_namespace_name.first
197
197
  relationship_name = DataMapper::Inflector.underscore(through_model.name.sub(/\A#{namespace.name}::/, '')).tr('/', '_')
198
- relationship_name.pluralize.to_sym
198
+ DataMapper::Inflector.pluralize(relationship_name).to_sym
199
199
  else
200
200
  options[:through]
201
201
  end
@@ -292,7 +292,7 @@ module DataMapper
292
292
 
293
293
  options = self.options
294
294
 
295
- options.only(*OPTIONS - [ :min, :max ]).update(
295
+ DataMapper::Ext::Hash.only(options, *OPTIONS - [ :min, :max ]).update(
296
296
  :through => through,
297
297
  :child_key => options[:parent_key],
298
298
  :parent_key => options[:child_key],
@@ -118,8 +118,13 @@ module DataMapper
118
118
  # @api semipublic
119
119
  def get(source, query = nil)
120
120
  lazy_load(source)
121
- collection = get_collection(source)
122
- collection.first(query) if collection
121
+
122
+ if query
123
+ collection = get_collection(source)
124
+ collection.first(query) if collection
125
+ else
126
+ get!(source)
127
+ end
123
128
  end
124
129
 
125
130
  def get_collection(source)
@@ -229,12 +234,18 @@ module DataMapper
229
234
  #
230
235
  # @api private
231
236
  def inverse_name
232
- super || DataMapper::Inflector.underscore(DataMapper::Inflector.demodulize(source_model.name)).pluralize.to_sym
237
+ name = super
238
+ return name if name
239
+
240
+ name = DataMapper::Inflector.demodulize(source_model.name)
241
+ name = DataMapper::Inflector.underscore(name)
242
+ name = DataMapper::Inflector.pluralize(name)
243
+ name.to_sym
233
244
  end
234
245
 
235
246
  # @api private
236
247
  def source_key_options(target_property)
237
- options = target_property.options.only(:length, :precision, :scale).update(
248
+ options = DataMapper::Ext::Hash.only(target_property.options, :length, :precision, :scale).update(
238
249
  :index => name,
239
250
  :required => required?,
240
251
  :key => key?
@@ -109,7 +109,7 @@ module DataMapper
109
109
 
110
110
  # @api semipublic
111
111
  def initialize(name, target_model, source_model, options = {})
112
- target_model ||= DataMapper::Inflector.camelize(name.to_s.singularize)
112
+ target_model ||= DataMapper::Inflector.camelize(DataMapper::Inflector.singularize(name.to_s))
113
113
  options = { :min => 0, :max => source_model.n }.update(options)
114
114
  super
115
115
  end
@@ -168,7 +168,7 @@ module DataMapper
168
168
  def child_model
169
169
  return @child_model if defined?(@child_model)
170
170
  child_model_name = self.child_model_name
171
- @child_model = (@parent_model || Object).find_const(child_model_name)
171
+ @child_model = DataMapper::Ext::Module.find_const(@parent_model || Object, child_model_name)
172
172
  rescue NameError
173
173
  raise NameError, "Cannot find the child_model #{child_model_name} for #{parent_model_name} in #{name}"
174
174
  end
@@ -221,7 +221,7 @@ module DataMapper
221
221
  def parent_model
222
222
  return @parent_model if defined?(@parent_model)
223
223
  parent_model_name = self.parent_model_name
224
- @parent_model = (@child_model || Object).find_const(parent_model_name)
224
+ @parent_model = DataMapper::Ext::Module.find_const(@child_model || Object, parent_model_name)
225
225
  rescue NameError
226
226
  raise NameError, "Cannot find the parent_model #{parent_model_name} for #{child_model_name} in #{name}"
227
227
  end
@@ -414,6 +414,7 @@ module DataMapper
414
414
 
415
415
  # @api private
416
416
  def hash
417
+ self.class.hash ^
417
418
  name.hash ^
418
419
  child_repository_name.hash ^
419
420
  parent_repository_name.hash ^
@@ -451,8 +452,8 @@ module DataMapper
451
452
  @options = options.dup.freeze
452
453
  @child_repository_name = @options[:child_repository_name]
453
454
  @parent_repository_name = @options[:parent_repository_name]
454
- @child_properties = @options[:child_key].try_dup.freeze
455
- @parent_properties = @options[:parent_key].try_dup.freeze
455
+ @child_properties = DataMapper::Ext.try_dup(@options[:child_key]).freeze
456
+ @parent_properties = DataMapper::Ext.try_dup(@options[:parent_key]).freeze
456
457
  @min = @options[:min]
457
458
  @max = @options[:max]
458
459
  @reader_visibility = @options.fetch(:reader_visibility, :public)
@@ -470,7 +471,7 @@ module DataMapper
470
471
  # query as :condition => and_object from self.query
471
472
  # - this should provide the best performance
472
473
 
473
- @query = @options.except(*self.class::OPTIONS).freeze
474
+ @query = DataMapper::Ext::Hash.except(@options, *self.class::OPTIONS).freeze
474
475
  end
475
476
 
476
477
  # Set the correct ivars for the named object
@@ -586,7 +587,7 @@ module DataMapper
586
587
 
587
588
  # @api private
588
589
  def inverted_options
589
- options.only(*OPTIONS - [ :min, :max ]).update(:inverse => self)
590
+ DataMapper::Ext::Hash.only(options, *OPTIONS - [ :min, :max ]).update(:inverse => self)
590
591
  end
591
592
 
592
593
  # @api private
@@ -730,6 +730,11 @@ module DataMapper
730
730
  super
731
731
  end
732
732
 
733
+ # Determines whether the collection is empty.
734
+ #
735
+ # @api public
736
+ alias_method :blank?, :empty?
737
+
733
738
  # Finds the first Resource by conditions, or initializes a new
734
739
  # Resource with the attributes if none found
735
740
  #
@@ -973,7 +978,7 @@ module DataMapper
973
978
 
974
979
  # @api semipublic
975
980
  def hash
976
- query.hash
981
+ self.class.hash ^ query.hash
977
982
  end
978
983
 
979
984
  protected
@@ -1437,7 +1442,7 @@ module DataMapper
1437
1442
 
1438
1443
  if model.respond_to?(method)
1439
1444
  delegate_to_model(method, *args, &block)
1440
- elsif relationship = relationships[method] || relationships[method.to_s.singularize.to_sym]
1445
+ elsif relationship = relationships[method] || relationships[DataMapper::Inflector.singularize(method.to_s).to_sym]
1441
1446
  delegate_to_relationship(relationship, *args)
1442
1447
  else
1443
1448
  super
@@ -1,18 +1,4 @@
1
1
  class Pathname
2
- # Append path segments and expand to absolute path
3
- #
4
- # file = Pathname(Dir.pwd) / "subdir1" / :subdir2 / "filename.ext"
5
- #
6
- # @param [Pathname, String, #to_s] path path segment to concatenate with receiver
7
- #
8
- # @return [Pathname]
9
- # receiver with _path_ appended and expanded to an absolute path
10
- #
11
- # @api public
12
- def /(path)
13
- (self + path).expand_path
14
- end
15
-
16
2
  # alias_method :to_s, :to to_str when to_str not defined
17
3
  unless public_instance_methods(false).any? { |m| m.to_sym == :to_str }
18
4
  alias_method :to_str, :to_s
@@ -0,0 +1,41 @@
1
+ module DataMapper; module Ext
2
+ module Array
3
+ # Transforms an Array of key/value pairs into a Hash.
4
+ #
5
+ # This is a better idiom than using Hash[*array.flatten] in Ruby 1.8.6
6
+ # because it is not possible to limit the flattening to a single
7
+ # level.
8
+ #
9
+ # @param [Array] array
10
+ # The array of key/value pairs to transform.
11
+ #
12
+ # @return [Hash]
13
+ # A Hash where each entry in the Array is turned into a key/value.
14
+ #
15
+ # @api semipublic
16
+ def self.to_hash(array)
17
+ h = {}
18
+ array.each { |k,v| h[k] = v }
19
+ h
20
+ end
21
+
22
+ # Transforms an Array of key/value pairs into a {Mash}.
23
+ #
24
+ # This is a better idiom than using Mash[*array.flatten] in Ruby 1.8.6
25
+ # because it is not possible to limit the flattening to a single
26
+ # level.
27
+ #
28
+ # @param [Array] array
29
+ # The array of key/value pairs to transform.
30
+ #
31
+ # @return [Mash]
32
+ # A {Mash} where each entry in the Array is turned into a key/value.
33
+ #
34
+ # @api semipublic
35
+ def self.to_mash(array)
36
+ m = Mash.new
37
+ array.each { |k,v| m[k] = v }
38
+ m
39
+ end
40
+ end # class Array
41
+ end; end