Module: Clevic::TableIndex
- Includes:
- FieldValuer
- Included in:
- SwingTableIndex, Qt::ModelIndex
- Defined in:
- lib/clevic/table_index.rb
Overview
to be included in something that responds to model, row, column
Instance Attribute Summary collapse
-
#entity ⇒ Object
the underlying entity TODO caching doesn’t help with Qt because ModelIndex objects are extremely short-lived.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sort by row, then column.
-
#attribute ⇒ Object
return the attribute of the underlying entity corresponding to the column of this index.
- #dump ⇒ Object
-
#errors ⇒ Object
return a collection of errors.
-
#field ⇒ Object
return the Clevic::Field for this index.
-
#field_name ⇒ Object
return the table’s field name.
-
#field_value ⇒ Object
return the value of the field, it may be the _id value.
-
#has_errors? ⇒ Boolean
return true if validation failed for this indexes field.
- #inspect ⇒ Object
-
#meta ⇒ Object
returns the list of ModelColumn metadata.
- #prev ⇒ Object
-
#rc ⇒ Object
return a string (row,column) suitable for displaying to users, ie 1-based not 0-based.
Methods included from FieldValuer
#attribute_value, #attribute_value=, #display_value, #edit_value, #edit_value=, #find_related, #raw_value, #text_value=, #tooltip, valuer, #valuer, #writer
Instance Attribute Details
#entity ⇒ Object
the underlying entity TODO caching doesn’t help with Qt because ModelIndex objects are extremely short-lived. Not sure about swing.
56 57 58 59 |
# File 'lib/clevic/table_index.rb', line 56 def entity return nil if model.nil? model.collection[row] end |
Instance Method Details
#<=>(other) ⇒ Object
sort by row, then column
81 82 83 84 85 86 87 88 |
# File 'lib/clevic/table_index.rb', line 81 def <=>( other ) row_comp = self.row <=> other.row if row_comp == 0 self.column <=> other.column else row_comp end end |
#attribute ⇒ Object
return the attribute of the underlying entity corresponding to the column of this index
31 32 33 |
# File 'lib/clevic/table_index.rb', line 31 def attribute model.attributes[column] end |
#dump ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/clevic/table_index.rb', line 13 def dump if valid? <<-EOF field: #{field_name} => #{field_value} attribute: #{attribute.inspect} => #{attribute_value.inspect} meta: #{.inspect} EOF else 'invalid' end end |
#errors ⇒ Object
return a collection of errors. Unlike AR, this will always return an array that will have zero, one or many elements.
76 77 78 |
# File 'lib/clevic/table_index.rb', line 76 def errors [ entity.errors[field_name.to_sym] ].flatten end |
#field ⇒ Object
return the Clevic::Field for this index
9 10 11 |
# File 'lib/clevic/table_index.rb', line 9 def field @field ||= model.field_for_index( self ) end |
#field_name ⇒ Object
return the table’s field name. For associations, this would be suffixed with _id
44 45 46 |
# File 'lib/clevic/table_index.rb', line 44 def field_name .name end |
#field_value ⇒ Object
return the value of the field, it may be the _id value
49 50 51 |
# File 'lib/clevic/table_index.rb', line 49 def field_value entity.send( field_name ) end |
#has_errors? ⇒ Boolean
return true if validation failed for this indexes field
64 65 66 67 68 69 70 71 |
# File 'lib/clevic/table_index.rb', line 64 def has_errors? # virtual fields don't have metadata if .nil? false else entity.errors.invalid?( field_name.to_sym ) end end |
#inspect ⇒ Object
90 91 92 |
# File 'lib/clevic/table_index.rb', line 90 def inspect "#<TableIndex (#{row},#{column}) '#{raw_value rescue "no raw value: #{$!.}"}'>" end |
#meta ⇒ Object
returns the list of ModelColumn metadata
36 37 38 39 40 |
# File 'lib/clevic/table_index.rb', line 36 def # use the optimised version # TODO just use the model version instead? field. end |
#prev ⇒ Object
25 26 27 |
# File 'lib/clevic/table_index.rb', line 25 def prev choppy( :row => row - 1 ) end |
#rc ⇒ Object
return a string (row,column) suitable for displaying to users, ie 1-based not 0-based
96 97 98 |
# File 'lib/clevic/table_index.rb', line 96 def rc "(#{row+1},#{column+1})" end |