hobo 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/bin/hobo +21 -22
  2. data/hobo_files/plugin/CHANGES.txt +429 -4
  3. data/hobo_files/plugin/Rakefile +2 -2
  4. data/hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml +6 -5
  5. data/hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml +2 -2
  6. data/hobo_files/plugin/generators/hobo_migration/hobo_migration_generator.rb +20 -15
  7. data/hobo_files/plugin/generators/hobo_model/templates/model.rb +1 -0
  8. data/hobo_files/plugin/generators/hobo_model_controller/templates/controller.rb +2 -0
  9. data/hobo_files/plugin/generators/hobo_rapid/templates/hobo_base.css +1 -2
  10. data/hobo_files/plugin/generators/hobo_rapid/templates/hobo_rapid.css +4 -3
  11. data/hobo_files/plugin/generators/hobo_rapid/templates/hobo_rapid.js +94 -12
  12. data/hobo_files/plugin/generators/hobo_rapid/templates/lowpro.js +5 -183
  13. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css +1 -1
  14. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml +23 -1
  15. data/hobo_files/plugin/generators/hobo_user_controller/templates/controller.rb +2 -0
  16. data/hobo_files/plugin/generators/hobo_user_model/templates/model.rb +3 -1
  17. data/hobo_files/plugin/init.rb +18 -7
  18. data/hobo_files/plugin/lib/active_record/has_many_association.rb +2 -2
  19. data/hobo_files/plugin/lib/extensions.rb +56 -12
  20. data/hobo_files/plugin/lib/hobo.rb +25 -88
  21. data/hobo_files/plugin/lib/hobo/composite_model.rb +2 -0
  22. data/hobo_files/plugin/lib/hobo/controller.rb +40 -20
  23. data/hobo_files/plugin/lib/hobo/dryml.rb +122 -106
  24. data/hobo_files/plugin/lib/hobo/dryml/dryml_builder.rb +2 -1
  25. data/hobo_files/plugin/lib/hobo/dryml/part_context.rb +3 -2
  26. data/hobo_files/plugin/lib/hobo/dryml/taglib.rb +19 -3
  27. data/hobo_files/plugin/lib/hobo/dryml/template.rb +40 -25
  28. data/hobo_files/plugin/lib/hobo/dryml/template_environment.rb +41 -20
  29. data/hobo_files/plugin/lib/hobo/email_address.rb +4 -1
  30. data/hobo_files/plugin/lib/hobo/enum_string.rb +50 -0
  31. data/hobo_files/plugin/lib/hobo/field_declaration_dsl.rb +36 -0
  32. data/hobo_files/plugin/lib/hobo/field_spec.rb +4 -7
  33. data/hobo_files/plugin/lib/hobo/hobo_helper.rb +47 -44
  34. data/hobo_files/plugin/lib/hobo/html_string.rb +2 -0
  35. data/hobo_files/plugin/lib/hobo/markdown_string.rb +2 -0
  36. data/hobo_files/plugin/lib/hobo/model.rb +158 -89
  37. data/hobo_files/plugin/lib/hobo/model_controller.rb +422 -376
  38. data/hobo_files/plugin/lib/hobo/model_queries.rb +1 -1
  39. data/hobo_files/plugin/lib/hobo/model_router.rb +174 -0
  40. data/hobo_files/plugin/lib/hobo/password_string.rb +2 -0
  41. data/hobo_files/plugin/lib/hobo/percentage.rb +14 -0
  42. data/hobo_files/plugin/lib/hobo/plugins.rb +4 -4
  43. data/hobo_files/plugin/lib/hobo/rapid_helper.rb +10 -2
  44. data/hobo_files/plugin/lib/hobo/text.rb +3 -3
  45. data/hobo_files/plugin/lib/hobo/textile_string.rb +2 -0
  46. data/hobo_files/plugin/lib/hobo/undefined.rb +3 -2
  47. data/hobo_files/plugin/lib/hobo/{authenticated_user.rb → user.rb} +10 -3
  48. data/hobo_files/plugin/lib/hobo/user_controller.rb +27 -23
  49. data/hobo_files/plugin/tags/core.dryml +8 -2
  50. data/hobo_files/plugin/tags/rapid.dryml +52 -40
  51. data/hobo_files/plugin/tags/rapid_document_tags.dryml +15 -11
  52. data/hobo_files/plugin/tags/rapid_editing.dryml +41 -9
  53. data/hobo_files/plugin/tags/rapid_forms.dryml +136 -36
  54. data/hobo_files/plugin/tags/rapid_navigation.dryml +2 -2
  55. data/hobo_files/plugin/tags/rapid_pages.dryml +204 -221
  56. data/hobo_files/plugin/tags/rapid_plus.dryml +8 -6
  57. data/hobo_files/plugin/tags/rapid_support.dryml +2 -3
  58. metadata +44 -42
  59. data/hobo_files/plugin/lib/hobo/define_tags.rb +0 -56
  60. data/hobo_files/plugin/lib/hobo/http_parameters.rb +0 -225
