active_scaffold 3.4.17 → 3.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -1
  3. data/README.md +8 -4
  4. data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
  5. data/app/assets/stylesheets/active_scaffold.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/blue-theme.css +1 -1
  8. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  11. data/lib/active_scaffold.rb +16 -16
  12. data/lib/active_scaffold/actions/common_search.rb +13 -11
  13. data/lib/active_scaffold/actions/core.rb +85 -78
  14. data/lib/active_scaffold/actions/create.rb +29 -28
  15. data/lib/active_scaffold/actions/delete.rb +17 -17
  16. data/lib/active_scaffold/actions/field_search.rb +18 -19
  17. data/lib/active_scaffold/actions/list.rb +30 -22
  18. data/lib/active_scaffold/actions/mark.rb +1 -1
  19. data/lib/active_scaffold/actions/nested.rb +78 -65
  20. data/lib/active_scaffold/actions/search.rb +13 -10
  21. data/lib/active_scaffold/actions/show.rb +10 -6
  22. data/lib/active_scaffold/actions/subform.rb +1 -2
  23. data/lib/active_scaffold/actions/update.rb +39 -31
  24. data/lib/active_scaffold/active_record_permissions.rb +14 -15
  25. data/lib/active_scaffold/attribute_params.rb +42 -43
  26. data/lib/active_scaffold/bridges.rb +22 -12
  27. data/lib/active_scaffold/bridges/ancestry.rb +1 -1
  28. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
  29. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  30. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
  31. data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
  32. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
  33. data/lib/active_scaffold/bridges/cancan.rb +1 -1
  34. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
  35. data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
  36. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
  37. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
  39. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  40. data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
  41. data/lib/active_scaffold/bridges/country_helper.rb +1 -1
  42. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
  43. data/lib/active_scaffold/bridges/date_picker.rb +2 -2
  44. data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
  45. data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
  46. data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
  47. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
  48. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
  49. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
  50. data/lib/active_scaffold/bridges/file_column.rb +5 -5
  51. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
  52. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
  53. data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
  54. data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
  55. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
  56. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
  57. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
  58. data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
  59. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
  60. data/lib/active_scaffold/bridges/paperclip.rb +5 -5
  61. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
  62. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
  63. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
  64. data/lib/active_scaffold/bridges/record_select.rb +1 -1
  65. data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
  66. data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
  67. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
  68. data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
  69. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
  70. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
  71. data/lib/active_scaffold/config/base.rb +9 -10
  72. data/lib/active_scaffold/config/core.rb +24 -29
  73. data/lib/active_scaffold/config/create.rb +0 -1
  74. data/lib/active_scaffold/config/field_search.rb +8 -10
  75. data/lib/active_scaffold/config/form.rb +5 -5
  76. data/lib/active_scaffold/config/list.rb +21 -20
  77. data/lib/active_scaffold/config/mark.rb +3 -3
  78. data/lib/active_scaffold/config/nested.rb +11 -10
  79. data/lib/active_scaffold/config/search.rb +2 -3
  80. data/lib/active_scaffold/config/show.rb +1 -1
  81. data/lib/active_scaffold/config/update.rb +1 -2
  82. data/lib/active_scaffold/configurable.rb +9 -11
  83. data/lib/active_scaffold/constraints.rb +9 -8
  84. data/lib/active_scaffold/core.rb +72 -84
  85. data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
  86. data/lib/active_scaffold/data_structures/action_link.rb +43 -43
  87. data/lib/active_scaffold/data_structures/action_links.rb +17 -15
  88. data/lib/active_scaffold/data_structures/actions.rb +5 -5
  89. data/lib/active_scaffold/data_structures/bridge.rb +6 -3
  90. data/lib/active_scaffold/data_structures/column.rb +110 -89
  91. data/lib/active_scaffold/data_structures/columns.rb +3 -3
  92. data/lib/active_scaffold/data_structures/error_message.rb +4 -6
  93. data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
  94. data/lib/active_scaffold/data_structures/set.rb +7 -8
  95. data/lib/active_scaffold/data_structures/sorting.rb +38 -33
  96. data/lib/active_scaffold/delayed_setup.rb +5 -6
  97. data/lib/active_scaffold/engine.rb +4 -4
  98. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
  99. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  100. data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
  101. data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
  102. data/lib/active_scaffold/extensions/localize.rb +1 -1
  103. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  104. data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
  105. data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
  106. data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
  107. data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
  108. data/lib/active_scaffold/finder.rb +90 -93
  109. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  110. data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
  111. data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
  112. data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
  113. data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
  114. data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
  115. data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
  116. data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
  117. data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
  118. data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
  119. data/lib/active_scaffold/marked_model.rb +10 -10
  120. data/lib/active_scaffold/paginator.rb +30 -34
  121. data/lib/active_scaffold/responds_to_parent.rb +27 -28
  122. data/lib/active_scaffold/tableless.rb +20 -15
  123. data/lib/active_scaffold/version.rb +1 -1
  124. data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
  125. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
  126. data/shoulda_macros/macros.rb +27 -22
  127. data/test/bridges/bridge_test.rb +38 -29
  128. data/test/bridges/date_picker_test.rb +1 -1
  129. data/test/bridges/paper_trail_test.rb +17 -0
  130. data/test/bridges/paperclip_test.rb +3 -2
  131. data/test/bridges/tiny_mce_test.rb +5 -2
  132. data/test/company.rb +25 -30
  133. data/test/config/base_test.rb +1 -1
  134. data/test/config/core_test.rb +9 -9
  135. data/test/config/create_test.rb +14 -8
  136. data/test/config/delete_test.rb +4 -4
  137. data/test/config/field_search_test.rb +6 -6
  138. data/test/config/list_test.rb +16 -16
  139. data/test/config/nested_test.rb +4 -4
  140. data/test/config/search_test.rb +8 -8
  141. data/test/config/show_test.rb +6 -6
  142. data/test/config/subform_test.rb +1 -1
  143. data/test/config/update_test.rb +5 -5
  144. data/test/const_mocker.rb +4 -4
  145. data/test/data_structures/action_columns_test.rb +4 -5
  146. data/test/data_structures/action_link_test.rb +1 -0
  147. data/test/data_structures/action_links_test.rb +5 -5
  148. data/test/data_structures/column_test.rb +9 -9
  149. data/test/data_structures/columns_test.rb +2 -2
  150. data/test/data_structures/error_message_test.rb +4 -5
  151. data/test/data_structures/set_test.rb +1 -2
  152. data/test/data_structures/sorting_test.rb +10 -10
  153. data/test/data_structures/validation_reflection_test.rb +8 -0
  154. data/test/extensions/routing_mapper_test.rb +2 -2
  155. data/test/helpers/list_column_helpers_test.rb +3 -2
  156. data/test/helpers/pagination_helpers_test.rb +5 -4
  157. data/test/helpers/search_column_helpers_test.rb +1 -1
  158. data/test/misc/active_record_permissions_test.rb +63 -50
  159. data/test/misc/attribute_params_test.rb +28 -26
  160. data/test/misc/calculation_test.rb +10 -3
  161. data/test/misc/configurable_test.rb +12 -13
  162. data/test/misc/constraints_test.rb +6 -6
  163. data/test/misc/convert_numbers_format_test.rb +7 -6
  164. data/test/misc/finder_test.rb +17 -12
  165. data/test/misc/lang_test.rb +3 -4
  166. data/test/misc/tableless_test.rb +2 -3
  167. data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
  168. data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
  169. data/test/mock_app/app/controllers/cars_controller.rb +1 -1
  170. data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
  171. data/test/mock_app/app/controllers/people_controller.rb +1 -1
  172. data/test/mock_app/app/models/file_model.rb +2 -2
  173. data/test/mock_app/app/models/person.rb +1 -1
  174. data/test/mock_app/config/application.rb +3 -3
  175. data/test/mock_app/config/boot.rb +1 -1
  176. data/test/mock_app/config/environment.rb +1 -0
  177. data/test/mock_app/config/environments/development.rb +0 -1
  178. data/test/mock_app/config/environments/production.rb +1 -1
  179. data/test/mock_app/db/schema.rb +14 -15
  180. data/test/model_stub.rb +13 -16
  181. data/test/run_all.rb +5 -7
  182. data/test/test_helper.rb +12 -9
  183. metadata +19 -3
