rhodes 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Manifest.txt +0 -61
  2. data/Rakefile +11 -13
  3. data/lib/rhodes.rb +2 -2
  4. metadata +33 -77
  5. data/History.txt +0 -40
  6. data/README.rdoc +0 -2
  7. data/bin/rhogen +0 -8
  8. data/generators/rhogen.rb +0 -131
  9. data/generators/templates/application/application.rb +0 -4
  10. data/generators/templates/application/index.erb +0 -11
  11. data/generators/templates/application/layout.erb +0 -17
  12. data/generators/templates/model/config.rb +0 -3
  13. data/generators/templates/model/controller.rb +0 -49
  14. data/generators/templates/model/edit.erb +0 -21
  15. data/generators/templates/model/index.erb +0 -10
  16. data/generators/templates/model/new.erb +0 -16
  17. data/generators/templates/model/show.erb +0 -6
  18. data/generators/templates/source/source_adapter.rb +0 -56
  19. data/lib/ServeME.rb +0 -7
  20. data/lib/TestServe.rb +0 -9
  21. data/lib/bsearch.rb +0 -120
  22. data/lib/builtinME.rb +0 -588
  23. data/lib/date.rb +0 -1792
  24. data/lib/date/format.rb +0 -1339
  25. data/lib/dateME.rb +0 -24
  26. data/lib/erb.rb +0 -896
  27. data/lib/find.rb +0 -81
  28. data/lib/rational.rb +0 -19
  29. data/lib/rationalME.rb +0 -530
  30. data/lib/rho.rb +0 -1
  31. data/lib/rho/render.rb +0 -51
  32. data/lib/rho/rho.rb +0 -240
  33. data/lib/rho/rhoapplication.rb +0 -36
  34. data/lib/rho/rhocontact.rb +0 -110
  35. data/lib/rho/rhocontroller.rb +0 -35
  36. data/lib/rho/rhofsconnector.rb +0 -32
  37. data/lib/rho/rhosupport.rb +0 -139
  38. data/lib/rho/rhoviewhelpers.rb +0 -121
  39. data/lib/rhoframework.rb +0 -38
  40. data/lib/rhofsconnector.rb +0 -1
  41. data/lib/rhom.rb +0 -1
  42. data/lib/rhom/rhom.rb +0 -58
  43. data/lib/rhom/rhom_db_adapter.rb +0 -185
  44. data/lib/rhom/rhom_db_adapterME.rb +0 -93
  45. data/lib/rhom/rhom_object.rb +0 -65
  46. data/lib/rhom/rhom_object_factory.rb +0 -197
  47. data/lib/rhom/rhom_source.rb +0 -60
  48. data/lib/singleton.rb +0 -137
  49. data/lib/time.rb +0 -489
  50. data/spec/app_generator_spec.rb +0 -33
  51. data/spec/app_manifest.txt +0 -3
  52. data/spec/configs/account.rb +0 -3
  53. data/spec/configs/case.rb +0 -3
  54. data/spec/configs/employee.rb +0 -3
  55. data/spec/generator_spec_helper.rb +0 -12
  56. data/spec/model_generator_spec.rb +0 -36
  57. data/spec/rho_controller_spec.rb +0 -139
  58. data/spec/rho_spec.rb +0 -61
  59. data/spec/rhom_object_factory_spec.rb +0 -132
  60. data/spec/rhom_spec.rb +0 -45
  61. data/spec/source_generator_spec.rb +0 -27
  62. data/spec/spec_helper.rb +0 -48
  63. data/spec/stubs.rb +0 -31
  64. data/spec/syncdbtest.sqlite +0 -0
  65. data/tasks/rspec.rake +0 -34