@@ -5,13 +5,14 @@
5
5
  <div class="search">
6
6
  <form param="search_form" method="get" action="">
7
7
  <hidden_fields for_query_string skip="page, search_form"/>
8
- Search <input class="search_field" type="text" name="search" value="&params[:search]"/>
8
+ Search
9
+ <input class="search_field" type="search" name="search" value="&params[:search]"/>
10
+ <submit label="Go" class="search_button" param="search_submit"/>
9
11
  </form>
10
12
  </div>
11
13
  </div>
12
14
 
13
- <Table merge_attrs="&attributes & (attrs_for(:Table) + attrs_for(:with_fields))"
14
- merge_params>
15
+ <Table merge_attrs="&attributes & (attrs_for(:Table) + attrs_for(:with_fields))" merge_params>
15
16
  <field_heading_row>
16
17
  <with_field_names merge_attrs="&all_attributes & attrs_for(:with_fields)">
17
18
  <% col = sort_columns[scope.field_path] || scope.field_path
@@ -19,8 +20,9 @@
19
20
  "-#{col}" : col
20
21
  sort_url = url_for(params.merge(:sort => sort) - [:page]) %>
21
22
 
22
- <th>
23
- <a href="&sort_url" param="#{scope.field_name}_heading"><%= scope.field_name.titleize %></a>
23
+ <th param="#{scope.field_name}_heading">
24
+ <a href="&sort_url" class="column_sort"
25
+ param="#{scope.field_name}_heading_link"><%= scope.field_name.titleize %></a>
24
26
  <if test="&col == sort_field">
25
27
  <do param="up_arrow" if="&sort_direction == 'desc'">&uarr;</do>
26
28
  <do param="down_arrow" if="&sort_direction == 'asc'">&darr;</do>
@@ -35,7 +37,7 @@
35
37
  </else>
36
38
 
37
39
  <nav class="page">
38
- <page_nav/>
40
+ <page_nav param/>
39
41
  </nav>
40
42
  </div>
41
43
  </def>
@@ -7,7 +7,7 @@
7
7
 
8
8
  if skip_associations == "has_many"
9
9
  assocs = this.class.reflections.values.reject {|r| r.macro == :has_many }.every(:name)
10
- columns - assocs
10
+ columns + assocs
11
11
  elsif skip_associations
12
12
  columns
13
13
  else
@@ -17,7 +17,6 @@
17
17
  else
18
18
  comma_split(fields)
19
19
  end
20
-
21
20
  field_names -= comma_split(skip) if skip
22
21
  field_names = field_names.select {|f| can_view?(this, f)}
23
22
  field_names.each do |field| %><with field="&field"><tagbody/></with><% end
@@ -31,7 +30,7 @@
31
30
 
32
31
  if skip_associations == "has_many"
33
32
  assocs = this.reflections.values.reject {|r| r.macro == :has_many }.every(:name)
34
- columns - assocs
33
+ columns + assocs
35
34
  elsif skip_associations
36
35
  columns
37
36
  else
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: hobo
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.2
7
- date: 2007-09-13 00:00:00 +01:00
6
+ version: 0.6.3
7
+ date: 2007-11-13 00:00:00 +00:00
8
8
  summary: The web app builder for Rails
9
9
  require_paths:
10
10
  - lib
@@ -32,50 +32,40 @@ files:
32
32
  - hobo_files/plugin
33
33
  - hobo_files/plugin/CHANGES.txt
34
34
  - hobo_files/plugin/generators
35
- - hobo_files/plugin/init.rb
36
- - hobo_files/plugin/lib
37
- - hobo_files/plugin/LICENSE.txt
38
- - hobo_files/plugin/Rakefile
39
- - hobo_files/plugin/README
40
- - hobo_files/plugin/tags
41
- - hobo_files/plugin/tasks
42
- - hobo_files/plugin/uninstall.rb
43
35
  - hobo_files/plugin/generators/hobo