@@ -12,9 +12,11 @@ module ActiveScaffold::DataStructures
12
12
  def label
13
13
  as_(@label) if @label
14
14
  end
15
+
15
16
  def name
16
17
  @label.to_s.underscore
17
18
  end
19
+
18
20
  def css_class
19
21
  @label.to_s.underscore
20
22
  end
@@ -23,7 +25,7 @@ module ActiveScaffold::DataStructures
23
25
  def ==(other) #:nodoc:
24
26
  # another ActionColumns
25
27
  if other.class == self.class
26
- self.label == other.label
28
+ label == other.label
27
29
  else
28
30
  @label.to_s == other.to_s
29
31
  end
@@ -31,28 +33,28 @@ module ActiveScaffold::DataStructures
31
33
 
32
34
  # Whether this column set is collapsed by default in contexts where collapsing is supported
33
35
  attr_accessor :collapsed
34
-
36
+
35
37
  # nests a subgroup in the column set
36
38
  def add_subgroup(label, &proc)
37
39
  columns = ActiveScaffold::DataStructures::ActionColumns.new
38
40
  columns.label = label
39
- columns.action = self.action
40
- columns.configure &proc
41
- self.exclude columns.collect_columns
42
- self.add columns
41
+ columns.action = action
42
+ columns.configure(&proc)
43
+ exclude columns.collect_columns
44
+ add columns
43
45
  end
