rails_dm_datastore 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,9 +9,9 @@ begin
9
9
  gem.name = "rails_dm_datastore"
10
10
  gem.summary = %Q{Generators for dm on gae}
11
11
  gem.description = %Q{Integrate datamapper to Rails for the Google App Engine}
12
- gem.email = "joshsmoore@gmail.com"
12
+ gem.email = ["joshsmoore@gmail.com", "woodie@netpress.com"]
13
13
  gem.homepage = "http://github.com/joshsmoore/dm-rails-gae"
14
- gem.authors = ["joshsmoore"]
14
+ gem.authors = ["Josh S Moore", "John Woodell"]
15
15
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
16
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
17
  gem.add_dependency 'dm-core', DM_VERSION
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -1,25 +1,24 @@
1
- <% max = 2
2
- presets = {'Text' => ':lazy => false', 'String' => ':length => 500'}
3
- reserved_dm_names = DataMapper::Resource.instance_methods +
4
- DataMapper::Resource.private_instance_methods
5
- datastore_types = %w(AncestorKey BigDecimal Blob Boolean ByteString
6
- Category Class Date DateTime Email Float Integer Key Link Object
7
- PhoneNumber PostalAddres Rating String Text Time TrueClass) -%>
8
- <% Array(attributes).each do |attribute|
9
- if reserved_dm_names.include? attribute.name
10
- raise "reserved property name '#{attribute.name}'"
11
- elsif !datastore_types.include? attribute.type.to_s.classify
12
- raise "unknown property type '#{attribute.type}'"
13
- end
14
- max = attribute.name.size if attribute.name.size > max -%>
15
- <% end -%>
16
1
  class <%= class_name %>
2
+ <% max = 2
3
+ presets = {'Text' => ':lazy => false', 'String' => ':length => 500'}
4
+ reserved_dm_names = DataMapper::Resource.instance_methods +
5
+ DataMapper::Resource.private_instance_methods
6
+ datastore_types = (DataMapper::Property::PRIMITIVES +
7
+ DataMapper::Types.constants.map{|c| DataMapper::Types.const_get(c)}.
8
+ select{|t| t.respond_to? :primitive}).map {|c| c.to_s.split('::')[-1]}
9
+ Array(attributes).each do |attribute|
10
+ if reserved_dm_names.include? attribute.name
11
+ raise "reserved property name '#{attribute.name}'"
12
+ elsif !datastore_types.include? attribute.type.to_s.camelcase
13
+ raise "unknown property type '#{attribute.type}'"
14
+ end
15
+ max = attribute.name.size if attribute.name.size > max -%>
16
+ end -%>
17
17
  include DataMapper::Resource
18
18
 
19
19
  property :id,<%= " " * (max - 2) %> Serial
20
20
  <% Array(attributes).each do |attribute|
21
- klass = attribute.type.to_s.classify.to_s
22
- klass += 's' if klass.eql? 'PostalAddres' # classify bug
21
+ klass = attribute.type.to_s.camelcase
23
22
  more = presets.has_key?(klass) ? ", #{presets[klass]}" : ''
24
23
  pad = max - attribute.name.size
25
24
  rad = 13 - klass.size
@@ -4,160 +4,14 @@ require 'dm-ar-finders'
4
4
  require 'dm-timestamps'
5
5
  require 'dm-validations'
6
6
  DataMapper.setup(:default, "appengine://auto")
7
- #DataMapper.setup(:ephemeral, "in_memory::")
8
7
 
9
- #convert the date from the date picker to an actual date class that the datastore can actually store
10
- def fix_date(hash, property, type)
11
- total_attributes = 0
12
- if Date == type
13
- total_attributes = 3
14
- else
15
- total_attributes = 5
16
- end
17
-
18
- time_string = ""
19
- 1.upto(total_attributes) do |n|
20
- if n == 1
21
- time_string << hash[:"#{property}(#{n}i)"]
22
- elsif n > 1 && n <= 3
23
- time_string << '-' + hash[:"#{property}(#{n}i)"]
24
- elsif n == 4
25
- time_string << ' ' + hash[:"#{property}(#{n}i)"]
26
- elsif n > 4
27
- time_string << ':' + hash[:"#{property}(#{n}i)"]
28
- end
29
- hash.delete :"#{property}(#{n}i)"
30
- end
31
-
32
- hash[property] = type.parse(time_string).send("to_#{type.to_s.downcase}")
33
- hash
34
- end
35
-
36
- module DataMapper
37
- module Resource
38
- alias :attributes_orig= :attributes=
39
- # avoid object references in URLs
40
- def to_param; id.to_s; end
41
- # silence deprecation warnings
42
- def new_record?; new?; end
43
- # avoid NoMethodError
44
- def update_attributes(*args); update(*args); end
45
-
46
- #make sure that all properties of the model that have to do with date or time are converted run through
47
- # the fix_date converter
48
- def attributes=(attributes)
49
- self.class.properties.each do |t|
50
- if !(t.name.to_s =~ /.*_at/) && (t.type.to_s =~ /Date/ || t.type.to_s =~ /Time/ ) &&
51
- attributes.include?("#{t.name.to_s}(1i)")
52
- fix_date(attributes, t.name.to_s, t.type)
53
- end
54
- end
55
- self.attributes_orig=(attributes)
56
- end
57
- end
58
- end
8
+ require 'rails_dm_datastore/multiparameter_assignments'
9
+ require 'rails_dm_datastore/data_mapper'
10
+ require 'rails_dm_datastore/local_object_space'
11
+ require 'rails_dm_datastore/extlib'
12
+ require 'rails_dm_datastore/action_view'
13
+ require 'rails_dm_datastore/active_support'
59
14
 