44
- - hobo_files/plugin/generators/hobo_front_controller
45
- - hobo_files/plugin/generators/hobo_migration
46
- - hobo_files/plugin/generators/hobo_model
47
- - hobo_files/plugin/generators/hobo_model_controller
48
- - hobo_files/plugin/generators/hobo_rapid
49
- - hobo_files/plugin/generators/hobo_user_controller
50
- - hobo_files/plugin/generators/hobo_user_model
51
36
  - hobo_files/plugin/generators/hobo/hobo_generator.rb
52
37
  - hobo_files/plugin/generators/hobo/templates
53
38
  - hobo_files/plugin/generators/hobo/templates/application.dryml
54
39
  - hobo_files/plugin/generators/hobo/templates/guest.rb
40
+ - hobo_files/plugin/generators/hobo_front_controller
55
41
  - hobo_files/plugin/generators/hobo_front_controller/hobo_front_controller_generator.rb
56
42
  - hobo_files/plugin/generators/hobo_front_controller/templates
57
- - hobo_files/plugin/generators/hobo_front_controller/USAGE
58
43
  - hobo_files/plugin/generators/hobo_front_controller/templates/controller.rb
59
44
  - hobo_files/plugin/generators/hobo_front_controller/templates/functional_test.rb
60
45
  - hobo_files/plugin/generators/hobo_front_controller/templates/helper.rb
61
46
  - hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml
62
47
  - hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml
48
+ - hobo_files/plugin/generators/hobo_front_controller/USAGE
49
+ - hobo_files/plugin/generators/hobo_migration
63
50
  - hobo_files/plugin/generators/hobo_migration/hobo_migration_generator.rb
64
51
  - hobo_files/plugin/generators/hobo_migration/templates
65
52
  - hobo_files/plugin/generators/hobo_migration/templates/migration.rb
53
+ - hobo_files/plugin/generators/hobo_model
66
54
  - hobo_files/plugin/generators/hobo_model/hobo_model_generator.rb
67
55
  - hobo_files/plugin/generators/hobo_model/templates
68
- - hobo_files/plugin/generators/hobo_model/USAGE
69
56
  - hobo_files/plugin/generators/hobo_model/templates/fixtures.yml
70
57
  - hobo_files/plugin/generators/hobo_model/templates/model.rb
71
58
  - hobo_files/plugin/generators/hobo_model/templates/unit_test.rb
59
+ - hobo_files/plugin/generators/hobo_model/USAGE
60
+ - hobo_files/plugin/generators/hobo_model_controller
72
61
  - hobo_files/plugin/generators/hobo_model_controller/hobo_model_controller_generator.rb
73
62
  - hobo_files/plugin/generators/hobo_model_controller/templates
74
- - hobo_files/plugin/generators/hobo_model_controller/USAGE
75
63
  - hobo_files/plugin/generators/hobo_model_controller/templates/controller.rb
76
64
  - hobo_files/plugin/generators/hobo_model_controller/templates/functional_test.rb
77
65
  - hobo_files/plugin/generators/hobo_model_controller/templates/helper.rb
78
66
  - hobo_files/plugin/generators/hobo_model_controller/templates/view.rhtml
67
+ - hobo_files/plugin/generators/hobo_model_controller/USAGE
68
+ - hobo_files/plugin/generators/hobo_rapid
79
69
  - hobo_files/plugin/generators/hobo_rapid/hobo_rapid_generator.rb
80
70
  - hobo_files/plugin/generators/hobo_rapid/templates
81
71
  - hobo_files/plugin/generators/hobo_rapid/templates/hobo_base.css
@@ -85,9 +75,7 @@ files:
85
75
  - hobo_files/plugin/generators/hobo_rapid/templates/themes
86
76
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default
87
77
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public
88
- - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views
89
78
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images
90
- - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets
91
79
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/banner.gif
92
80
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_bodytop.gif
93
81
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_corner_01.gif
@@ -118,55 +106,68 @@ files:
118
106
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_left.gif
119
107
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_right.gif
120
108
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_top.gif
109
+ - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets
121
110
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css
111
+ - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views
122
112
  - hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml
