ohm-contrib 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohm/contrib.rb +2 -2
- data/lib/ohm/contrib/callbacks.rb +24 -28
- data/lib/ohm/contrib/typecast.rb +1 -12
- data/test/typecast_hash_test.rb +1 -1
- metadata +61 -71
- data/test/autoload_test.rb +0 -19
data/lib/ohm/contrib.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ohm
|
2
2
|
module Contrib
|
3
|
-
VERSION = "0.1.
|
3
|
+
VERSION = "0.1.2"
|
4
4
|
end
|
5
5
|
|
6
6
|
autoload :ActiveModelExtension, "ohm/contrib/active_model_extension"
|
@@ -18,4 +18,4 @@ module Ohm
|
|
18
18
|
autoload :Scope, "ohm/contrib/scope"
|
19
19
|
autoload :SoftDelete, "ohm/contrib/soft_delete"
|
20
20
|
autoload :FulltextSearching, "ohm/contrib/fulltext_searching"
|
21
|
-
end
|
21
|
+
end
|
@@ -55,7 +55,6 @@ module Ohm
|
|
55
55
|
module Callbacks
|
56
56
|
def self.included(base)
|
57
57
|
base.extend Macros
|
58
|
-
base.extend Overrides
|
59
58
|
end
|
60
59
|
|
61
60
|
module Macros
|
@@ -127,18 +126,6 @@ module Ohm
|
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|
130
|
-
# This module is for class method overrides. As of now
|
131
|
-
# it only overrides Ohm::Model::create to force calling save
|
132
|
-
# instead of calling create so that Model.create will call
|
133
|
-
# not only before/after :create but also before/after :save
|
134
|
-
module Overrides
|
135
|
-
def create(*args)
|
136
|
-
model = new(*args)
|
137
|
-
model.save
|
138
|
-
model
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
129
|
# Overrides the validate method of Ohm::Model. This is a bit tricky,
|
143
130
|
# since typically you override this. Make sure you do something like:
|
144
131
|
#
|
@@ -165,10 +152,20 @@ module Ohm
|
|
165
152
|
# If the create succeeds, all after :create callbacks are
|
166
153
|
# executed.
|
167
154
|
def create
|
168
|
-
|
155
|
+
return unless valid?
|
156
|
+
|
157
|
+
execute_callback(:before, :create)
|
158
|
+
execute_callback(:before, :save)
|
159
|
+
|
160
|
+
initialize_id
|
169
161
|
|
170
|
-
|
171
|
-
|
162
|
+
mutex do
|
163
|
+
create_model_membership
|
164
|
+
write
|
165
|
+
add_to_indices
|
166
|
+
|
167
|
+
execute_callback(:after, :create)
|
168
|
+
execute_callback(:after, :save)
|
172
169
|
end
|
173
170
|
end
|
174
171
|
|
@@ -178,18 +175,18 @@ module Ohm
|
|
178
175
|
# If the save also succeeds, all after :save callbacks are
|
179
176
|
# executed.
|
180
177
|
def save
|
181
|
-
|
178
|
+
return create if new?
|
179
|
+
return unless valid?
|
182
180
|
|
183
|
-
|
184
|
-
|
185
|
-
execute_callback(:before, :update) if existing
|
186
|
-
end
|
181
|
+
execute_callback(:before, :save)
|
182
|
+
execute_callback(:before, :update)
|
187
183
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
184
|
+
mutex do
|
185
|
+
write
|
186
|
+
update_indices
|
187
|
+
|
188
|
+
execute_callback(:after, :save)
|
189
|
+
execute_callback(:after, :update)
|
193
190
|
end
|
194
191
|
end
|
195
192
|
|
@@ -222,5 +219,4 @@ module Ohm
|
|
222
219
|
__send__("#{ position }_#{ method }")
|
223
220
|
end
|
224
221
|
end
|
225
|
-
end
|
226
|
-
|
222
|
+
end
|
data/lib/ohm/contrib/typecast.rb
CHANGED
@@ -2,18 +2,7 @@ require 'bigdecimal'
|
|
2
2
|
require 'time'
|
3
3
|
require 'date'
|
4
4
|
require 'forwardable'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require "yajl/json_gem"
|
8
|
-
rescue LoadError
|
9
|
-
$stderr.puts(
|
10
|
-
"WARNING: Currently using the `json` gem. You might encounter encoding " +
|
11
|
-
"problems with `Ohm::Types::Hash` and `Ohm::Types::Array`. Best to use " +
|
12
|
-
"the `yajl-ruby` gem to avoid problems and also for performance reasons."
|
13
|
-
)
|
14
|
-
|
15
|
-
require "json"
|
16
|
-
end
|
5
|
+
require "json"
|
17
6
|
|
18
7
|
module Ohm
|
19
8
|
# Provides all the primitive types. The following are included:
|
data/test/typecast_hash_test.rb
CHANGED
@@ -113,7 +113,7 @@ test "ascii 8bit encoding" do
|
|
113
113
|
|
114
114
|
data = File.read(txt, :encoding => "ascii-8bit")
|
115
115
|
|
116
|
-
post = Post.create(:address => { "address1" => data })
|
116
|
+
post = Post.create(:address => { "address1" => data.force_encoding("UTF-8") })
|
117
117
|
post = Post[post.id]
|
118
118
|
|
119
119
|
assert_equal post.address["address1"], data.force_encoding("UTF-8")
|
metadata
CHANGED
@@ -1,82 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm-contrib
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Cyril David
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: ohm
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2164476460 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: cutest
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *2164476460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: cutest
|
27
|
+
requirement: &2164475860 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
36
33
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: redis
|
40
34
|
prerelease: false
|
41
|
-
|
35
|
+
version_requirements: *2164475860
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: redis
|
38
|
+
requirement: &2164474640 !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
47
44
|
type: :development
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: lunar
|
51
45
|
prerelease: false
|
52
|
-
|
46
|
+
version_requirements: *2164474640
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: lunar
|
49
|
+
requirement: &2164474060 !ruby/object:Gem::Requirement
|
53
50
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
58
55
|
type: :development
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: override
|
62
56
|
prerelease: false
|
63
|
-
|
57
|
+
version_requirements: *2164474060
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: override
|
60
|
+
requirement: &2164473440 !ruby/object:Gem::Requirement
|
64
61
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version:
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
69
66
|
type: :development
|
70
|
-
|
71
|
-
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2164473440
|
69
|
+
description: Includes a couple of core functions such as callbacks, timestamping,
|
70
|
+
typecasting and lots of generic validation routines.
|
72
71
|
email: cyx.ucron@gmail.com
|
73
72
|
executables: []
|
74
|
-
|
75
73
|
extensions: []
|
76
|
-
|
77
74
|
extra_rdoc_files: []
|
78
|
-
|
79
|
-
files:
|
75
|
+
files:
|
80
76
|
- lib/ohm/contrib/active_model_extension.rb
|
81
77
|
- lib/ohm/contrib/boundaries.rb
|
82
78
|
- lib/ohm/contrib/callbacks.rb
|
@@ -97,7 +93,6 @@ files:
|
|
97
93
|
- LICENSE
|
98
94
|
- Rakefile
|
99
95
|
- test/activemodel_test.rb
|
100
|
-
- test/autoload_test.rb
|
101
96
|
- test/boundaries_test.rb
|
102
97
|
- test/callbacks_lint.rb
|
103
98
|
- test/date_validations_test.rb
|
@@ -125,33 +120,28 @@ files:
|
|
125
120
|
- test/typecast_time_test.rb
|
126
121
|
- test/typecast_timezone_test.rb
|
127
122
|
- test/web_validations_test.rb
|
128
|
-
has_rdoc: true
|
129
123
|
homepage: http://github.com/cyx/ohm-contrib
|
130
124
|
licenses: []
|
131
|
-
|
132
125
|
post_install_message:
|
133
126
|
rdoc_options: []
|
134
|
-
|
135
|
-
require_paths:
|
127
|
+
require_paths:
|
136
128
|
- lib
|
137
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
130
|
none: false
|
139
|
-
requirements:
|
140
|
-
- -
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
version:
|
143
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
136
|
none: false
|
145
|
-
requirements:
|
146
|
-
- -
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
version:
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
149
141
|
requirements: []
|
150
|
-
|
151
142
|
rubyforge_project: ohm-contrib
|
152
|
-
rubygems_version: 1.
|
143
|
+
rubygems_version: 1.8.11
|
153
144
|
signing_key:
|
154
145
|
specification_version: 2
|
155
146
|
summary: A collection of decoupled drop-in modules for Ohm.
|
156
147
|
test_files: []
|
157
|
-
|
data/test/autoload_test.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
test "autoloading of all libraries" do
|
6
|
-
assert_nothing_raised NameError, LoadError do
|
7
|
-
Ohm::ActiveModelExtension
|
8
|
-
Ohm::Boundaries
|
9
|
-
Ohm::Timestamping
|
10
|
-
Ohm::WebValidations
|
11
|
-
Ohm::NumberValidations
|
12
|
-
Ohm::Typecast
|
13
|
-
Ohm::Locking
|
14
|
-
Ohm::ExtraValidations
|
15
|
-
Ohm::DateValidations
|
16
|
-
Ohm::FulltextSearching
|
17
|
-
Ohm::Slug
|
18
|
-
end
|
19
|
-
end
|