60
15
  # DataMapper::Validate
61
16
  class Dictionary; alias count length; end
62
-
63
-
64
- #Override Extlib::Hook::ClassMethods.inline_call to check in the given weak reference
65
-
66
- module LocalObjectSpace
67
- def self.extended(klass)
68
- (class << klass; self;end).send :attr_accessor, :hook_scopes
69
-
70
- klass.hook_scopes = []
71
- end
72
-
73
- def object_by_id(object_id)
74
- self.hook_scopes.each do |object|
75
- return object if object.object_id == object_id
76
- end
77
- end
78
-
79
- end
80
-
81
- module Extlib
82
- module Hook
83
- module ClassMethods
84
-
85
- extend LocalObjectSpace
86
-
87
- #end
88
-
89
- def inline_call(method_info, scope)
90
- Extlib::Hook::ClassMethods.hook_scopes << method_info[:from]
91
- name = method_info[:name]
92
-
93
- if scope == :instance
94
- args = method_defined?(name) && instance_method(name).arity != 0 ? '*args' : ''
95
- %(#{name}(#{args}) if self.class <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
96
- else
97
- args = respond_to?(name) && method(name).arity != 0 ? '*args' : ''
98
- %(#{name}(#{args}) if self <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
99
- end
100
- end
101
- end
102
- end
103
- end
104
-
105
- # makes the shorthand <%= render @posts %> work for collections of DataMapper objects
106
- module ActionView
107
- module Partials
108
- alias :render_partial_orig :render_partial
109
- private
110
-
111
- def render_partial(options = {})
112
- if DataMapper::Collection === options[:partial]
113
- collection = options[:partial]
114
- options[:partial] = options[:partial].first.class.to_s.tableize.singular
115
- render_partial_collection(options.merge(:collection => collection))
116
- else
117
- render_partial_orig(options)
118
- end
119
- end
120
-
121
- end
122
- end
123
-
124
-
125
- # provided by John Woodell mando.woodie@gmail.com to fix problems with date conversion
126
- module ActiveSupport #:nodoc:
127
- module CoreExtensions #:nodoc:
128
- module String #:nodoc:
129
- # Converting strings to other objects
130
- module Conversions
131
- # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
132
- def ord
133
- self[0]
134
- end if RUBY_VERSION < '1.9'
135
-
136
- # Form can be either :utc (default) or :local.
137
- def to_time(form = :utc)
138
- begin
139
- ::Time.send("#{form}_time", *::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 })
140
- rescue
141
- nil
142
- end
143
- end
144
-
145
- def to_date
146
- begin
147
- ::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday))
148
- rescue
149
- nil
150
- end
151
- end
152
17
 