113
+ - hobo_files/plugin/generators/hobo_user_controller
123
114
  - hobo_files/plugin/generators/hobo_user_controller/hobo_user_controller_generator.rb
124
115
  - hobo_files/plugin/generators/hobo_user_controller/templates
125
- - hobo_files/plugin/generators/hobo_user_controller/USAGE
126
116
  - hobo_files/plugin/generators/hobo_user_controller/templates/controller.rb
127
117
  - hobo_files/plugin/generators/hobo_user_controller/templates/functional_test.rb
128
118
  - hobo_files/plugin/generators/hobo_user_controller/templates/helper.rb
129
119
  - hobo_files/plugin/generators/hobo_user_controller/templates/view.rhtml
120
+ - hobo_files/plugin/generators/hobo_user_controller/USAGE
121
+ - hobo_files/plugin/generators/hobo_user_model
130
122
  - hobo_files/plugin/generators/hobo_user_model/hobo_user_model_generator.rb
131
123
  - hobo_files/plugin/generators/hobo_user_model/templates
132
- - hobo_files/plugin/generators/hobo_user_model/USAGE
133
124
  - hobo_files/plugin/generators/hobo_user_model/templates/fixtures.yml
134
125
  - hobo_files/plugin/generators/hobo_user_model/templates/model.rb
135
126
  - hobo_files/plugin/generators/hobo_user_model/templates/unit_test.rb
127
+ - hobo_files/plugin/generators/hobo_user_model/USAGE
128
+ - hobo_files/plugin/init.rb
129
+ - hobo_files/plugin/lib
136
130
  - hobo_files/plugin/lib/action_view_extensions
137
- - hobo_files/plugin/lib/active_record
138
- - hobo_files/plugin/lib/extensions
139
- - hobo_files/plugin/lib/extensions.rb
140
- - hobo_files/plugin/lib/hobo
141
- - hobo_files/plugin/lib/hobo.rb
142
- - hobo_files/plugin/lib/rexml.rb
143
131
  - hobo_files/plugin/lib/action_view_extensions/base.rb
132
+ - hobo_files/plugin/lib/active_record
144
133
  - hobo_files/plugin/lib/active_record/has_many_association.rb
145
134
  - hobo_files/plugin/lib/active_record/has_many_through_association.rb
146
135
  - hobo_files/plugin/lib/active_record/table_definition.rb
136
+ - hobo_files/plugin/lib/extensions
147
137
  - hobo_files/plugin/lib/extensions/test_case.rb
148
- - hobo_files/plugin/lib/hobo/authenticated_user.rb
138
+ - hobo_files/plugin/lib/extensions.rb
139
+ - hobo_files/plugin/lib/hobo
149
140
  - hobo_files/plugin/lib/hobo/authentication_support.rb
150
141
  - hobo_files/plugin/lib/hobo/composite_model.rb
151
142
  - hobo_files/plugin/lib/hobo/controller.rb
152
- - hobo_files/plugin/lib/hobo/define_tags.rb
153
143
  - hobo_files/plugin/lib/hobo/dryml
144
+ - hobo_files/plugin/lib/hobo/dryml/dryml_builder.rb
145
+ - hobo_files/plugin/lib/hobo/dryml/part_context.rb
146
+ - hobo_files/plugin/lib/hobo/dryml/scoped_variables.rb
147
+ - hobo_files/plugin/lib/hobo/dryml/tag_module.rb
148
+ - hobo_files/plugin/lib/hobo/dryml/taglib.rb
149
+ - hobo_files/plugin/lib/hobo/dryml/template.rb
150
+ - hobo_files/plugin/lib/hobo/dryml/template_environment.rb
151
+ - hobo_files/plugin/lib/hobo/dryml/template_handler.rb
154
152
  - hobo_files/plugin/lib/hobo/dryml.rb
155
153
  - hobo_files/plugin/lib/hobo/email_address.rb
154
+ - hobo_files/plugin/lib/hobo/enum_string.rb
155
+ - hobo_files/plugin/lib/hobo/field_declaration_dsl.rb
156
156
  - hobo_files/plugin/lib/hobo/field_spec.rb
157
157
  - hobo_files/plugin/lib/hobo/generator.rb
158
158
  - hobo_files/plugin/lib/hobo/guest.rb
159
159
  - hobo_files/plugin/lib/hobo/hobo_helper.rb
160
160
  - hobo_files/plugin/lib/hobo/html_string.rb
