Class: ActiveScaffold::DataStructures::Column
- Includes:
- Configurable
- Defined in:
- lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/virtual_column_test.rb,
lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/standard_column_test.rb,
lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb,
lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb
Overview
require ‘test/model_stub’
Constant Summary collapse
- @@associated_limit =
3
- @@associated_number =
true
- @@show_blank_record =
true
- @@actions_for_association_links =
AST - I like to default to :show only
[:show]
Instance Attribute Summary collapse
-
#actions_for_association_links ⇒ Object
Returns the value of attribute actions_for_association_links.
-
#active_record_class ⇒ Object
readonly
Returns the value of attribute active_record_class.
-
#allow_add_existing ⇒ Object
AST allow_add_existing Whether to enable add_existing for this column.
-
#associated_limit ⇒ Object
Returns the value of attribute associated_limit.
-
#associated_number ⇒ Object
writeonly
Sets the attribute associated_number.
-
#association ⇒ Object
readonly
the association from the ActiveRecord class.
-
#calculate ⇒ Object
define a calculation for the column.
-
#collapsed ⇒ Object
Whether this column set is collapsed by default in contexts where collapsing is supported.
-
#column ⇒ Object
readonly
the ConnectionAdapter::*Column object from the ActiveRecord class.
-
#css_class ⇒ Object
this will be /joined/ to the :name for the td’s class attribute.
- #description ⇒ Object
-
#file_column_display ⇒ Object
Returns the value of attribute file_column_display.
- #form_ui ⇒ Object (also: #ui_type)
-
#includes ⇒ Object
a collection of associations to pre-load when finding the records on a page.
-
#inplace_edit ⇒ Object
Whether to enable inplace editing for this column.
-
#label(options = {:count => 1}) ⇒ Object
AST - still figuring out just exactly how to do this.
-
#link ⇒ Object
readonly
associate an action_link with this column.
- #list_ui ⇒ Object
-
#name ⇒ Object
this is the name of the getter on the ActiveRecord model.
-
#options ⇒ Object
a place to store dev’s column specific options.
-
#required ⇒ Object
writeonly
whether the field is required or not.
- #search_sql ⇒ Object
- #search_ui ⇒ Object
-
#select_columns ⇒ Object
a collection of columns to load when eager loading is disabled, if it’s nil all columns will be loaded.
-
#show_blank_record ⇒ Object
writeonly
Sets the attribute show_blank_record.
-
#weight ⇒ Object
to modify the default order of columns.
Instance Method Summary collapse
- #<=>(other_column) ⇒ Object
-
#==(other) ⇒ Object
this is so that array.delete and array.include?, etc., will work by column name.
- #associated_number? ⇒ Boolean
-
#autolink? ⇒ Boolean
set an action_link to nested list or inline form in this column.
-
#calculation? ⇒ Boolean
get whether to run a calculation on this column.
-
#clear_link ⇒ Object
this should not only delete any existing link but also prevent column links from being automatically added by later routines.
-
#field_name ⇒ Object
just the field (not table.field).
- #format_column(value) ⇒ Object
- #h(value) ⇒ Object
-
#initialize(name, active_record_class) ⇒ Column
constructor
instantiation is handled internally through the DataStructures::Columns object.
-
#params ⇒ Object
Any extra parameters this particular column uses.
- #plural_association? ⇒ Boolean
- #polymorphic_association? ⇒ Boolean
- #required? ⇒ Boolean
- #searchable? ⇒ Boolean
- #set_link(action, options = {}) ⇒ Object
- #show_blank_record?(associated) ⇒ Boolean
- #singular_association? ⇒ Boolean
- #sort ⇒ Object
-
#sort=(value) ⇒ Object
sorting on a column can be configured four ways: sort = true default, uses intelligent sorting sql default sort = false sometimes sorting doesn’t make sense sort = => “” define your own sql for sorting.
-
#sort_by(options) ⇒ Object
a configuration helper for the self.sort property.
- #sortable? ⇒ Boolean
- #through_association? ⇒ Boolean
- #ui_type=(val) ⇒ Object
-
#virtual? ⇒ Boolean
an interpreted property.
Methods included from Configurable
Constructor Details
#initialize(name, active_record_class) ⇒ Column
instantiation is handled internally through the DataStructures::Columns object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 249 def initialize(name, active_record_class) #:nodoc: self.name = name.to_sym @column = active_record_class.columns_hash[self.name.to_s] @association = active_record_class.reflect_on_association(self.name) @autolink = !@association.nil? @active_record_class = active_record_class @table = active_record_class.table_name @weight = 0 @associated_limit = self.class.associated_limit @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association # AST - this means I have to set my search_ui value for every field that uses record_select # @search_ui = :select if @association and not polymorphic_association? @options = {:format => :i18n_number} if @column.try(:number?) # default all the configurable variables self.css_class = '' if active_record_class.respond_to? :reflect_on_validations_for column_names = [name] column_names << @association.primary_key_name if @association self.required = column_names.any? do |column_name| active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.[:allow_nil] and not val.[:allow_blank]) end end else self.required = false end self.sort = true self.search_sql = true # AST Begin if defined?(SemanticAttributes::Attribute) #TODO 2009-05-08 (EJM) Level=0 - This isn't picking up the condition require with_options block self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil? active_record_class.semantic_attributes[self.name].predicates.find do |p| sem_type = p.class.to_s.split('::')[1].underscore.to_sym next if [:required, :association].include?(sem_type) @form_ui = sem_type end end # AST End self.includes = (association and not polymorphic_association?) ? [association.name] : [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveScaffold::Configurable
Instance Attribute Details
#actions_for_association_links ⇒ Object
Returns the value of attribute actions_for_association_links.
205 206 207 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 205 def actions_for_association_links @actions_for_association_links end |
#active_record_class ⇒ Object (readonly)
Returns the value of attribute active_record_class.
5 6 7 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 5 def active_record_class @active_record_class end |
#allow_add_existing ⇒ Object
AST allow_add_existing Whether to enable add_existing for this column
22 23 24 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 22 def allow_add_existing @allow_add_existing end |
#associated_limit ⇒ Object
Returns the value of attribute associated_limit.
179 180 181 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 179 def associated_limit @associated_limit end |
#associated_number=(value) ⇒ Object (writeonly)
Sets the attribute associated_number
184 185 186 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 184 def associated_number=(value) @associated_number = value end |
#association ⇒ Object (readonly)
the association from the ActiveRecord class
215 216 217 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 215 def association @association end |
#calculate ⇒ Object
define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do.
145 146 147 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 145 def calculate @calculate end |
#collapsed ⇒ Object
Whether this column set is collapsed by default in contexts where collapsing is supported
18 19 20 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 18 def collapsed @collapsed end |
#column ⇒ Object (readonly)
the ConnectionAdapter::*Column object from the ActiveRecord class
212 213 214 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 212 def column @column end |
#css_class ⇒ Object
this will be /joined/ to the :name for the td’s class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names.
51 52 53 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 51 def css_class @css_class end |
#description ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 42 def description if @description @description else I18n.t name, :scope => [:activerecord, :description, active_record_class.to_s.underscore.to_sym], :default => '' end end |
#file_column_display ⇒ Object
Returns the value of attribute file_column_display.
4 5 6 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb', line 4 def file_column_display @file_column_display end |
#form_ui ⇒ Object Also known as: ui_type
92 93 94 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 92 def form_ui @form_ui end |
#includes ⇒ Object
a collection of associations to pre-load when finding the records on a page
153 154 155 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 153 def includes @includes end |
#inplace_edit ⇒ Object
Whether to enable inplace editing for this column. Currently works for text columns, in the List.
11 12 13 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 11 def inplace_edit @inplace_edit end |
#label(options = {:count => 1}) ⇒ Object
AST - still figuring out just exactly how to do this
35 36 37 38 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 35 def label( = {:count => 1}) # as_(@label, options)# || active_record_class.human_attribute_name(name.to_s) as_(@label) || active_record_class.human_attribute_name(name.to_s) end |
#link ⇒ Object (readonly)
associate an action_link with this column
120 121 122 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 120 def link @link end |
#list_ui ⇒ Object
97 98 99 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 97 def list_ui @list_ui || @form_ui end |
#name ⇒ Object
this is the name of the getter on the ActiveRecord model. it is the only absolutely required attribute … all others will be inferred from this name.
8 9 10 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 8 def name @name end |
#options ⇒ Object
a place to store dev’s column specific options
114 115 116 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 114 def @options end |
#required=(value) ⇒ Object (writeonly)
whether the field is required or not. used on the form for visually indicating the fact to the user. TODO: move into predicate
55 56 57 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 55 def required=(value) @required = value end |
#search_sql ⇒ Object
165 166 167 168 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 165 def search_sql self.initialize_search_sql if @search_sql === true @search_sql end |
#search_ui ⇒ Object
102 103 104 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 102 def search_ui @search_ui || @form_ui end |
#select_columns ⇒ Object
a collection of columns to load when eager loading is disabled, if it’s nil all columns will be loaded
159 160 161 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 159 def select_columns @select_columns end |
#show_blank_record=(value) ⇒ Object (writeonly)
Sets the attribute show_blank_record
192 193 194 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 192 def show_blank_record=(value) @show_blank_record = value end |
#weight ⇒ Object
to modify the default order of columns
174 175 176 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 174 def weight @weight end |
Instance Method Details
#<=>(other_column) ⇒ Object
301 302 303 304 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 301 def <=>(other_column) order_weight = self.weight <=> other_column.weight order_weight != 0 ? order_weight : self.name.to_s <=> other_column.name.to_s end |
#==(other) ⇒ Object
this is so that array.delete and array.include?, etc., will work by column name
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 235 def ==(other) #:nodoc: # another column if other.respond_to? :name and other.class == self.class self.name == other.name.to_sym # a string or symbol elsif other.respond_to? :to_sym self.name == other.to_sym rescue false # catch "interning empty string" # unknown else self.eql? other end end |
#associated_number? ⇒ Boolean
185 186 187 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 185 def associated_number? @associated_number end |
#autolink? ⇒ Boolean
set an action_link to nested list or inline form in this column
123 124 125 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 123 def autolink? @autolink and self.association.reverse end |
#calculation? ⇒ Boolean
get whether to run a calculation on this column
148 149 150 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 148 def calculation? !(@calculate == false or @calculate.nil?) end |
#clear_link ⇒ Object
this should not only delete any existing link but also prevent column links from being automatically added by later routines
128 129 130 131 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 128 def clear_link @link = nil @autolink = false end |
#field_name ⇒ Object
just the field (not table.field)
296 297 298 299 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 296 def field_name return nil if virtual? column ? @active_record_class.connection.quote_column_name(column.name) : association.primary_key_name end |
#format_column(value) ⇒ Object
9 10 11 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/virtual_column_test.rb', line 9 def format_column(value) value end |
#h(value) ⇒ Object
5 6 7 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/virtual_column_test.rb', line 5 def h(value) value end |
#params ⇒ Object
Any extra parameters this particular column uses. This is for create/update purposes.
26 27 28 29 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 26 def params # lazy initialize @params ||= Set.new end |
#plural_association? ⇒ Boolean
219 220 221 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 219 def plural_association? self.association and [:has_many, :has_and_belongs_to_many].include? self.association.macro end |
#polymorphic_association? ⇒ Boolean
225 226 227 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 225 def polymorphic_association? self.association and self.association..has_key? :polymorphic and self.association.[:polymorphic] end |
#required? ⇒ Boolean
56 57 58 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 56 def required? @required end |
#searchable? ⇒ Boolean
169 170 171 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 169 def searchable? search_sql != false && search_sql != nil end |
#set_link(action, options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 133 def set_link(action, = {}) if action.is_a? ActiveScaffold::DataStructures::ActionLink @link = action else [:label] ||= self.label [:position] ||= :after unless .has_key?(:position) [:type] ||= :record @link = ActiveScaffold::DataStructures::ActionLink.new(action, ) end end |
#show_blank_record?(associated) ⇒ Boolean
193 194 195 196 197 198 199 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 193 def show_blank_record?(associated) if @show_blank_record return false if self.through_association? return false unless self.association.klass.(:action => :create) self.plural_association? or (self.singular_association? and associated.empty?) end end |
#singular_association? ⇒ Boolean
216 217 218 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 216 def singular_association? self.association and [:has_one, :belongs_to].include? self.association.macro end |
#sort ⇒ Object
74 75 76 77 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 74 def sort self.initialize_sort if @sort === true @sort end |
#sort=(value) ⇒ Object
sorting on a column can be configured four ways:
sort = true default, uses intelligent sorting sql default
sort = false sometimes sorting doesn't make sense
sort = {:sql => ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending.
sort = {:method => ""} define ruby-side code for sorting. this is SLOW with large recordsets!
65 66 67 68 69 70 71 72 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 65 def sort=(value) if value.is_a? Hash value.assert_valid_keys(:sql, :method) @sort = value else @sort = value ? true : false # force true or false end end |
#sort_by(options) ⇒ Object
a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
84 85 86 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 84 def sort_by() self.sort = end |
#sortable? ⇒ Boolean
79 80 81 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 79 def sortable? sort != false && !sort.nil? end |
#through_association? ⇒ Boolean
222 223 224 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 222 def through_association? self.association and self.association.[:through] end |
#ui_type=(val) ⇒ Object
108 109 110 111 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 108 def ui_type=(val) ::ActiveSupport::Deprecation.warn("config.columns[:#{name}].ui_type will disappear in version 2.0. Please use config.columns[:#{name}].form_ui instead.", caller) self.form_ui = val end |
#virtual? ⇒ Boolean
an interpreted property. the column is virtual if it isn’t from the active record model or any associated models
230 231 232 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb', line 230 def virtual? column.nil? && association.nil? end |