44
46
 
45
47
  def include?(item)
46
48
  @set.each do |c|
47
- return true if !c.is_a? Symbol and c.include? item
49
+ return true if !c.is_a?(Symbol) && c.include?(item)
48
50
  return true if c == item.to_sym
49
51
  end
50
- return false
52
+ false
51
53
  end
52
54
 
53
55
  def names
54
56
  if @columns
55
- self.collect_visible(:flatten => true) { |c| c.name }
57
+ collect_visible(:flatten => true) { |c| c.name }
56
58
  else
57
59
  names_without_auth_check
58
60
  end
@@ -87,35 +89,34 @@ module ActiveScaffold::DataStructures
87
89
  end
88
90
  end
89
91
  end
90
-
92
+
91
93
  def collect_visible(options = {}, &proc)
92
94
  columns = []
93
95
  options[:for] ||= @columns.active_record_class
94
96
  self.unauthorized_columns = []
95
97
  @set.each do |item|
96
- unless item.is_a? ActiveScaffold::DataStructures::ActionColumns || @columns.nil?
98
+ unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil?
97
99
  item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
98
100
  next if self.skip_column?(item, options)
99
101
  end
100
- if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten]
102
+ if item.is_a?(ActiveScaffold::DataStructures::ActionColumns) && options.key?(:flatten) && options[:flatten]
101
103
  columns += item.collect_visible(options, &proc)
102
104
  else
103
105
  columns << (block_given? ? yield(item) : item)
104
106
  end
105
107
  end
106
108
  columns
107
- end
108
-
109
+ end
110
+
109
111
  def skip_column?(column, options)
110
- result = false
111
112
  # skip if this matches a constrained column
112
- result = true if constraint_columns.include?(column.name.to_sym)
113
+ return true if constraint_columns.include?(column.name.to_sym)
113
114
  # skip this field if it's not authorized
114
- unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.try(:crud_type) || :read, :column => column.name)
115
- self.unauthorized_columns << column.name.to_sym
116
- result = true
115
+ unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || action.try(:crud_type) || :read, :column => column.name)
116
+ unauthorized_columns << column.name.to_sym
117
+ return true
117
118
  end
118
- return result
119
+ false
119
120
  end
120
121
 
121
122
  # registers a set of column objects (recursively, for all nested ActionColumns)
@@ -139,25 +140,25 @@ module ActiveScaffold::DataStructures
139
140
  Thread.current[:constraint_columns] ||= {}
140
141
  Thread.current[:constraint_columns][constraint_columns_key] = columns
141
142
  end
142
-
143
+
143
144
  def constraint_columns
144
145
  constraints = Thread.current[:constraint_columns]
145
146
  (constraints[constraint_columns_key] if constraints) || []
146
147
  end
147
-
148
+
148
149
  attr_writer :unauthorized_columns
149
150
  def unauthorized_columns