161
- - hobo_files/plugin/lib/hobo/http_parameters.rb
162
161
  - hobo_files/plugin/lib/hobo/lazy_hash.rb
163
162
  - hobo_files/plugin/lib/hobo/markdown_string.rb
164
163
  - hobo_files/plugin/lib/hobo/migrations.rb
165
164
  - hobo_files/plugin/lib/hobo/model.rb
166
165
  - hobo_files/plugin/lib/hobo/model_controller.rb
167
166
  - hobo_files/plugin/lib/hobo/model_queries.rb
167
+ - hobo_files/plugin/lib/hobo/model_router.rb
168
168
  - hobo_files/plugin/lib/hobo/model_support.rb
169
169
  - hobo_files/plugin/lib/hobo/password_string.rb
170
+ - hobo_files/plugin/lib/hobo/percentage.rb
170
171
  - hobo_files/plugin/lib/hobo/plugins.rb
171
172
  - hobo_files/plugin/lib/hobo/predicate_dispatch.rb
172
173
  - hobo_files/plugin/lib/hobo/proc_binding.rb
@@ -176,16 +177,15 @@ files:
176
177
  - hobo_files/plugin/lib/hobo/textile_string.rb
177
178
  - hobo_files/plugin/lib/hobo/undefined.rb
178
179
  - hobo_files/plugin/lib/hobo/undefined_access_error.rb
180
+ - hobo_files/plugin/lib/hobo/user.rb
179
181
  - hobo_files/plugin/lib/hobo/user_controller.rb
180
182
  - hobo_files/plugin/lib/hobo/where_fragment.rb
181
- - hobo_files/plugin/lib/hobo/dryml/dryml_builder.rb
182
- - hobo_files/plugin/lib/hobo/dryml/part_context.rb
183
- - hobo_files/plugin/lib/hobo/dryml/scoped_variables.rb
184
- - hobo_files/plugin/lib/hobo/dryml/tag_module.rb
185
- - hobo_files/plugin/lib/hobo/dryml/taglib.rb
186
- - hobo_files/plugin/lib/hobo/dryml/template.rb
187
- - hobo_files/plugin/lib/hobo/dryml/template_environment.rb
188
- - hobo_files/plugin/lib/hobo/dryml/template_handler.rb
183
+ - hobo_files/plugin/lib/hobo.rb
184
+ - hobo_files/plugin/lib/rexml.rb
185
+ - hobo_files/plugin/LICENSE.txt
186
+ - hobo_files/plugin/Rakefile
187
+ - hobo_files/plugin/README
188
+ - hobo_files/plugin/tags
189
189
  - hobo_files/plugin/tags/core.dryml
190
190
  - hobo_files/plugin/tags/rapid.dryml
191
191
  - hobo_files/plugin/tags/rapid_document_tags.dryml
@@ -195,9 +195,11 @@ files:
195
195
  - hobo_files/plugin/tags/rapid_pages.dryml
196
196
  - hobo_files/plugin/tags/rapid_plus.dryml
197
197
  - hobo_files/plugin/tags/rapid_support.dryml
198
+ - hobo_files/plugin/tasks
198
199
  - hobo_files/plugin/tasks/dump_fixtures.rake
199
200
  - hobo_files/plugin/tasks/environments.rake
200
201
  - hobo_files/plugin/tasks/hobo_tasks.rake
202
+ - hobo_files/plugin/uninstall.rb
201
203
  - bin/hobo
202
204
  - LICENSE.txt
203
205
  - README.txt
