rubyhaze-persisted 0.0.1-jruby → 0.0.3-jruby
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/Rakefile +6 -3
- data/VERSION +1 -1
- data/lib/rubyhaze-persisted.rb +1 -0
- data/lib/rubyhaze/persisted.rb +10 -9
- data/lib/rubyhaze/persisted/model.rb +81 -47
- data/lib/rubyhaze/persisted/shadow_class_generator.rb +78 -51
- data/test/helper.rb +35 -7
- data/test/test_model.rb +120 -4
- data/test/test_persisted.rb +13 -14
- metadata +53 -8
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -6,14 +6,17 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "rubyhaze-persisted"
|
8
8
|
gem.summary = %Q{ActiveRecord-like objects persisted with Hazelcast and RubyHaze}
|
9
|
-
gem.description = %Q{Have your distributed
|
10
|
-
gem.email = "aemadrid@
|
9
|
+
gem.description = %Q{Have your in-mempry distributed JRuby objects and search them too.}
|
10
|
+
gem.email = "aemadrid@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/aemadrid/rubyhaze-persisted"
|
12
12
|
gem.authors = ["Adrian Madrid"]
|
13
13
|
gem.files = FileList['bin/*', 'lib/**/*.rb', 'test/**/*.rb', '[A-Z]*'].to_a
|
14
14
|
gem.test_files = Dir["test/test*.rb"]
|
15
15
|
gem.platform = "jruby"
|
16
|
-
gem.add_dependency "
|
16
|
+
gem.add_dependency "rubyhaze", "~> 0.0.6"
|
17
|
+
gem.add_dependency "bitescript", "0.0.6"
|
18
|
+
gem.add_dependency "activesupport", "~> 3.0.0"
|
19
|
+
gem.add_dependency "activemodel", "~> 3.0.0"
|
17
20
|
end
|
18
21
|
Jeweler::GemcutterTasks.new
|
19
22
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/rubyhaze/persisted')
|
data/lib/rubyhaze/persisted.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
gem "rubyhaze", "~> 0.0.6"
|
3
|
+
rescue NoMethodError
|
4
|
+
require 'rubygems'
|
5
|
+
gem "rubyhaze", "~> 0.0.6"
|
6
|
+
ensure
|
7
|
+
require "rubyhaze"
|
8
|
+
end
|
9
|
+
|
1
10
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'persisted'))
|
11
|
+
|
2
12
|
require 'shadow_class_generator'
|
3
13
|
require 'model'
|
4
|
-
|
5
|
-
class D
|
6
|
-
include RubyHaze::Persisted
|
7
|
-
attribute :name, :string
|
8
|
-
attribute :age, :int
|
9
|
-
|
10
|
-
|
11
|
-
validates_presence_of :name
|
12
|
-
end
|
@@ -1,36 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
gem "activesupport"
|
4
|
-
|
1
|
+
gem "activesupport", "3.0.0"
|
5
2
|
require "active_support/core_ext/module/attr_accessor_with_default"
|
6
3
|
require "active_support/core_ext/object/blank"
|
7
4
|
require "active_support/concern"
|
8
5
|
require "active_support/callbacks"
|
9
6
|
|
7
|
+
gem "activemodel", "3.0.0"
|
10
8
|
require "active_model"
|
11
9
|
|
12
10
|
module RubyHaze
|
11
|
+
|
13
12
|
module Persisted
|
13
|
+
class Register
|
14
|
+
class << self
|
15
|
+
def classes
|
16
|
+
@classes ||= []
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
def add(base)
|
20
|
+
return false if classes.include? base.name
|
21
|
+
classes << base.name
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
extend ActiveModel::Callbacks
|
27
|
+
def self.included(base)
|
28
|
+
return unless RubyHaze::Persisted::Register.add(base)
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
include ActiveModel::Serializers::JSON
|
27
|
-
include ActiveModel::Serializers::Xml
|
28
|
-
include ActiveModel::Validations
|
30
|
+
base.send :extend, ClassMethods
|
31
|
+
base.send :extend, ActiveModel::Naming
|
32
|
+
base.send :extend, ActiveModel::Translation
|
33
|
+
base.send :extend, ActiveModel::Callbacks
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
base.send :include, ActiveModel::AttributeMethods
|
36
|
+
base.send :include, ActiveModel::Conversion
|
37
|
+
base.send :include, ActiveModel::Dirty
|
38
|
+
base.send :include, ActiveModel::Serialization
|
39
|
+
base.send :include, ActiveModel::Serializers::JSON
|
40
|
+
base.send :include, ActiveModel::Serializers::Xml
|
41
|
+
base.send :include, ActiveModel::Validations
|
42
|
+
base.send :include, InstanceMethods
|
43
|
+
|
44
|
+
base.attribute_method_suffix '', '=', '?'
|
45
|
+
base.define_model_callbacks :create, :update, :load, :destroy
|
46
|
+
end
|
34
47
|
|
35
48
|
module InstanceMethods
|
36
49
|
|
@@ -121,35 +134,52 @@ module RubyHaze
|
|
121
134
|
result != false
|
122
135
|
end
|
123
136
|
|
124
|
-
def
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
137
|
+
def create
|
138
|
+
_run_create_callbacks do
|
139
|
+
@uid ||= RubyHaze.random_uuid
|
140
|
+
self.class.map[uid] = shadow_object
|
141
|
+
@previously_changed = changes
|
142
|
+
@changed_attributes.clear
|
143
|
+
@new_record = false
|
144
|
+
uid
|
145
|
+
end
|
130
146
|
end
|
131
147
|
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
148
|
+
def update
|
149
|
+
_run_update_callbacks do
|
150
|
+
raise "Missing uid" unless uid?
|
151
|
+
self.class.map[uid] = shadow_object
|
152
|
+
@previously_changed = changes
|
153
|
+
@changed_attributes.clear
|
154
|
+
true
|
155
|
+
end
|
139
156
|
end
|
140
157
|
|
141
158
|
def load
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
159
|
+
_run_load_callbacks do
|
160
|
+
raise "Missing uid for load" if uid.blank?
|
161
|
+
found = self.class.map[uid]
|
162
|
+
raise "Record not found" unless found
|
163
|
+
load_shadow_object(found)
|
164
|
+
@changed_attributes.clear
|
165
|
+
@new_record = false
|
166
|
+
self
|
167
|
+
end
|
149
168
|
end
|
150
169
|
alias :reload :load
|
151
170
|
alias :reset :load
|
152
171
|
|
172
|
+
def destroy
|
173
|
+
_run_destroy_callbacks do
|
174
|
+
if persisted?
|
175
|
+
self.class.map.remove uid
|
176
|
+
end
|
177
|
+
@destroyed = true
|
178
|
+
freeze
|
179
|
+
end
|
180
|
+
end
|
181
|
+
alias :delete :destroy
|
182
|
+
|
153
183
|
def to_s
|
154
184
|
"<#{self.class.name}:#{object_id} #{to_ary[1..-1].map { |k, v| "#{k}=#{v}" }.join(" ")} >"
|
155
185
|
end
|
@@ -170,16 +200,12 @@ module RubyHaze
|
|
170
200
|
obj
|
171
201
|
end
|
172
202
|
|
173
|
-
def map_java_class_name
|
174
|
-
'RubyHaze_Shadow__' + name
|
175
|
-
end
|
176
|
-
|
177
203
|
def map_java_class
|
178
|
-
@java_class ||= RubyHaze::Persisted::
|
204
|
+
@java_class ||= RubyHaze::Persisted::Shadow::Generator.get name, attributes
|
179
205
|
end
|
180
206
|
|
181
207
|
def map
|
182
|
-
@map ||= RubyHaze::Map.new
|
208
|
+
@map ||= RubyHaze::Map.new "RubyHaze::Persisted #{name}"
|
183
209
|
end
|
184
210
|
|
185
211
|
def attributes
|
@@ -201,13 +227,21 @@ module RubyHaze
|
|
201
227
|
def attribute(name, type, options = {})
|
202
228
|
raise "Attribute [#{name}] already defined" if attribute_names.include?(name)
|
203
229
|
@attributes << [name, type, options]
|
204
|
-
|
230
|
+
@attribute_methods_generated = false
|
231
|
+
define_attribute_methods [ name ]
|
232
|
+
self
|
205
233
|
end
|
206
234
|
|
207
235
|
def find(predicate)
|
208
236
|
map.values(predicate).map { |shadow| new.load_shadow_object shadow }
|
209
237
|
end
|
210
238
|
|
239
|
+
def [](*args)
|
240
|
+
options = args.extract_options!
|
241
|
+
options[:uid] = args.first if RubyHaze.valid_uuid?(args.first)
|
242
|
+
find(options).first
|
243
|
+
end
|
244
|
+
|
211
245
|
def find_uids(predicate)
|
212
246
|
map.keys(predicate)
|
213
247
|
end
|
@@ -1,64 +1,91 @@
|
|
1
|
+
gem "bitescript", "0.0.6"
|
1
2
|
require 'bitescript'
|
2
3
|
|
3
4
|
module RubyHaze
|
4
5
|
module Persisted
|
5
|
-
module
|
6
|
+
module Shadow
|
6
7
|
|
7
|
-
|
8
|
-
RubyHaze::Persisted.const_defined?(name) ?
|
9
|
-
RubyHaze::Persisted.const_get(name) :
|
10
|
-
generate(name, attributes)
|
8
|
+
module Classes
|
11
9
|
end
|
12
10
|
|
13
|
-
|
14
|
-
{
|
15
|
-
:string => :aload,
|
16
|
-
:int => :iload,
|
17
|
-
:boolean => :iload,
|
18
|
-
:double => :dload,
|
19
|
-
}
|
20
|
-
end
|
11
|
+
class Generator
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
class_dsl << %{ putfield this, :#{attr_name}, send(:#{type})}
|
39
|
-
end
|
40
|
-
class_dsl << %{ returnvoid}
|
41
|
-
class_dsl << %{ end}
|
42
|
-
class_dsl << %{end}
|
43
|
-
class_dsl = class_dsl.join("\n")
|
44
|
-
if $DEBUG
|
45
|
-
FileUtils.mkdir_p tmp_path
|
46
|
-
filename = File.join tmp_path, name + '.bc'
|
47
|
-
File.open(filename, 'w') { |file| file.write class_dsl }
|
48
|
-
end
|
49
|
-
builder.instance_eval class_dsl, __FILE__, __LINE__
|
50
|
-
builder.generate do |builder_filename, class_builder|
|
51
|
-
bytes = class_builder.generate
|
52
|
-
klass = JRuby.runtime.jruby_class_loader.define_class name, bytes.to_java_bytes
|
53
|
-
if $DEBUG
|
54
|
-
filename = File.join tmp_path, builder_filename
|
55
|
-
File.open(filename, 'w') { |file| file.write class_builder.generate }
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def get(name, attributes)
|
16
|
+
safe_name = name.gsub '::', '__'
|
17
|
+
RubyHaze::Persisted::Shadow::Classes.const_defined?(safe_name) ?
|
18
|
+
RubyHaze::Persisted::Shadow::Classes.const_get(safe_name) :
|
19
|
+
generate(name, attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def attribute_load_types
|
23
|
+
{
|
24
|
+
:string => :aload,
|
25
|
+
:int => :iload,
|
26
|
+
:boolean => :iload,
|
27
|
+
:double => :dload,
|
28
|
+
}
|
56
29
|
end
|
57
|
-
|
30
|
+
|
31
|
+
def template(name, attributes)
|
32
|
+
str = []
|
33
|
+
packages = %w{org rubyhaze persisted shadow classes}
|
34
|
+
names = name.split '::'
|
35
|
+
name = names.pop
|
36
|
+
packages += names
|
37
|
+
str << "package '#{packages.join('.')}' do"
|
38
|
+
str << %{ public_class "#{name}", object, Java::JavaIo::Serializable do}
|
39
|
+
attributes.each do |attr_name, type, options|
|
40
|
+
str << %{ public_field :#{attr_name}, send(:#{type})}
|
41
|
+
end
|
42
|
+
str << %{ public_constructor [], #{attributes.map { |ary| ary[1].to_s }.join(', ')} do}
|
43
|
+
str << %{ aload 0}
|
44
|
+
str << %{ invokespecial object, "<init>", [void]}
|
45
|
+
index = 1
|
46
|
+
attributes.each do |attr_name, type, options|
|
47
|
+
str << %{ aload 0}
|
48
|
+
load_type = attribute_load_types[type]
|
49
|
+
raise "Unknown load type for attribute [#{attr_name}] on class [#{name}]" unless load_type
|
50
|
+
str << %{ #{load_type} #{index}}
|
51
|
+
index += 1
|
52
|
+
str << %{ putfield this, :#{attr_name}, send(:#{type})}
|
53
|
+
end
|
54
|
+
str << %{ returnvoid}
|
55
|
+
str << %{ end}
|
56
|
+
str << %{ end}
|
57
|
+
str << %{end}
|
58
|
+
str.join("\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate(name, attributes)
|
62
|
+
tmp_path = (ENV['RUBYHAZE_PERSISTED_TMP_PATH'] || File.join(Dir.pwd, 'tmp'))
|
63
|
+
builder = BiteScript::FileBuilder.new name + '.class'
|
64
|
+
str = template name, attributes
|
65
|
+
if $DEBUG
|
66
|
+
FileUtils.mkdir_p tmp_path
|
67
|
+
filename = File.join tmp_path, name + '.bc'
|
68
|
+
puts ">> Saving bitescript [#{filename}]..."
|
69
|
+
File.open(filename, 'w') { |file| file.write str }
|
70
|
+
end
|
71
|
+
builder.instance_eval str, __FILE__, __LINE__
|
72
|
+
safe_name = name.gsub '::', '__'
|
73
|
+
builder.generate do |builder_filename, class_builder|
|
74
|
+
bytes = class_builder.generate
|
75
|
+
klass = JRuby.runtime.jruby_class_loader.define_class builder_filename[0..-7].gsub('/', '.'), bytes.to_java_bytes
|
76
|
+
if $DEBUG
|
77
|
+
filename = File.join tmp_path, builder_filename
|
78
|
+
FileUtils.mkdir_p File.dirname(filename)
|
79
|
+
puts ">> Saving class [#{filename}]..."
|
80
|
+
File.open(filename, 'w') { |file| file.write class_builder.generate }
|
81
|
+
end
|
82
|
+
RubyHaze::Persisted::Shadow::Classes.const_set safe_name, JavaUtilities.get_proxy_class(klass.name)
|
83
|
+
end
|
84
|
+
RubyHaze::Persisted::Shadow::Classes.const_get safe_name
|
85
|
+
end
|
86
|
+
|
58
87
|
end
|
59
|
-
RubyHaze::Persisted.const_get name
|
60
88
|
end
|
61
|
-
|
62
89
|
end
|
63
90
|
end
|
64
|
-
end
|
91
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,11 +1,39 @@
|
|
1
|
-
|
2
|
-
require 'forwardable'
|
1
|
+
unless defined?(HELPER_LOADED)
|
3
2
|
|
4
|
-
require
|
3
|
+
require 'test/unit'
|
4
|
+
require 'forwardable'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/rubyhaze/persisted')
|
7
|
+
|
8
|
+
class Notices
|
9
|
+
class << self
|
10
|
+
extend Forwardable
|
11
|
+
def all
|
12
|
+
@all ||= []
|
13
|
+
end
|
14
|
+
def_delegators :all, :size, :<<, :first, :last, :pop, :clear, :map
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Foo
|
19
|
+
include RubyHaze::Persisted
|
20
|
+
attribute :name, :string
|
21
|
+
attribute :age, :int
|
22
|
+
end
|
23
|
+
|
24
|
+
module Sub
|
25
|
+
class Foo
|
26
|
+
include RubyHaze::Persisted
|
27
|
+
attribute :name, :string
|
28
|
+
end
|
29
|
+
end
|
8
30
|
|
9
|
-
# Start a new hazelcast cluster
|
10
|
-
RubyHaze.init :group => { :username => "test_persisted", :password => "test_persisted" }
|
31
|
+
# Start a new hazelcast cluster
|
32
|
+
RubyHaze.init :group => { :username => "test_persisted", :password => "test_persisted" }
|
11
33
|
|
34
|
+
HELPER_LOADED = true
|
35
|
+
|
36
|
+
class Test::Unit::TestCase
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/test_model.rb
CHANGED
@@ -1,14 +1,130 @@
|
|
1
|
-
require
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helper'))
|
2
2
|
|
3
3
|
class LintTest < ActiveModel::TestCase
|
4
4
|
include ActiveModel::Lint::Tests
|
5
5
|
|
6
|
-
class
|
6
|
+
class Admin
|
7
|
+
class User
|
8
|
+
include RubyHaze::Persisted
|
9
|
+
|
10
|
+
attribute :name, :string
|
11
|
+
attribute :age, :integer
|
12
|
+
attribute :active, :boolean
|
13
|
+
attribute :salary, :double
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ImportantPerson
|
18
|
+
include RubyHaze::Persisted
|
19
|
+
|
20
|
+
attribute :name, :string
|
21
|
+
|
22
|
+
before_create :notice_create_before
|
23
|
+
after_update :notice_update_after
|
24
|
+
around_load :notice_load_around
|
25
|
+
after_destroy :notice_destroy_after
|
26
|
+
|
27
|
+
def notice_create_before
|
28
|
+
Notices.all << "ImportantPerson before create"
|
29
|
+
end
|
30
|
+
|
31
|
+
def notice_update_after
|
32
|
+
Notices.all << "ImportantPerson after update"
|
33
|
+
end
|
34
|
+
|
35
|
+
def notice_load_around
|
36
|
+
Notices.all << "ImportantPerson around load before"
|
37
|
+
yield
|
38
|
+
Notices.all << "ImportantPerson around load after"
|
39
|
+
end
|
40
|
+
|
41
|
+
def notice_destroy_after
|
42
|
+
Notices.all << "ImportantPerson after destroy"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class SimplePerson
|
7
48
|
include RubyHaze::Persisted
|
49
|
+
|
8
50
|
attribute :name, :string
|
9
51
|
end
|
10
52
|
|
11
53
|
def setup
|
12
|
-
@model =
|
54
|
+
@model = Admin::User.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_naming
|
58
|
+
@model_name = Admin::User.model_name
|
59
|
+
assert_equal "lint_test_admin_user", @model_name.singular
|
60
|
+
assert_equal "lint_test_admin_users", @model_name.plural
|
61
|
+
assert_equal "user", @model_name.element
|
62
|
+
assert_equal "lint_test/admin/users", @model_name.collection
|
63
|
+
assert_equal "lint_test/admin/users/user", @model_name.partial_path
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_translation
|
67
|
+
I18n.backend = I18n::Backend::Simple.new
|
68
|
+
I18n.backend.store_translations 'en', :attributes => { :age => 'age default attribute' }
|
69
|
+
assert_equal 'age default attribute', Admin::User.human_attribute_name('age')
|
70
|
+
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:foo => {:name => 'foo name attribute'} } }
|
71
|
+
assert_equal 'foo name attribute', Foo.human_attribute_name('name')
|
72
|
+
I18n.backend.store_translations 'en', :activemodel => {:models => {:foo => 'foo model'} }
|
73
|
+
assert_equal 'foo model', Foo.model_name.human
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_callbacks
|
77
|
+
Notices.clear
|
78
|
+
assert_equal 0, Notices.size
|
79
|
+
important_person = ImportantPerson.create :name => "David"
|
80
|
+
ImportantPerson.attributes
|
81
|
+
assert_equal 1, Notices.size
|
82
|
+
assert_equal "ImportantPerson before create", Notices.pop
|
83
|
+
important_person.name = "David The Great"
|
84
|
+
important_person.update
|
85
|
+
assert_equal 1, Notices.size
|
86
|
+
assert_equal "ImportantPerson after update", Notices.pop
|
87
|
+
important_person.reload
|
88
|
+
assert_equal 2, Notices.size
|
89
|
+
assert_equal "ImportantPerson around load after", Notices.pop
|
90
|
+
assert_equal "ImportantPerson around load before", Notices.pop
|
91
|
+
important_person.destroy
|
92
|
+
assert_equal 1, Notices.size
|
93
|
+
assert_equal "ImportantPerson after destroy", Notices.pop
|
94
|
+
assert_equal 0, Notices.size
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_attribute_methods
|
98
|
+
simple_person = SimplePerson.create :name => "David"
|
99
|
+
assert_equal simple_person.name, "David"
|
100
|
+
assert simple_person.name?
|
101
|
+
simple_person.name = "Joseph"
|
102
|
+
assert_equal simple_person.name, "Joseph"
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_conversion
|
106
|
+
simple_person = SimplePerson.create :uid => '123', :name => "David"
|
107
|
+
assert_equal simple_person.to_model, simple_person
|
108
|
+
assert_nil simple_person.to_key
|
109
|
+
assert_nil simple_person.to_param
|
110
|
+
simple_person.save
|
111
|
+
assert_equal %w{123}, simple_person.to_key
|
112
|
+
assert_equal '123', simple_person.to_param
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_dirty
|
116
|
+
uid = '456'
|
117
|
+
names = [ "David", "Bob", "James", "Earl" ]
|
118
|
+
SimplePerson.create :uid => uid, :name => names.first
|
119
|
+
simple_person = SimplePerson.find uid
|
120
|
+
assert_equal false, simple_person.changed?
|
121
|
+
simple_person.name = names[1]
|
122
|
+
assert simple_person.changed?
|
123
|
+
assert simple_person.name_changed?
|
124
|
+
assert_equal names[1], simple_person.name_was
|
125
|
+
assert_equal names[0,2], simple_person.name_change
|
126
|
+
exp_changes = { :name => names[0,2] }
|
127
|
+
assert_equal exp_changes, simple_person.changes
|
128
|
+
|
13
129
|
end
|
14
|
-
end
|
130
|
+
end
|
data/test/test_persisted.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class Foo
|
4
|
-
include RubyHaze::Persisted
|
5
|
-
attribute :name, :string
|
6
|
-
attribute :age, :int
|
7
|
-
end unless defined? Foo
|
1
|
+
require(File.expand_path(File.dirname(__FILE__) + '/helper'))
|
8
2
|
|
9
3
|
class TestRubyHazePersistedClassMethods < Test::Unit::TestCase
|
10
4
|
|
11
5
|
def test_right_store
|
12
6
|
store = Foo.map
|
13
7
|
assert_equal store.class.name, "RubyHaze::Map"
|
14
|
-
assert_equal store.name, "
|
15
|
-
assert_equal store.name, RubyHaze::Map.new("
|
8
|
+
assert_equal store.name, "RubyHaze::Persisted Foo"
|
9
|
+
assert_equal store.name, RubyHaze::Map.new("RubyHaze::Persisted Foo").name
|
16
10
|
end
|
17
11
|
|
18
12
|
def test_right_fields
|
19
|
-
|
20
|
-
assert_equal fields, [[:uid, :string, {}], [:name, :string, {}], [:age, :int, {}]]
|
13
|
+
assert_equal Foo.attributes, [[:uid, :string, {}], [:name, :string, {}], [:age, :int, {}]]
|
21
14
|
assert_equal Foo.attribute_names, [:uid, :name, :age]
|
22
15
|
assert_equal Foo.attribute_types, [:string, :string, :int]
|
23
16
|
assert_equal Foo.attribute_options, [{}, {}, {}]
|
17
|
+
|
18
|
+
assert_equal Sub::Foo.attributes, [[:uid, :string, {}], [:name, :string, {}]]
|
19
|
+
assert_equal Sub::Foo.attribute_names, [:uid, :name]
|
20
|
+
assert_equal Sub::Foo.attribute_types, [:string, :string]
|
21
|
+
assert_equal Sub::Foo.attribute_options, [{}, {}]
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_right_shadow_class
|
27
|
-
assert_equal Foo.
|
28
|
-
assert_equal Foo.map_java_class.name, "Java::
|
25
|
+
assert_equal Foo.map_java_class.name, "Java::OrgRubyhazePersistedShadowClasses::Foo"
|
26
|
+
assert_equal Sub::Foo.map_java_class.name, "Java::OrgRubyhazePersistedShadowClassesSub::Foo"
|
29
27
|
end
|
30
28
|
|
31
29
|
end
|
@@ -68,13 +66,14 @@ class TestRubyHazePersistedStorage < Test::Unit::TestCase
|
|
68
66
|
assert_equal res.first, @a
|
69
67
|
assert_equal res.first.name, @a.name
|
70
68
|
|
69
|
+
# # Throws an internal exception
|
71
70
|
# res = Foo.find "age IN (32, 65)"
|
72
71
|
# assert_equal res.size, 2
|
73
72
|
# names = res.map{|x| x.name }.sort
|
74
73
|
# assert_equal names.first, @a.name
|
75
74
|
# assert_equal names.last, @b.name
|
76
75
|
|
77
|
-
res = Foo.find "age <
|
76
|
+
res = Foo.find "age < 60 AND name LIKE '%ae%'"
|
78
77
|
assert_equal res.size, 1
|
79
78
|
assert_equal res.first, @c
|
80
79
|
assert_equal res.first.name, @c.name
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: jruby
|
11
11
|
authors:
|
12
12
|
- Adrian Madrid
|
@@ -14,23 +14,67 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08
|
17
|
+
date: 2010-09-08 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: rubyhaze
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 0
|
29
|
-
|
29
|
+
- 0
|
30
|
+
- 6
|
31
|
+
version: 0.0.6
|
30
32
|
type: :runtime
|
31
33
|
version_requirements: *id001
|
32
|
-
|
33
|
-
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bitescript
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
- 6
|
45
|
+
version: 0.0.6
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activesupport
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 3
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
version: 3.0.0
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activemodel
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 3
|
71
|
+
- 0
|
72
|
+
- 0
|
73
|
+
version: 3.0.0
|
74
|
+
type: :runtime
|
75
|
+
version_requirements: *id004
|
76
|
+
description: Have your in-mempry distributed JRuby objects and search them too.
|
77
|
+
email: aemadrid@gmail.com
|
34
78
|
executables: []
|
35
79
|
|
36
80
|
extensions: []
|
@@ -43,6 +87,7 @@ files:
|
|
43
87
|
- README.rdoc
|
44
88
|
- Rakefile
|
45
89
|
- VERSION
|
90
|
+
- lib/rubyhaze-persisted.rb
|
46
91
|
- lib/rubyhaze/persisted.rb
|
47
92
|
- lib/rubyhaze/persisted/model.rb
|
48
93
|
- lib/rubyhaze/persisted/shadow_class_generator.rb
|