rails_dm_datastore 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rails_dm_datastore.rb +82 -0
- data/rails_dm_datastore.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/lib/rails_dm_datastore.rb
CHANGED
@@ -5,14 +5,55 @@ require 'dm-timestamps'
|
|
5
5
|
require 'dm-validations'
|
6
6
|
DataMapper.setup(:default, "appengine://auto")
|
7
7
|
#DataMapper.setup(:ephemeral, "in_memory::")
|
8
|
+
|
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
|
+
|
8
36
|
module DataMapper
|
9
37
|
module Resource
|
38
|
+
alias :attributes_orig= :attributes=
|
10
39
|
# avoid object references in URLs
|
11
40
|
def to_param; id.to_s; end
|
12
41
|
# silence deprecation warnings
|
13
42
|
def new_record?; new?; end
|
14
43
|
# avoid NoMethodError
|
15
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
|
16
57
|
end
|
17
58
|
end
|
18
59
|
|
@@ -78,4 +119,45 @@ module ActionView
|
|
78
119
|
end
|
79
120
|
|
80
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
|
+
|
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
|
81
163
|
end
|
data/rails_dm_datastore.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_dm_datastore}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["joshsmoore"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-08}
|
13
13
|
s.description = %q{Integrate datamapper to Rails for the Google App Engine}
|
14
14
|
s.email = %q{joshsmoore@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_dm_datastore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joshsmoore
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-08 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|