@@ -1,56 +0,0 @@
1
- module Hobo
2
-
3
- module DefineTags
4
-
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- base.extend(PredicateDispatch::ClassMethods)
8
- end
9
-
10
- module ClassMethods
11
-
12
- attr_reader :hobo_tag_blocks
13
-
14
-
15
- def def_tag(name, *attrs_and_pred, &tagdef_block)
16
- pred, attrs = if attrs_and_pred.first.is_a? Proc
17
- [attrs_and_pred.first, attrs_and_pred[1..-1]]
18
- else
19
- [nil, attrs_and_pred]
20
- end
21
-
22
- name = name.to_s
23
- @hobo_tag_blocks ||= HashWithIndifferentAccess.new
24
- @hobo_tag_blocks[name] = tagdef_block
25
- @hobo_tag_blocks["#{name}_predicate"] = pred if pred
26
-
27
- safe_name = Dryml.unreserve(name)
28
- locals = attrs.map{|a| Hobo::Dryml.unreserve(a)} + %w{options inner_tag_options}
29
-
30
- def_line = if pred
31
- "defp :#{safe_name}, @hobo_tag_blocks['#{name}_predicate'] do |options, block|"
32
- elsif predicate_method?(safe_name)
33
- # be sure not to overwrite the predicate dispatch method
34
- "defp :#{safe_name} do |options, block|"
35
- else
36
- "def #{safe_name}(options={}, &block)"
37
- end
38
-
39
- class_eval(<<-END, __FILE__, __LINE__+1)
40
- #{def_line}
41
- _tag_context(options, block) do |tagbody|
42
- locals = _tag_locals(options, #{attrs.inspect})
43
- locals_hash = { :tagbody => tagbody };
44
- #{locals.inspect}.each_with_index{|a, i| locals_hash[a] = locals[i]}
45
- Hobo::ProcBinding.new(self, locals_hash).instance_eval(&#{self.name}.hobo_tag_blocks['#{name}'])
46
- end
47
- end
48
- END
49
-
50
- end
51
-
52
- end
53
-
54
- end
55
-
56
- end
@@ -1,225 +0,0 @@
1
- module Hobo
2
-
3
- module HttpParameters
4
-
5
- class PermissionDeniedError < RuntimeError; end
6
- class InvalidError < RuntimeError; end
7
-
8
- def initialize_record(record, params)
9
- update_without_tracking(record, params)
10
- record.set_creator(current_user)
11
- (@to_create ||= []) << record
12
- record
13
- end
14
-
15
-
16
- def update_record(record, params)
17
- return if params.blank?
18
-
19
- original = record.duplicate
20
- # 'duplicate' can set these, but they can
21
- # conflict with the changes so we clear them
22
- @this.send(:clear_aggregation_cache)
23
- @this.send(:clear_association_cache)
24
-
25
- (@to_update ||= []) << [original, record]
26
-
27
- update_without_tracking(record, params)
28
- end
29
-
30
-
31
- def update_without_tracking(record, params)
32
- params && params.each_pair do |field_name, value|
33
- field = if (create = field_name =~ /^\+/)
34
- field_name[1..-1].to_sym
35
- else
36
- field_name.to_sym
37
- end
38
- refl = record.class.reflections[field]
39
-
40
- if refl._?.macro == :belongs_to
41
- if create
42
- new_for_belongs_to(record, refl, value)
43
- else
44
- update_belongs_to(record, refl, value)
45
- end
46
-
47
- elsif Hobo.simple_has_many_association?(refl)
48
- raise HoboError, "invalid HTTP parameter #{field_name}" if create
49
- update_has_many(record, refl, value)
50
-
51
- else
52
- raise HoboError, "invalid HTTP parameter #{field_name}" if create
53
- update_primitive(record, field, value)
54
-
55
- end
56
- end
57
- end
58
-
59
-
60
- def new_for_belongs_to(record, refl, fields)
61
- # person[+home][address]=blah Create new home and set address (PUT POST)
62
-
63
- target = refl.klass.new
64
- initialize_record(target, fields)
65
- record.send("#{refl.name}=", target)
66
- end
67
-
68
-
69
- def update_belongs_to(record, refl, value)
70
- if value.is_a? String
71
- # Update belongs_to to reference some existing record
72
-
73
- target = if value.starts_with?('@')
74
- # person[home]=@home_12 Reference different existing home (PUT POST)
75
-
76
- Hobo.object_from_dom_id(value[1..-1])
77
- elsif refl.klass.id_name?
78
- # product[category]=garden Reference existing category with id or name (PUT POST)
79
-
80
- refl.klass.find_by_id_name(value)
81
- else
82
- raise HoboError, "invalid HTTP parameter" if create
83
- end
84
- record.send("#{refl.name}=", target)
85
-
86
- else
87
- # Update state of current belongs_to target
88
- # person[home][address]=blah Update existing home.address (PUT)
89
- raise HoboError, "invalid HTTP parameter" unless params[:action] == "update"
90
-
91
- target = record.send(refl.name)
92
- raise HoboError, "invalid HTTP parameter" if target.nil?
93
- update_record(target, value)
94
- end
95
- end
96
-
97
-
98
- def update_has_many(record, refl, items)
99
- new_items, changed_items = items.partition_hash {|k,v| k =~ /^\+/}
100
-
101
- new_items.keys.sort_by{|k|k.to_i}.each do |k|
102
- # home[people][+1][name]=blah Create new Person with fkey refing to this home and set name (PUT POST)
103
- fields = new_items[k]
104
- new_for_has_many(record, refl, fields)
105
- end
106
-
107
- changed_items.each_pair do |id, value|
108
- # Change to existing record - only valid on PUTs
109
- raise HoboError, "invalid HTTP parameter" unless params[:action] == "update"
110
-
111
- target = id =~ /_/ ? Hobo.object_from_dom_id(id) : refl.klass.find(id)
112
- # Ensure the target is actually in this has_many
113
- raise HoboError, "invalid http parameter" unless target.send(refl.primary_key_name) == record.id
114
-
115
- if value.is_a?(String) && value.downcase == "delete"
116
- # home[people][45]=delete Delete Person[45] (PUT)
117
- delete_record(target)
118
-
119
- else
120
- # home[people][45][name]=blah Update Person[45].name (PUT)
121
- raise HoboError, "invalid http parameter" unless value.is_a?(Hash) # field/value pairs
122
- update_record(target, value)
123
-
124
- end
125
- end
126
- end
127
-
128
-
129
- def new_for_has_many(record, refl, value)
130
- # home[people][+1][name]=blah Create new Person with fkey refing to this home and set name (PUT POST)
131
-
132
- new_record = record.send(refl.name).new
133
- initialize_record(new_record, value)
134
- record.send("#{refl.name}").target << new_record
135
- end
136
-
137
-
138
- def delete_record(record)
139
- raise HoboError, "invalid HTTP parameter" unless params[:action] == "update"
140
- (@to_delete ||= []) << record
141
- end
142
-
143
-
144
- def update_primitive(record, field, value)
145
- # person[name]=fred (POST PUT)
146
- field_type = record.class.field_type(field)
147
- record.send("#{field}=", param_to_value(field_type, value))
148
- end
149
-
150
-
151
- def parse_datetime(s)
152
- defined?(Chronic) ? Chronic.parse(s) : Time.parse(s)
153
- end
154
-
155
-
156
- def param_to_value(field_type, value)
157
- if field_type.nil?
158
- value
159
- elsif field_type <= Date
160
- if value.is_a? Hash
161
- Date.new(*(%w{year month day}.map{|s| value[s].to_i}))
162
- elsif value.is_a? String
163
- dt = parse_datetime(value)
164
- dt && dt.to_date
165
- end
166
- elsif field_type <= Time
167
- if value.is_a? Hash
168
- Time.local(*(%w{year month day hour minute}.map{|s| value[s].to_i}))
169
- elsif value.is_a? String
170
- parse_datetime(value)
171
- end
172
- elsif field_type <= TrueClass
173
- (value.is_a?(String) && value.strip.downcase.in?(['0', 'false']) || value.blank?) ? false : true
174
- else
175
- # primitive field
176
- value
177
- end
178
- end
179
-
180
-
181
- def check_permissions_and_apply_changes
182
- valid = true
183
- for old, new in @to_update
184
- raise PermissionDeniedError unless Hobo.can_update?(current_user, old, new)
185
- new_valid = new.save
186
- valid &&= new_valid
187
- end if @to_update
188
-
189
- for record in @to_create
190
- raise PermissionDeniedError unless Hobo.can_create?(current_user, record)
191
- # check if it's new because it might have already been saved as a result of the updates
192
- record_valid = record.save if record.new_record?
193
- valid &&= record_valid
194
- end if @to_create
195
-
196
- for record in @to_delete
197
- raise PermissionDeniedError unless Hobo.can_delete?(current_user, record)
198
- record.destroy
199
- end if @to_delete
200
-
201
- valid
202
- ensure
203
- @to_update = @to_create = @to_delete = nil
204
- end
205
-
206
-
207
- def secure_change_transaction
208
- valid = nil
209
- begin
210
- ActiveRecord::Base.transaction do
211
- yield
212
- valid = check_permissions_and_apply_changes
213
- raise InvalidError unless valid
214
- end
215
- rescue PermissionDeniedError
216
- return :not_allowed
217
- rescue InvalidError
218
- return :invalid
219
- end
220
- :valid
221
- end
222
-
223
- end
224
-
225
- end