@@ -1,32 +0,0 @@
1
-
2
- module Rho
3
- class RhoFSConnector
4
-
5
- class << self
6
-
7
- def get_app_path(appname)
8
- File.join(__rhoGetCurrentDir(), 'apps/'+appname+'/')
9
- end
10
-
11
- def get_base_app_path
12
- File.join(__rhoGetCurrentDir(), 'apps/')
13
- end
14
-
15
- def get_app_manifest_filename
16
- File.join(__rhoGetCurrentDir(), 'apps/app_manifest.txt')
17
- end
18
-
19
- def get_model_path(appname, modelname)
20
- File.join(__rhoGetCurrentDir(), 'apps/'+appname+'/'+modelname+'/')
21
- end
22
-
23
- def get_db_fullpathname
24
- if defined? SYNC_DB_FILE
25
- File.join(SYNC_DB_FILE)
26
- else
27
- File.join(__rhoGetCurrentDir(), 'db/syncdb.sqlite')
28
- end
29
- end
30
- end
31
- end # RhoApplication
32
- end # Rho
@@ -1,139 +0,0 @@
1
- module Rho
2
- module RhoSupport
3
-
4
- class << self
5
- def _unescape(str, regex) str.gsub(regex){ $1.hex.chr } end
6
-
7
- ESCAPED = /%([0-9a-fA-F]{2})/
8
-
9
- def unescape_form(str)
10
- _unescape(str.gsub(/\+/, " "), ESCAPED)
11
- end
12
-
13
- def parse_query_parameters(query_string)
14
- return {} if query_string.nil?
15
-
16
- pairs = query_string.split('&').collect do |chunk|
17
- next if chunk.empty?
18
- key, value = chunk.split('=', 2)
19
- next if key.empty?
20
- value = value.nil? ? nil : unescape_form(value)
21
- [ unescape_form(key), value ]
22
- end.compact
23
-
24
- UrlEncodedPairParser.new(pairs).result
25
- end
26
-
27
- def query_params(req)
28
- params = {}
29
- unless req['id'].nil?
30
- params['id'] = req['id']
31
- end
32
- unless req['request-query'].nil? or req['request-query'].length == 0
33
- params.merge!(parse_query_parameters(req['request-query']))
34
- end
35
- unless req['headers'].nil? or req['headers']['Content-Type'].nil?
36
- if 'application/x-www-form-urlencoded'.eql? req['headers']['Content-Type']
37
- params.merge!(parse_query_parameters(req['request-body']))
38
- end
39
- end
40
- puts "Params: " + params.to_s unless params.empty?
41
- params
42
- end
43
- end
44
-
45
- class UrlEncodedPairParser < StringScanner #:nodoc:
46
- attr_reader :top, :parent, :result
47
-
48
- def initialize(pairs = [])
49
- super('')
50
- @result = {}
51
- pairs.each { |key, value| parse(key, value) }
52
- end
53
-
54
- KEY_REGEXP = %r{([^\[\]=&]+)}
55
- BRACKETED_KEY_REGEXP = %r{\[([^\[\]=&]+)\]}
56
-
57
- # Parse the query string
58
- def parse(key, value)
59
- self.string = key
60
- @top, @parent = result, nil
61
-
62
- # First scan the bare key
63
- key = scan(KEY_REGEXP) or return
64
- key = post_key_check(key)
65
-
66
- # Then scan as many nestings as present
67
- until eos?
68
- r = scan(BRACKETED_KEY_REGEXP) or return
69
- key = self[1]
70
- key = post_key_check(key)
71
- end
72
-
73
- bind(key, value)
74
- end
75
-
76
- private
77
- # After we see a key, we must look ahead to determine our next action. Cases:
78
- #
79
- # [] follows the key. Then the value must be an array.
80
- # = follows the key. (A value comes next)
81
- # & or the end of string follows the key. Then the key is a flag.
82
- # otherwise, a hash follows the key.
83
- def post_key_check(key)
84
- if scan(/\[\]/) # a[b][] indicates that b is an array
85
- container(key, Array)
86
- nil
87
- elsif check(/\[[^\]]/) # a[b] indicates that a is a hash
88
- container(key, Hash)
89
- nil
90
- else # End of key? We do nothing.
91
- key
92
- end
93
- end
94
-
95
- # Add a container to the stack.
96
- def container(key, klass)
97
- type_conflict! klass, top[key] if top.is_a?(Hash) && top.key?(key) && ! top[key].is_a?(klass)
98
- value = bind(key, klass.new)
99
- type_conflict! klass, value unless value.is_a?(klass)
100
- push(value)
101
- end
102
-
103
- # Push a value onto the 'stack', which is actually only the top 2 items.
104
- def push(value)
105
- @parent, @top = @top, value
106
- end
107
-
108
- # Bind a key (which may be nil for items in an array) to the provided value.
109
- def bind(key, value)
110
- if top.is_a? Array
111
- if key
112
- if top[-1].is_a?(Hash) && ! top[-1].key?(key)
113
- top[-1][key] = value
114
- else
115
- top << {key => value}.with_indifferent_access
116
- push top.last
117
- value = top[key]
118
- end
119
- else
120
- top << value
121
- end
122
- elsif top.is_a? Hash
123
- #key = CGI.unescape(key)
124
- parent << (@top = {}) if top.key?(key) && parent.is_a?(Array)
125
- top[key] ||= value
126
- return top[key]
127
- else
128
- raise ArgumentError, "Don't know what to do: top is #{top.inspect}"
129
- end
130
-
131
- return value
132
- end
133
-
134
- def type_conflict!(klass, value)
135
- raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value. (The parameters received were #{value.inspect}.)"
136
- end
137
- end
138
- end # RhoSupport
139
- end # Rho
@@ -1,121 +0,0 @@
1
- module Rho
2
- class RhoController
3
-
4
- def truncate(text,length)
5
- if text
6
- omission = '...'
7
- l = length - omission.length
8
- (text.length > length ? text[0...l] + omission : text).to_s
9
- end
10
- end
11
-
12
- def click_to_call(phone,description=nil)
13
- description = phone if description.nil?
14
- return "" if phone.nil? or phone.length == 0
15
- "<a href=\"tel:#{phone}\" target=\"_self\">#{description}</a>"
16
- end
17
-
18
- def mailto(address,description=nil)
19
- description = address if description.nil?
20
- return "" if address.nil? or address.length == 0
21
- "<a href=\"mailto:#{address}\" target=\"_self\">#{description}</a>"
22
- end
23
-
24
- # Examples of how to use link_to method:
25
- #
26
- # link_to "Visit Other Site", "http://www.rhomobile.com/"
27
- # ==> <a href=\"http://www.rhomobile.com/\" >Visit Other Site</a>
28
- #
29
- # link_to "Help", { :action => "help" }
30
- # ==> <a href=\"/application/model/help\" >Help</a>
31
- #
32
- # link_to "Delete", { :action => "delete", :id => '{12}' }
33
- # ==> <a href="/application/model/{12}/delete" onclick="var f = document.createElement('form');
34
- # f.style.display = 'none';this.parentNode.appendChild(f); f.method = 'POST';
35
- # f.action = this.href;f.submit();return false;">Delete</a>
36
- #
37
- # link_to "Show", { :action => "show", :id => '{12}'},"style=\"height:4px;width:7px;border-width:0px;\""
38
- # ==> <a href="/application/model/{12}/show" style="height:4px;width:7px;border-width:0px;">Show</a>
39
- #
40
- # link_to "Delete", { :action => "delete", :id => '{12}' }, "class=\"delete_link\""
41
- # ==> <a href="/application/model/{12}/delete" class="delete_link" onclick="var f = document.createElement('form');
42
- # f.style.display = 'none';this.parentNode.appendChild(f); f.method = 'POST';
43
- # f.action = this.href;f.submit();return false;\">Delete</a>"
44
- #
45
- # link_to "Invate",:action => :invite, :query => {:name => 'John Smith', 'address' => "http://john.smith.com"}
46
- # ==> <a href="/application/model/invite?name=John%20Smith&address=http%3A%2F%2Fjohn.smith.com" >Invate</a>
47
- #
48
- def link_to(name,url_params = {},html_options = "",confirm = nil)
49
- url = url_for(url_params)
50
- if (url_params[:action].to_s != 'delete')
51
- "<a href=\"#{url}\" #{html_options}>#{name || url}</a>"
52
- else
53
- "<a href=\"#{url}\" #{html_options} onclick=\""+ #if (confirm('#{confirm}')) {
54
- "var f = document.createElement('form'); f.style.display = 'none';" +
55
- "this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();"+
56
- "return false;\">#{name || url}</a>"
57
- end
58
- end
59
-
60
- # Examples of how to use url_for method:
61
- #
62
- # url_for '/some_url'
63
- # ==> /some_url
64
- #
65
- # When generating a new URL, missing values may be filled in from the current request's parameters.
66
- # For example, if application name or model are not specifyed in the call parameters, they would be filled from the request.
67
- #
68
- # url_for :action => :index
69
- # ==> /application/model
70
- #
71
- # url_for :action => :create
72
- # ==> /application/model
73
- #
74
- # url_for :action => :new
75
- # ==> /application/model/new
76
- #
77
- # url_for :action => :show, :id => '{12}'
78
- # ==> /application/model/{12}/show
79
- #
80
- # url_for :model => :another_model, :action => :show, :id => '{12}'
81
- # ==> /application/another_model/{12}/show
82
- #
83
- # url_for :application => :another_app, :model => :another_model, :action => :show, :id => '{12}'
84
- # ==> /another_app/another_model/{12}/show
85
- #
86
- # url_for :action => :create, :query => {:name => 'John Smith', 'address' => "http://john.smith.com"}
87
- # ==> /application/model?name=John%20Smith&address=http%3A%2F%2Fjohn.smith.com
88
- #
89
- # url_for :action => :show, :id => '{12}', :fragment => "an-anchor"
90
- # ==> /application/model/{12}/show#an-anchor
91
- #
92
- def url_for(params = {})
93
- return params.to_s if params.is_a? String or params.is_a? Symbol
94
- return '/' if not params.is_a? Hash or params.nil?
95
-
96
- application = params[:application] || @request['application']
97
- model = params[:model] || @request['model']
98
- action = params[:action].nil? ? nil : params[:action].to_s
99
- id = params[:id].nil? ? nil : params[:id].to_s
100
- query = query_to_s(params[:query])
101
- fragment = params[:fragment].nil? ? '' : '#' + params[:fragment]
102
-
103
- amurl = '/' + application.to_s + '/' + model.to_s
104
-
105
- return amurl + query + fragment if action.nil? or action == 'create' or action == 'index'
106
- return amurl +'/'+ (id.nil? ? action : id + '/' + action) + query + fragment
107
- end
108
-
109
- private
110
- def query_to_s(query)
111
- return '' if query.nil?
112
- qstring = '?'
113
- query.each do |key,value|
114
- qstring += '&' if qstring.length > 1
115
- qstring += ERB::Util.url_encode(key.to_s) + '=' + ERB::Util.url_encode(value.to_s)
116
- end
117
- qstring
118
- end
119
-
120
- end # RhoController
121
- end # Rho
@@ -1,38 +0,0 @@
1
- begin
2
- require 'rational'
3
- require 'date/format'
4
- require 'time'
5
-
6
- require 'sqlite3/constants'
7
- require 'sqlite3/errors'
8
- require 'sqlite3/pragmas'
9
-
10
- require 'sqlite3/resultset'
11
- require 'sqlite3/statement'
12
-
13
- require 'date'
14
- require 'sqlite3/translator'
15
-
16
- require 'sqlite3/value'
17
-
18
- require 'sqlite3/database'
19
- require 'rhom/rhom_db_adapter'
20
-
21
- require 'rhom/rhom_object'
22
- require 'rhofsconnector'
23
-
24
- require 'rhom/rhom_object_factory'
25
-
26
- require 'rhom/rhom'
27
- require 'rhom'
28
-
29
- require 'rho/rhoapplication'
30
-
31
- require 'rho/rho'
32
- require 'rho'
33
-
34
- puts 'RHO loaded'
35
- Rho::RHO.new
36
- rescue Exception => e
37
- puts e.message
38
- end
@@ -1 +0,0 @@
1
- require 'rho/rhofsconnector.rb'
@@ -1 +0,0 @@
1
- require 'rhom/rhom'
@@ -1,58 +0,0 @@
1
- #
2
- # rhom.rb
3
- # rhodes
4
- # This module represents the rhodes mini OM
5
- #
6
- # Copyright (C) 2008 Lars Burgess. All rights reserved.
7
- #
8
- # This program is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
- #
21
-
22
- require 'rhom/rhom_object_factory'
23
- require 'rhom/rhom_object'
24
- if defined? RHO_ME
25
- require 'rhom/rhom_db_adapterME'
26
- else
27
- require 'rhom/rhom_db_adapter'
28
- end
29
-
30
- module Rhom
31
- TABLE_NAME = 'object_values'
32
-
33
- class Rhom
34
- include RhomObject
35
- attr_accessor :factory
36
-
37
- def initialize
38
- @factory = RhomObjectFactory.new
39
- end
40
-
41
- class << Rhom
42
- def client_id
43
- c_id = ::Rhom::RhomDbAdapter::select_from_table('client_info','client_id')[0]
44
- c_id.nil? ? nil : c_id['client_id']
45
- end
46
-
47
- def database_full_reset
48
- ::Rhom::RhomDbAdapter::delete_all_from_table(TABLE_NAME)
49
- ::Rhom::RhomDbAdapter::delete_all_from_table('client_info')
50
- end
51
-
52
- def database_full_reset_and_logout
53
- database_full_reset
54
- SyncEngine::logout
55
- end
56
- end #class methods
57
- end # Rhom
58
- end # Rhom
@@ -1,185 +0,0 @@
1
- #
2
- # rhom_db_adapter.rb
3
- # rhodes
4
- #
5
- # Copyright (C) 2008 Lars Burgess. All rights reserved.
6
- #
7
- # This program is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
- #
20
- $:.unshift(File.join(File.dirname(__FILE__), '../../'))
21
- require 'sqlite3/database'
22
-
23
- module Rhom
24
- class RhomDbAdapter
25
-
26
- @@database = nil
27
-
28
- class << self
29
-
30
- # maintains a single database connection
31
- def open(dbfile=nil)
32
- puts "DB name = " + dbfile.inspect
33
- unless @@database or dbfile.nil?
34
- @@database = SQLite3::Database.new(dbfile)
35
- end
36
- end
37
-
38
- # closes the database if and only if it is open
39
- def close
40
- if @@database and not @@database.closed?
41
- @@database.close
42
- @@database = nil
43
- else
44
- return false
45
- end
46
- return true
47
- end
48
-
49
- # execute a sql statement
50
- # optionally, disable the factory processing
51
- # which returns the result array directly
52
- def execute_sql(sql=nil)
53
- result = []
54
- if sql
55
- #puts 'query is ' + sql
56
- # Make sure we lock the sync engine's mutex
57
- # before we perform a database transaction.
58
- # This prevents concurrency issues.
59
- begin
60
- SyncEngine::lock_sync_mutex
61
- # execute sql statement inside of transaction
62
- # result is returned as an array of hashes
63
- @@database.transaction unless @@database.transaction_active?
64
- @@database.results_as_hash = true
65
- result = @@database.execute sql
66
- @@database.commit
67
- SyncEngine::unlock_sync_mutex
68
- rescue Exception => e
69
- puts "exception when running query: #{e}"
70
- # make sure we unlock even if there's an error!
71
- SyncEngine::unlock_sync_mutex
72
- end
73
- end
74
- #puts "returned #{result.length.to_s} records..."
75
- result
76
- end
77
-
78
- # generates where clause based on hash
79
- def where_str(condition)
80
- cond = string_from_key_vals(condition," and")
81
- cond[0..cond.length - 5]
82
- end
83
-
84
- # generates value clause based on hash
85
- def vals_str(values)
86
- vals = string_from_key_vals(values, ",")
87
- vals[0..vals.length - 2]
88
- end
89
-
90
- # generates key/value list
91
- def string_from_key_vals(values, delim)
92
- vals = ""
93
- values.each do |key,value|
94
- val = value.is_a?(String) ? "'#{value}'" : "#{value}"
95
- vals << " #{key} = #{val}#{delim}"
96
- end
97
- vals
98
- end
99
-
100
- # support for select statements
101
- # this function takes table name, columns (as a comma-separated list),
102
- # condition (as a hash), and params (as a hash)
103
- # example usage is the following:
104
- # select_from_table('object_values', '*', {"source_id"=>2,"update_type"=>'query'},
105
- # {"order by"=>'object'})
106
- # this would return all columns where source_id = 2 and update_type = 'query' ordered
107
- # by the "object" column
108
- def select_from_table(table=nil,columns=nil,condition=nil,params=nil)
109
- query = nil
110
- if table and columns and condition
111
- if params and params['distinct']
112
- query = "select distinct #{columns} from #{table} where #{where_str(condition)}"
113
- elsif params and params['order by']
114
- query = "select #{columns} from #{table} where #{where_str(condition)} \
115
- order by #{params['order by']}"
116
- else
117
- query = "select #{columns} from #{table} where #{where_str(condition)}"
118
- end
119
- elsif table and columns
120
- query = "select #{columns} from #{table}"
121
- end
122
- execute_sql query
123
- end
124
-
125
- # inserts a single row into the database
126
- # takes the table name and values (hash) as arguments
127
- # exmaple usage is the following:
128
- # insert_into_table('object_values, {"source_id"=>1,"object"=>"some-object","update_type"=>'delete'})
129
- # this would execute the following sql:
130
- # insert into object_values (source_id,object,update_type) values (1,'some-object','delete');
131
- def insert_into_table(table=nil,values=nil)
132
- query = nil
133
- cols = ""
134
- vals = ""
135
- if table and values
136
- values.each do |key,val|
137
- value = val.is_a?(Fixnum) ? "#{val}," : "'#{val}',"
138
- cols << "#{key},"
139
- vals << value
140
- end
141
- cols = cols[0..cols.length - 2]
142
- vals = vals[0..vals.length - 2]
143
- query = "insert into #{table} (#{cols}) values (#{vals})"
144
- end
145
- execute_sql query
146
- end
147
-
148
- # deletes rows from a table which satisfy condition (hash)
149
- # example usage is the following:
150
- # delete_from_table('object_values',{"object"=>"some-object"})
151
- # this would execute the following sql:
152
- # delete from object_values where object="some-object"
153
- def delete_from_table(table=nil,condition=nil)
154
- query = nil
155
- if table and condition
156
- query = "delete from #{table} where #{where_str(condition)}"
157
- end
158
- execute_sql query
159
- end
160
-
161
- # deletes all rows from a given table
162
- def delete_all_from_table(table=nil)
163
- query = nil
164
- if table
165
- query = "delete from #{table}"
166
- end
167
- execute_sql query
168
- end
169
-
170
- # updates values (hash) in a given table which satisfy condition (hash)
171
- # example usage is the following:
172
- # update_into_table('object_values',{"value"=>"Electronics"},{"object"=>"some-object", "attrib"=>"industry"})
173
- # this executes the following sql:
174
- # update table object_values set value='Electronics' where object='some-object' and attrib='industry';
175
- def update_into_table(table=nil,values=nil,condition=nil)
176
- query = nil
177
- vals = values.nil? ? nil : vals_str(values)
178
- if table and condition and vals
179
- query = "update #{table} set #{vals} where #{where_str(condition)}"
180
- end
181
- execute_sql query
182
- end
183
- end # class methods
184
- end # RhomDbAdapter
185
- end # Rhom