150
151
  @unauthorized_columns ||= []
151
152
  end
152
-
153
+
153
154
  def length
154
- ((@set - self.constraint_columns) - self.unauthorized_columns).length
155
+ ((@set - constraint_columns) - unauthorized_columns).length
155
156
  end
156
157
 
157
158
  protected
158
159
 
159
160
  def collect_columns
160
- @set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col}
161
+ @set.collect { |col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col }
161
162
  end
162
163
 
163
164
  # called during clone or dup. makes the clone/dup deeper.
@@ -21,14 +21,14 @@ module ActiveScaffold::DataStructures
21
21
  # apply quick properties
22
22
  options.each_pair do |k, v|
23
23
  setter = "#{k}="
24
- self.send(setter, v) if self.respond_to? setter
24
+ send(setter, v) if self.respond_to? setter
25
25
  end
26
26
  self.toggle = self.action.try(:to_sym) == :index && (parameters.present? || dynamic_parameters) unless options.include? :toggle
27
27
  end
28
28
 
29
29
  def initialize_copy(action_link)
30
- self.parameters = self.parameters.clone if action_link.instance_variable_get(:@parameters)
31
- self.html_options = self.html_options.clone if action_link.instance_variable_get(:@html_options)
30
+ self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters)
31
+ self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options)
32
32
  end
33
33
 
34
34
  # the weight for this link in the action links collection, it will be used to sort the collection
@@ -36,7 +36,7 @@ module ActiveScaffold::DataStructures
36
36
 
37
37
  # the action-path for this link. what page to request? this is required!
38
38
  attr_accessor :action
39
-
39
+
40
40
  # the controller for this action link. if nil, the current controller should be assumed.
41
41
  attr_writer :controller
42
42
 
@@ -71,7 +71,7 @@ module ActiveScaffold::DataStructures
71
71
  def label
72
72
  @label.is_a?(Symbol) ? as_(@label) : @label
73
73
  end
74
-
74
+
75
75
  # image to use {:name => 'arrow.png', :size => '16x16'}
76
76
  attr_accessor :image
77
77
 
@@ -80,21 +80,24 @@ module ActiveScaffold::DataStructures
80
80
  @dhtml_confirm = nil if value
81
81
  @confirm = value
82
82
  end
83
+
83
84
  def confirm(label = '')
84
85
  @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label)
85
86
  end
87
+
86
88
  def confirm?
87
- !!@confirm
89
+ @confirm.present?
88
90
  end
89
-
91
+
90
92
  # if the action uses a DHTML based (i.e. 2-phase) confirmation
91
93
  attr_accessor :dhtml_confirm
92
94
  def dhtml_confirm=(value)
93
95
  @confirm = nil if value
94
96
  @dhtml_confirm = value
95
97
  end
98
+
96
99
  def dhtml_confirm?
97
- !!@dhtml_confirm
100
+ @dhtml_confirm.present?
98
101
  end
99
102
 
100
103
  # what method to call on the controller to see if this action_link should be visible
@@ -102,20 +105,20 @@ module ActiveScaffold::DataStructures
102
105
  # note that this is only the UI part of the security. to prevent URL hax0rz, you also need security on requests (e.g. don't execute update method unless authorized).
103
106
  attr_writer :security_method
104
107
  def security_method
105
- @security_method || "#{self.action}_authorized?"
108
+ @security_method || "#{action}_authorized?"
106
109
  end
107
110
 
108
111
  def security_method_set?
109
- !!@security_method
112
+ @security_method.present?
110
113
  end
111
114
 
112
115
  # enable it to refresh the parent row when the view is closed
113
116
  attr_accessor :refresh_on_close
114
-
117
+
115
118
  # what method to call on the controller to see if this action_link should be visible
116
119
  # if method return true, link won't be displayed
117
120
  attr_accessor :ignore_method
118
-
121
+
119
122
  # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent.
120
123
  # this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type).
121
124
  # options are :create, :read, :update, and :delete
@@ -127,38 +130,37 @@ module ActiveScaffold::DataStructures
127
130
  @inline = (val == true)
128
131
  self.popup = self.page = false if @inline
129
132
  end
130
- def inline?; @inline end
133
+
134
+ def inline?
135
+ @inline
136
+ end
131
137
 