153
- def to_datetime
154
- begin
155
- ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 })
156
- rescue
157
- nil
158
- end
159
- end
160
- end
161
- end
162
- end
163
- end
@@ -0,0 +1,17 @@
1
+ # makes the shorthand <%= render @posts %> work
2
+ # for collections of DataMapper objects
3
+ module ActionView
4
+ module Partials
5
+ alias :render_partial_orig :render_partial
6
+ private
7
+ def render_partial(options = {})
8
+ if DataMapper::Collection === options[:partial]
9
+ collection = options[:partial]
10
+ options[:partial] = options[:partial].first.class.to_s.tableize.singular
11
+ render_partial_collection(options.merge(:collection => collection))
12
+ else
13
+ render_partial_orig(options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ # set a nil date or time when a date cannot be parced
2
+ # to avoid exception by ruby via to_date and to_time
3
+ module ActiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module String #:nodoc:
6
+ # Converting strings to other objects
7
+ module Conversions
8
+ # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
9
+ def ord
10
+ self[0]
11
+ end if RUBY_VERSION < '1.9'
12
+ # Form can be either :utc (default) or :local.
13
+ def to_time(form = :utc)
14
+ begin
15
+ ::Time.send("#{form}_time", *::Date._parse(self, false).
16
+ values_at(:year, :mon, :mday, :hour, :min, :sec).
17
+ map { |arg| arg || 0 })
18
+ rescue
19
+ nil
20
+ end
21
+ end
22
+ def to_date
23
+ begin
24
+ ::Date.new(*::Date._parse(self, false).
25
+ values_at(:year, :mon, :mday))
26
+ rescue
27
+ nil
28
+ end
29
+ end
30
+ def to_datetime
31
+ begin
32
+ ::DateTime.civil(*::Date._parse(self, false).
33
+ values_at(:year, :mon, :mday, :hour, :min, :sec).
34
+ map { |arg| arg || 0 })
35
+ rescue
36
+ nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ # Patch connections between DataMapper and Rails 2.3.5
2
+ module DataMapper
3
+ module Resource
4
+ alias :attributes_orig= :attributes=
5
+ # avoid object references in URLs
6
+ def to_param; id.to_s; end
7
+ # silence deprecation warnings
8
+ def new_record?; new?; end
9
+ # avoid NoMethodError
10
+ def update_attributes(*args); update(*args); end
11
+
12
+ # make sure that all properties of the model that have to do with
13
+ # date or time are converted run through the fix_date converter
14
+ def attributes=(attributes)
15
+ self.class.properties.each do |t|
16
+ if !(t.name.to_s =~ /.*_at/) && (t.type.to_s =~ /Date|Time/ ) &&
17
+ attributes.include?("#{t.name.to_s}(1i)")
18
+ MultiparameterAssignments.fix_date(attributes, t.name.to_s, t.type)
19
+ end
20
+ end
21
+ self.attributes_orig=(attributes)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # Fix LocalObjectSpace hooks
2
+ module Extlib
3
+ module Hook
4
+ module ClassMethods
5
+ extend LocalObjectSpace
6
+ def inline_call(method_info, scope)
7
+ Extlib::Hook::ClassMethods.hook_scopes << method_info[:from]
8
+ name = method_info[:name]
9
+ if scope == :instance
10
+ args = method_defined?(name) && instance_method(name).arity != 0 ? '*args' : ''
11
+ %(#{name}(#{args}) if self.class <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
12
+ else
13
+ args = respond_to?(name) && method(name).arity != 0 ? '*args' : ''
14
+ %(#{name}(#{args}) if self <= Extlib::Hook::ClassMethods.object_by_id(#{method_info[:from].object_id}))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ # Override Extlib::Hook::ClassMethods.inline_call
2
+ # to check in the given weak reference
3
+ module LocalObjectSpace
4
+ def self.extended(klass)
5
+ (class << klass; self;end).send :attr_accessor, :hook_scopes
6
+ klass.hook_scopes = []
7
+ end
8
+
9
+ def object_by_id(object_id)
10
+ self.hook_scopes.each do |object|
11
+ return object if object.object_id == object_id
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # Convert the values from the date and time picker
2
+ # to a date or time class that the datastore can accept
3
+ module MultiparameterAssignments
4
+ def self.fix_date(hash, property, type)
5
+ total_attributes = 0
6
+ if Date == type
7
+ total_attributes = 3
8
+ else
9
+ total_attributes = 5
10
+ end
11
+ time_string = ""
12
+ 1.upto(total_attributes) do |n|
13
+ if n == 1
14
+ time_string << hash[:"#{property}(#{n}i)"]
15
+ elsif n > 1 && n <= 3
16
+ time_string << '-' + hash[:"#{property}(#{n}i)"]
17
+ elsif n == 4
18
+ time_string << ' ' + hash[:"#{property}(#{n}i)"]
19
+ elsif n > 4
20
+ time_string << ':' + hash[:"#{property}(#{n}i)"]
21
+ end
22
+ hash.delete :"#{property}(#{n}i)"
23
+ end
24
+ hash[property] = type.parse(time_string).send("to_#{type.to_s.downcase}")
25
+ hash
26
+ end
27
+ end
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_dm_datastore}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["joshsmoore"]
12
- s.date = %q{2010-02-08}
11
+ s.authors = ["Josh S Moore", "John Woodell"]
12
+ s.date = %q{2010-02-20}
13
13
  s.description = %q{Integrate datamapper to Rails for the Google App Engine}
14
- s.email = %q{joshsmoore@gmail.com}
14
+ s.email = ["joshsmoore@gmail.com", "woodie@netpress.com"]
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -23,12 +23,17 @@ Gem::Specification.new do |s|
23
23
  "README.rdoc",
24
24
  "Rakefile",
25
25
  "VERSION",
26
- "dm-rails-gae.gemspec",
27
26
  "generators/dd_model/USAGE",
28
27
  "generators/dd_model/dd_model_generator.rb",
29
28
  "generators/dd_model/templates/model.rb",
30
29
  "generators/dd_model/templates/unit_test.rb",
31
30
  "lib/rails_dm_datastore.rb",
31
+ "lib/rails_dm_datastore/action_view.rb",
32
+ "lib/rails_dm_datastore/active_support.rb",
33
+ "lib/rails_dm_datastore/data_mapper.rb",
34
+ "lib/rails_dm_datastore/extlib.rb",
35
+ "lib/rails_dm_datastore/local_object_space.rb",
36
+ "lib/rails_dm_datastore/multiparameter_assignments.rb",
32
37
  "rails_dm_datastore.gemspec",
33
38
  "test/helper.rb",
34
39
  "test/test_dm-rails-gae.rb",
@@ -40,8 +45,8 @@ Gem::Specification.new do |s|
40
45
  s.rubygems_version = %q{1.3.5}
41
46
  s.summary = %q{Generators for dm on gae}
42
47
  s.test_files = [
43
- "test/helper.rb",
44
- "test/test_dm-rails-gae.rb",
48
+ "test/test_dm-rails-gae.rb",
49
+ "test/helper.rb",
45
50
  "test/test_weak_reference.rb"
46
51
  ]
47
52
 
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_dm_datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
- - joshsmoore
7
+ - Josh S Moore
8
+ - John Woodell
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2010-02-08 00:00:00 +08:00
13
+ date: 2010-02-20 00:00:00 +08:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -83,7 +84,9 @@ dependencies:
83
84
  version: "0"
84
85
  version:
85
86
  description: Integrate datamapper to Rails for the Google App Engine
86
- email: joshsmoore@gmail.com
87
+ email:
88
+ - joshsmoore@gmail.com
89
+ - woodie@netpress.com
87
90
  executables: []
88
91
 
89
92
  extensions: []
@@ -98,12 +101,17 @@ files:
98
101
  - README.rdoc
99
102
  - Rakefile
100
103
  - VERSION
101
- - dm-rails-gae.gemspec
102
104
  - generators/dd_model/USAGE
103
105
  - generators/dd_model/dd_model_generator.rb
104
106
  - generators/dd_model/templates/model.rb
105
107
  - generators/dd_model/templates/unit_test.rb
106
108
  - lib/rails_dm_datastore.rb
109
+ - lib/rails_dm_datastore/action_view.rb
110
+ - lib/rails_dm_datastore/active_support.rb
111
+ - lib/rails_dm_datastore/data_mapper.rb
112
+ - lib/rails_dm_datastore/extlib.rb
113
+ - lib/rails_dm_datastore/local_object_space.rb
114
+ - lib/rails_dm_datastore/multiparameter_assignments.rb
107
115
  - rails_dm_datastore.gemspec
108
116
  - test/helper.rb
109
117
  - test/test_dm-rails-gae.rb
@@ -137,6 +145,6 @@ signing_key:
137
145
  specification_version: 3
138
146
  summary: Generators for dm on gae
139
147
  test_files:
140
- - test/helper.rb
141
148
  - test/test_dm-rails-gae.rb
149
+ - test/helper.rb
142
150
  - test/test_weak_reference.rb
data/dm-rails-gae.gemspec DELETED
@@ -1,62 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{dm-rails-gae}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["joshsmoore"]
12
- s.date = %q{2010-01-08}
13
- s.description = %q{Integrate datamapper to rails3 for the Google App Engine}
14
- s.email = %q{joshsmoore@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "dm-rails-gae.gemspec",
27
- "generators/dm_model/dm_model_generator.rb",
28
- "generators/dm_model/templates/model.rb",
29
- "generators/dm_model/templates/unit_test.rb",
30
- "lib/USAGE",
31
- "lib/dm-rails-gae.rb",
32
- "lib/generators/data_mapper/USAGE",
33
- "lib/generators/data_mapper/model/model_generator.rb",
34
- "lib/generators/data_mapper/model/templates/model.rb",
35
- "lib/generators/data_mapper/templates/model.rb",
36
- "test/helper.rb",
37
- "test/test_dm-rails-gae.rb"
38
- ]
39
- s.homepage = %q{http://github.com/joshsmoore/dm-rails-gae}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.5}
43
- s.summary = %q{Generators for dm on gae}
44
- s.test_files = [
45
- "test/helper.rb",
46
- "test/test_dm-rails-gae.rb"
47
- ]
48
-
49
- if s.respond_to? :specification_version then
50
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
- s.specification_version = 3
52
-
53
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
- else
56
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
- end
58
- else
59
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
- end
61
- end
62
-