rhodes 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +2 -0
- data/generators/rhogen.rb +13 -8
- data/generators/templates/model/controller.rb +2 -1
- data/generators/templates/model/index.erb +1 -1
- data/generators/templates/model/show.erb +6 -0
- data/generators/templates/source/source_adapter.rb +1 -0
- data/lib/builtinME.rb +25 -6
- data/lib/dateME.rb +24 -0
- data/lib/rho/rhocontact.rb +1 -1
- data/lib/rhodes.rb +1 -1
- data/lib/rhom/rhom_db_adapter.rb +2 -2
- data/lib/rhom/rhom_object.rb +8 -0
- data/lib/rhom/rhom_object_factory.rb +35 -65
- data/lib/rhom/rhom_source.rb +1 -0
- data/spec/configs/account.rb +1 -1
- data/spec/configs/case.rb +1 -1
- data/spec/configs/employee.rb +1 -1
- data/spec/model_generator_spec.rb +1 -1
- data/spec/rhom_object_factory_spec.rb +18 -31
- data/spec/syncdbtest.sqlite +0 -0
- metadata +4 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -13,12 +13,14 @@ generators/templates/model/controller.rb
|
|
13
13
|
generators/templates/model/edit.erb
|
14
14
|
generators/templates/model/index.erb
|
15
15
|
generators/templates/model/new.erb
|
16
|
+
generators/templates/model/show.erb
|
16
17
|
generators/templates/source/source_adapter.rb
|
17
18
|
lib/ServeME.rb
|
18
19
|
lib/TestServe.rb
|
19
20
|
lib/builtinME.rb
|
20
21
|
lib/date.rb
|
21
22
|
lib/date/format.rb
|
23
|
+
lib/dateME.rb
|
22
24
|
lib/erb.rb
|
23
25
|
lib/find.rb
|
24
26
|
lib/rational.rb
|
data/generators/rhogen.rb
CHANGED
@@ -10,13 +10,13 @@ module Rhogen
|
|
10
10
|
DESC
|
11
11
|
|
12
12
|
class BaseGenerator < Templater::Generator
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
alias_method :module_name, :class_name
|
13
|
+
def class_name
|
14
|
+
name.gsub('-', '_').camel_case
|
18
15
|
end
|
19
16
|
|
17
|
+
alias_method :module_name, :class_name
|
18
|
+
end
|
19
|
+
|
20
20
|
class AppGenerator < BaseGenerator
|
21
21
|
|
22
22
|
def self.source_root
|
@@ -34,17 +34,17 @@ module Rhogen
|
|
34
34
|
|
35
35
|
template :application do |template|
|
36
36
|
template.source = 'application.rb'
|
37
|
-
template.destination = "#{name}/application.rb"
|
37
|
+
template.destination = "#{name.camel_case}/application.rb"
|
38
38
|
end
|
39
39
|
|
40
40
|
template :index do |template|
|
41
41
|
template.source = 'index.erb'
|
42
|
-
template.destination = "#{name}/index.erb"
|
42
|
+
template.destination = "#{name.camel_case}/index.erb"
|
43
43
|
end
|
44
44
|
|
45
45
|
template :layout do |template|
|
46
46
|
template.source = 'layout.erb'
|
47
|
-
template.destination = "#{name}/layout.erb"
|
47
|
+
template.destination = "#{name.camel_case}/layout.erb"
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -86,6 +86,11 @@ module Rhogen
|
|
86
86
|
template.source = 'new.erb'
|
87
87
|
template.destination = "#{name.camel_case}/new.erb"
|
88
88
|
end
|
89
|
+
|
90
|
+
template :new do |template|
|
91
|
+
template.source = 'show.erb'
|
92
|
+
template.destination = "#{name.camel_case}/show.erb"
|
93
|
+
end
|
89
94
|
|
90
95
|
template :controller do |template|
|
91
96
|
template.source = 'controller.rb'
|
@@ -10,7 +10,8 @@ class <%= class_name %>Controller < Rho::RhoController
|
|
10
10
|
|
11
11
|
# GET /<%= class_name %>/1
|
12
12
|
def show
|
13
|
-
@<%= name
|
13
|
+
@<%= name %> = <%= class_name %>.find(@params['id'])
|
14
|
+
render :action => :show
|
14
15
|
end
|
15
16
|
|
16
17
|
# GET /<%= class_name %>/new
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<ul id="<%= name.pluralize %>" title="<%= class_name.pluralize %>">
|
2
2
|
<%%@<%=name.pluralize%>.each do |x|%>
|
3
3
|
<%if self.attributes?%>
|
4
|
-
<li><%%=link_to "#{x.<%=attributes[0]%>}", "
|
4
|
+
<li><%%=link_to "#{x.<%=attributes[0]%>}", "show", x.object%></li>
|
5
5
|
<%else%>
|
6
6
|
<li>Some list entry...</li>
|
7
7
|
<%end%>
|
data/lib/builtinME.rb
CHANGED
@@ -59,9 +59,9 @@ module Kernel
|
|
59
59
|
end
|
60
60
|
|
61
61
|
class Object
|
62
|
-
def to_a
|
63
|
-
[self]
|
64
|
-
end
|
62
|
+
# def to_a
|
63
|
+
# [self]
|
64
|
+
# end
|
65
65
|
|
66
66
|
alias type :class
|
67
67
|
|
@@ -76,6 +76,14 @@ module Enumerable
|
|
76
76
|
each {|x| yield x, i; i = i + 1}
|
77
77
|
end
|
78
78
|
|
79
|
+
def to_a
|
80
|
+
arr = []
|
81
|
+
each{|obj| arr <<obj}
|
82
|
+
return arr
|
83
|
+
end
|
84
|
+
|
85
|
+
alias entries :to_a
|
86
|
+
|
79
87
|
def inject(*args)
|
80
88
|
if args.size == 0 then
|
81
89
|
vals = to_a
|
@@ -128,9 +136,9 @@ class Array
|
|
128
136
|
a
|
129
137
|
end
|
130
138
|
|
131
|
-
def to_a
|
132
|
-
self
|
133
|
-
end
|
139
|
+
# def to_a
|
140
|
+
# self
|
141
|
+
# end
|
134
142
|
|
135
143
|
def join(sepString="")
|
136
144
|
return to_s if sepString.nil? || sepString == ""
|
@@ -215,6 +223,17 @@ class Hash
|
|
215
223
|
|
216
224
|
alias each_pair each
|
217
225
|
|
226
|
+
def to_a
|
227
|
+
res = []
|
228
|
+
each_pair do |k, v|
|
229
|
+
item = []
|
230
|
+
item << k
|
231
|
+
item << v
|
232
|
+
res << item
|
233
|
+
end
|
234
|
+
res
|
235
|
+
end
|
236
|
+
|
218
237
|
def inspect
|
219
238
|
r = '{'
|
220
239
|
is_first = true
|
data/lib/dateME.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'date/format'
|
2
|
+
|
3
|
+
class Time
|
4
|
+
|
5
|
+
def strftime(fmt='%F')
|
6
|
+
DateTimeME.new(self).strftime(fmt);
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class DateTimeME < Date
|
11
|
+
|
12
|
+
def wday() @m_time.wday end
|
13
|
+
def mon() @m_time.mon end
|
14
|
+
def year() @m_time.year end
|
15
|
+
def mday() @m_time.mday end
|
16
|
+
def hour() @m_time.hour end
|
17
|
+
def min() @m_time.min end
|
18
|
+
def sec() @m_time.sec end
|
19
|
+
|
20
|
+
def initialize( time )
|
21
|
+
@m_time = time
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/rho/rhocontact.rb
CHANGED
data/lib/rhodes.rb
CHANGED
data/lib/rhom/rhom_db_adapter.rb
CHANGED
@@ -52,7 +52,7 @@ module Rhom
|
|
52
52
|
def execute_sql(sql=nil)
|
53
53
|
result = []
|
54
54
|
if sql
|
55
|
-
puts 'query is ' + sql
|
55
|
+
#puts 'query is ' + sql
|
56
56
|
# Make sure we lock the sync engine's mutex
|
57
57
|
# before we perform a database transaction.
|
58
58
|
# This prevents concurrency issues.
|
@@ -71,7 +71,7 @@ module Rhom
|
|
71
71
|
SyncEngine::unlock_sync_mutex
|
72
72
|
end
|
73
73
|
end
|
74
|
-
puts "returned #{result.length.to_s} records..."
|
74
|
+
#puts "returned #{result.length.to_s} records..."
|
75
75
|
result
|
76
76
|
end
|
77
77
|
|
data/lib/rhom/rhom_object.rb
CHANGED
@@ -36,6 +36,10 @@ module Rhom
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
def remove_var(name)
|
41
|
+
remove_instance_variable("@#{name}")
|
42
|
+
end
|
39
43
|
|
40
44
|
def strip_braces(str=nil)
|
41
45
|
str ? str.gsub(/\{/,"").gsub(/\}/,"") : nil
|
@@ -49,5 +53,9 @@ module Rhom
|
|
49
53
|
end
|
50
54
|
return hash
|
51
55
|
end
|
56
|
+
|
57
|
+
def method_name_reserved?(method)
|
58
|
+
method =~ /object|source_id|update_type|type/
|
59
|
+
end
|
52
60
|
end # RhomObject
|
53
61
|
end # Rhom
|
@@ -76,22 +76,47 @@ module Rhom
|
|
76
76
|
def get_source_id
|
77
77
|
Rho::RhoConfig::sources[self.name.to_s]['source_id'].to_s
|
78
78
|
end
|
79
|
+
|
79
80
|
# retrieve a single record if object id provided, otherwise return
|
80
81
|
# full list corresponding to factory's source id
|
81
82
|
def find(*args)
|
82
83
|
list = []
|
84
|
+
hash_list = {}
|
85
|
+
conditions = {}
|
86
|
+
attrib_length = 0
|
87
|
+
source = Rho::RhoConfig::sources[self.name.to_s]
|
88
|
+
attrib_length = source['attribs'].length if source
|
89
|
+
# source attributes are not initialized, try again
|
90
|
+
::Rhom::RhomObjectFactory::init_source_attribs if attrib_length == 0
|
91
|
+
|
92
|
+
# first find all query objects
|
83
93
|
if args.first == :all
|
84
|
-
|
85
|
-
'*',
|
86
|
-
{"source_id"=>get_source_id,"update_type"=>'query'},
|
87
|
-
{"order by"=>'object'})
|
94
|
+
conditions = {"source_id"=>get_source_id}
|
88
95
|
else
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
96
|
+
conditions = {"object"=>strip_braces(args.first.to_s)}
|
97
|
+
end
|
98
|
+
|
99
|
+
# process query, create, and update lists in order
|
100
|
+
["query", "create", "update"].each do |update_type|
|
101
|
+
conditions.merge!({"update_type"=>update_type})
|
102
|
+
objs = ::Rhom::RhomDbAdapter::select_from_table(::Rhom::TABLE_NAME, '*', conditions,
|
103
|
+
{"order by"=>'object'})
|
104
|
+
objs.collect! do |obj|
|
105
|
+
object = obj['object']
|
106
|
+
attrib = obj['attrib']
|
107
|
+
value = obj['value']
|
108
|
+
hash_list[object] = get_new_obj(obj) if not hash_list[object]
|
109
|
+
if not method_name_reserved?(attrib) and hash_list[object].send attrib.to_sym
|
110
|
+
hash_list[object].remove_var(attrib)
|
111
|
+
end
|
112
|
+
hash_list[object].send attrib.to_sym, value if not method_name_reserved?(attrib)
|
113
|
+
nil # remove the element from the array
|
114
|
+
end
|
93
115
|
end
|
94
|
-
|
116
|
+
|
117
|
+
# convert hash to array
|
118
|
+
list = hash_list.values
|
119
|
+
hash_list = nil
|
95
120
|
if list.length == 1 and args.first != :all
|
96
121
|
return list[0]
|
97
122
|
end
|
@@ -101,54 +126,12 @@ module Rhom
|
|
101
126
|
def find_by(*args)
|
102
127
|
# TODO: implement
|
103
128
|
end
|
104
|
-
|
105
|
-
# returns an array of objects based on an existing array
|
106
|
-
def get_list(objs)
|
107
|
-
new_list = []
|
108
|
-
attrib_length = 0
|
109
|
-
source = Rho::RhoConfig::sources[self.name.to_s]
|
110
|
-
if source
|
111
|
-
attrib_length = source['attribs'].length
|
112
|
-
end
|
113
|
-
if attrib_length == 0
|
114
|
-
# source attributes are not initialized, try again
|
115
|
-
::Rhom::RhomObjectFactory::init_source_attribs
|
116
|
-
end
|
117
|
-
if objs and source and attrib_length > 0
|
118
|
-
list_length = 0
|
119
|
-
list_length = (objs.length / attrib_length) unless attrib_length == 0
|
120
|
-
new_obj = nil
|
121
|
-
# iterate over the array and determine object
|
122
|
-
# structure based on attribute/value pairs
|
123
|
-
list_length.times do |i|
|
124
|
-
new_obj = get_new_obj(objs[i*attrib_length])
|
125
|
-
attrib_length.times do |j|
|
126
|
-
# setup index and assign accessors
|
127
|
-
idx = i*attrib_length+j
|
128
|
-
begin
|
129
|
-
# only update attributes if they belong
|
130
|
-
# to the current object
|
131
|
-
if objs[idx]['object'] == strip_braces((new_obj.send 'object'.to_sym))
|
132
|
-
attrib = objs[idx]['attrib'].to_s
|
133
|
-
value = objs[idx]['value'].to_s
|
134
|
-
new_obj.send attrib.to_sym, value
|
135
|
-
end
|
136
|
-
rescue
|
137
|
-
puts "failed to reference objs[#{idx}]..."
|
138
|
-
end
|
139
|
-
end
|
140
|
-
new_list << new_obj
|
141
|
-
end
|
142
|
-
end
|
143
|
-
new_list
|
144
|
-
end
|
145
129
|
|
130
|
+
private
|
146
131
|
# returns new model instance with a temp object id
|
147
132
|
def get_new_obj(obj, type='query')
|
148
133
|
tmp_obj = self.new
|
149
134
|
tmp_obj.send 'object'.to_sym, "{#{obj['object'].to_s}}"
|
150
|
-
tmp_obj.send 'source_id'.to_sym, get_source_id
|
151
|
-
tmp_obj.send 'update_type'.to_sym, type
|
152
135
|
tmp_obj
|
153
136
|
end
|
154
137
|
end #class methods
|
@@ -190,15 +173,6 @@ module Rhom
|
|
190
173
|
"update_type"=>'create'})
|
191
174
|
end
|
192
175
|
end
|
193
|
-
# Create a temporary query record to display in the list
|
194
|
-
Rho::RhoConfig::sources[self.class.name.to_s]['attribs'].each do |attrib|
|
195
|
-
result = ::Rhom::RhomDbAdapter::insert_into_table(::Rhom::TABLE_NAME,
|
196
|
-
{"source_id"=>self.get_inst_source_id,
|
197
|
-
"object"=>obj,
|
198
|
-
"attrib"=>attrib['attrib'],
|
199
|
-
"value"=>self.send(attrib['attrib'].to_sym),
|
200
|
-
"update_type"=>'query'})
|
201
|
-
end
|
202
176
|
result
|
203
177
|
end
|
204
178
|
|
@@ -236,10 +210,6 @@ module Rhom
|
|
236
210
|
def inst_strip_braces(str=nil)
|
237
211
|
str ? str.gsub(/\{/,"").gsub(/\}/,"") : nil
|
238
212
|
end
|
239
|
-
|
240
|
-
def method_name_reserved?(method)
|
241
|
-
method =~ /object|source_id|update_type/
|
242
|
-
end
|
243
213
|
end)
|
244
214
|
end
|
245
215
|
end
|
data/lib/rhom/rhom_source.rb
CHANGED
data/spec/configs/account.rb
CHANGED
data/spec/configs/case.rb
CHANGED
data/spec/configs/employee.rb
CHANGED
@@ -24,7 +24,7 @@ describe Rhogen::ModelGenerator do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should create config.rb, controller.rb, index.erb, edit.erb, and new.erb files" do
|
27
|
-
['config.rb', 'controller.rb', 'index.erb', 'edit.erb', 'new.erb'].each do |template|
|
27
|
+
['config.rb', 'controller.rb', 'index.erb', 'edit.erb', 'new.erb', 'show.erb'].each do |template|
|
28
28
|
@generator.should create("/tmp/#{model_name.camel_case}/#{template}")
|
29
29
|
end
|
30
30
|
end
|
@@ -34,6 +34,7 @@ describe "RhomObjectFactory" do
|
|
34
34
|
it "should set source_id attributes" do
|
35
35
|
"1".should == Account.get_source_id
|
36
36
|
"2".should == Case.get_source_id
|
37
|
+
"3".should == Employee.get_source_id
|
37
38
|
end
|
38
39
|
|
39
40
|
it "should dynamically assign values" do
|
@@ -50,30 +51,26 @@ describe "RhomObjectFactory" do
|
|
50
51
|
|
51
52
|
it "should retrieve Case models" do
|
52
53
|
results = Case.find(:all)
|
53
|
-
|
54
|
-
results.
|
55
|
-
|
56
|
-
"hire another engineer".should == results[4].name
|
54
|
+
results.length.should == 7
|
55
|
+
results[0].case_number.should == "57"
|
56
|
+
results[4].name.should == "implement SugarCRM sample app"
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should retrieve Account models" do
|
60
60
|
results = Account.find(:all)
|
61
61
|
results.length.should == 5
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"Electronics".should == results[4].industry
|
69
|
-
"Mirapath".should == results[4].name
|
62
|
+
results[0].name.should == "vSpring"
|
63
|
+
results[0].industry.should == "Finance"
|
64
|
+
results[1].name.should == "Rhomobile"
|
65
|
+
results[1].industry.should == "Technology"
|
66
|
+
results[4].industry.should == "Technology"
|
67
|
+
results[4].name.should == "Mobio India"
|
70
68
|
end
|
71
69
|
|
72
70
|
it "should have correct number of attributes" do
|
73
71
|
@account = Account.find(:all).first
|
74
|
-
|
75
|
-
|
76
|
-
@account.instance_variables.size.should == 5
|
72
|
+
|
73
|
+
@account.instance_variables.size.should == 36
|
77
74
|
end
|
78
75
|
|
79
76
|
it "should calculate same djb_hash" do
|
@@ -99,38 +96,28 @@ describe "RhomObjectFactory" do
|
|
99
96
|
destroy_id = @account.object
|
100
97
|
@account.destroy
|
101
98
|
@account_nil = Account.find(destroy_id)
|
102
|
-
|
103
99
|
@account_nil.size.should == 0
|
104
100
|
new_count = Account.find(:all).size
|
105
|
-
|
106
101
|
(count - 1).should == new_count
|
107
102
|
end
|
108
103
|
|
109
104
|
it "should partially update a record" do
|
110
|
-
pending "due to bug #128 this fails"
|
111
|
-
=begin
|
112
105
|
new_attributes = {"name"=>"Mobio US"}
|
113
|
-
@account = Account.find(
|
106
|
+
@account = Account.find("44e804f2-4933-4e20-271c-48fcecd9450d")
|
114
107
|
@account.update_attributes(new_attributes)
|
115
|
-
|
116
|
-
@new_acct
|
117
|
-
|
118
|
-
"Mobio US".should == @new_acct.name
|
119
|
-
"Technology".should == @new_acct.industry
|
120
|
-
=end
|
108
|
+
@new_acct = Account.find("44e804f2-4933-4e20-271c-48fcecd9450d")
|
109
|
+
@new_acct.name.should == "Mobio US"
|
110
|
+
@new_acct.industry.should == "Technology"
|
121
111
|
end
|
122
112
|
|
123
113
|
it "should fully update a record" do
|
124
|
-
pending "due to bug #128 this fails"
|
125
|
-
=begin
|
126
114
|
new_attributes = {"name"=>"Mobio US", "industry"=>"Electronics"}
|
127
115
|
@account = Account.find(:all).first
|
128
116
|
@account.update_attributes(new_attributes)
|
129
117
|
|
130
118
|
@new_acct = Account.find(:all).first
|
131
119
|
|
132
|
-
"Mobio US"
|
133
|
-
|
134
|
-
=end
|
120
|
+
@new_acct.name.should == "Mobio US"
|
121
|
+
@new_acct.industry.should == "Electronics"
|
135
122
|
end
|
136
123
|
end
|
data/spec/syncdbtest.sqlite
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhodes
|
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
|
- Rhomobile Dev
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-27 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -120,12 +120,14 @@ files:
|
|
120
120
|
- generators/templates/model/edit.erb
|
121
121
|
- generators/templates/model/index.erb
|
122
122
|
- generators/templates/model/new.erb
|
123
|
+
- generators/templates/model/show.erb
|
123
124
|
- generators/templates/source/source_adapter.rb
|
124
125
|
- lib/ServeME.rb
|
125
126
|
- lib/TestServe.rb
|
126
127
|
- lib/builtinME.rb
|
127
128
|
- lib/date.rb
|
128
129
|
- lib/date/format.rb
|
130
|
+
- lib/dateME.rb
|
129
131
|
- lib/erb.rb
|
130
132
|
- lib/find.rb
|
131
133
|
- lib/rational.rb
|