132
138
  # a "popup" link displays in a separate (browser?) window. this will eventually take arguments.
133
139
  # exclusive with inline? and page?
134
140
  def popup=(val)
135
141
  @popup = (val == true)
136
- if @popup
137
- self.inline = self.page = false
142
+ return unless @popup
143
+ self.inline = self.page = false
138
144
 
139
- # the :method parameter doesn't mix with the :popup parameter
140
- # when/if we start using DHTML popups, we can bring :method back
141
- self.method = nil
142
- end
145
+ # the :method parameter doesn't mix with the :popup parameter
146
+ # when/if we start using DHTML popups, we can bring :method back
147
+ self.method = nil
148
+ end
149
+
150
+ def popup?
151
+ @popup
143
152
  end
144
- def popup?; @popup end
145
153
 
146
154
  # a "page" link displays by reloading the current page
147
155
  # exclusive with inline? and popup?
148
156
  def page=(val)
149
157
  @page = (val == true)
150
- if @page
151
- self.inline = self.popup = false
152
-
153
- # when :method is defined, ActionView adds an onclick to use a form ...
154
- # so it's best to just empty out :method whenever possible.
155
- # we only ever need to know @method = :get for things that default to POST.
156
- # the only things that default to POST are forms and ajax calls.
157
- # when @page = true, we don't use ajax.
158
- self.method = nil if method == :get
159
- end
158
+ self.inline = self.popup = false if @page
159
+ end
160
+
161
+ def page?
162
+ @page
160
163
  end
161
- def page?; @page end
162
164
 
163
165
  # where the result of this action should insert in the display.
164
166
  # for :type => :collection, supported values are:
@@ -173,10 +175,10 @@ module ActiveScaffold::DataStructures
173
175
  # false (no attempt at positioning)
174
176
  attr_writer :position
175
177
  def position
176
- return @position unless @position.nil? or @position == true
177
- return :replace if self.type == :member
178
- return :top if self.type == :collection
179
- raise "what should the default position be for #{self.type}?"
178
+ return @position unless @position.nil? || @position == true
179
+ return :replace if type == :member
180
+ return :top if type == :collection
181
+ raise "what should the default position be for #{type}?"
180
182
  end
181
183
 
182
184
  # what type of link this is. currently supported values are :collection and :member.
@@ -187,25 +189,23 @@ module ActiveScaffold::DataStructures
187
189
  def html_options
188
190
  @html_options ||= {}
189
191
  end
190
-
192
+
191
193
  # nested action_links are referencing a column
192
194
  attr_accessor :column
193
-
194
- # don't close the panel when another action link is open
195
+
196
+ # don't close the panel when another action link is open
195
197
  attr_writer :keep_open
196
198
  def keep_open?
197
199
  @keep_open
198
200
  end
199
-
201
+
200
202
  # indicates that this a nested_link
201
203
  def nested_link?
202
204
  @column || (parameters && parameters[:named_scope])
203
205
  end
204
-
206
+
205
207
  def name_to_cache
206
- @name_to_cache ||= "#{controller || 'self'}_#{type}_#{action}#{'_' if parameters.present?}#{parameters.map{|k,v| "#{k}=#{v.is_a?(Array) ? v.join(',') : v}"}.join('_')}"
208
+ @name_to_cache ||= "#{controller || 'self'}_#{type}_#{action}#{'_' if parameters.present?}#{parameters.map { |k, v| "#{k}=#{v.is_a?(Array) ? v.join(',') : v}" }.join('_')}"
207
209
  end
208
-
209
-
210
210
  end
211
211
  end
@@ -11,22 +11,24 @@ module ActiveScaffold::DataStructures
11
11
 
12
12
  # adds an ActionLink, creating one from the arguments if need be
13
13
  def add(action, options = {})
14
- link = if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
15
- action
16
- else
17
- options[:type] ||= default_type if default_type
18
- ActiveScaffold::DataStructures::ActionLink.new(action, options)
19
- end
14
+ link =
15
+ if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
16
+ action
17
+ else
18
+ options[:type] ||= default_type if default_type
19
+ ActiveScaffold::DataStructures::ActionLink.new(action, options)
20
+ end
20
21
  # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure
21
22
  existing = find_duplicate(link)
22
- unless existing
23
+
24
+ if existing
25
+ existing
26
+ else
23
27
  # That s for backwards compatibility if we are in root of action_links
24
28
  # we have to move actionlink into members or collection subgroup
25
29
  group = (name == :root ? subgroup(link.type, link.type) : self)
26
30
  group.add_to_set(link)
27
31
  link
28
- else
29
- existing
30
32
  end
31
33
  end
32
34
  alias_method :<<, :add
@@ -38,9 +40,9 @@ module ActiveScaffold::DataStructures
38
40
  # adds a link to a specific group
39
41
  # groups are represented as a string separated by a dot
40
42
  # eg member.crud
41
- def add_to_group(link, group = nil)
43
+ def add_to_group(link, group_name = nil)
42
44
  add_to = root
43
- add_to = group.split('.').inject(root){|group, group_name| group.send(group_name)} if group
45
+ add_to = group_name.split('.').inject(root) { |group, name| group.send(name) } if group_name
44
46
  add_to << link unless link.nil?
45
47
  end
46
48
 
@@ -65,14 +67,14 @@ module ActiveScaffold::DataStructures
65
67
  collected = item.find_duplicate(link)
66
68
  links << collected unless collected.nil?
67
69
  else
68
- links << item if item.action == link.action and item.static_controller? && item.controller == link.controller and item.parameters == link.parameters
70
+ links << item if item.action == link.action && item.static_controller? && item.controller == link.controller && item.parameters == link.parameters
69
71
  end
70
72
  end
71
73
  links.first
72
74
  end
73
75
 
74
76
  def delete(val)
75
- self.each({:include_set => true}) do |link, set|
77
+ each(:include_set => true) do |link, set|
76
78
  if link.action.to_s == val.to_s
77
79
  set.delete link
78
80
  break
@@ -107,10 +109,10 @@ module ActiveScaffold::DataStructures
107
109
  end
108
110
  end
109
111
  end
110
-
112
+
111
113
  def collect_by_type(type = nil)
112
114
  links = []
113
- subgroup(type).each(type) {|link| links << link}
115
+ subgroup(type).each(type) { |link| links << link }
114
116
  links
115
117
  end
116
118
 
@@ -3,11 +3,11 @@ class ActiveScaffold::DataStructures::Actions
3
3
 
4
4
  def initialize(*args)
5
5
  @set = []
6
- self.add *args
6
+ add *args
7
7
  end
8
8
 
9
9
  def exclude(*args)
10
- args.collect! { |a| a.to_sym } # symbolize the args
10
+ args.collect!(&:to_sym) # symbolize the args
11
11
  @set.reject! { |m| args.include? m } # reject all actions specified
12
12
  end
13
13
 
@@ -17,11 +17,11 @@ class ActiveScaffold::DataStructures::Actions
17
17
  alias_method :<<, :add
18
18
 
19
19
  def each
20
- @set.each {|item| yield item}
20
+ @set.each { |item| yield item }
21
21
  end
22
22
 
23
23
  def include?(val)
24
- val.is_a?(Symbol) ? super : @set.any?{|item| item.to_s == val.to_s}
24
+ val.is_a?(Symbol) ? super : @set.any? { |item| item.to_s == val.to_s }
25
25
  end
26
26
 
27
27
  # swaps one element in the list with the other.
@@ -42,4 +42,4 @@ class ActiveScaffold::DataStructures::Actions
42
42
  def initialize_copy(from)
43
43
  @set = from.instance_variable_get('@set').clone
44
44
  end
45
- end
45
+ end
@@ -1,14 +1,17 @@
1
1
  module ActiveScaffold::DataStructures
2
2
  class Bridge
3
3
  def self.install
4
- raise(RunTimeError, "install not defined for bridge #{name}")
4
+ raise RunTimeError, "install not defined for bridge #{name}"
5
5
  end
6
-
6
+
7
+ def self.prepare
8
+ end
9
+
7
10
  # by convention and default, use the bridge name as the required constant for installation
8
11
  def self.install?
9
12
  Object.const_defined? name.demodulize
10
13
  end
11
-
14
+
12
15
  def self.run
13
16
  install if install?
14
17
  end