Class: Osm::FlexiRecord::Column
Constant Summary
Constants inherited from Model
Instance Attribute Summary collapse
-
#editable ⇒ Boolean
Wether the field can be edited.
-
#flexi_record ⇒ Boolean
The FlexiRecord this column belongs to.
-
#id ⇒ String
OSM identifier for the field.
-
#name ⇒ String
Human readable name for the field.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Column based on flexi_record then id.
-
#delete(api) ⇒ Boolean
Delete a column in OSM.
-
#initialize ⇒ Object
constructor
Initialize a new FlexiRecord::Column.
- #inspect ⇒ Object
-
#update(api) ⇒ Boolean
Update a column in OSM.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new FlexiRecord::Column
|
# File 'lib/osm/flexi_record.rb', line 154
|
Instance Attribute Details
#editable ⇒ Boolean
Returns Wether the field can be edited.
140 |
# File 'lib/osm/flexi_record.rb', line 140 attribute :flexi_record, :type => Object |
#flexi_record ⇒ Boolean
Returns The FlexiRecord this column belongs to.
140 |
# File 'lib/osm/flexi_record.rb', line 140 attribute :flexi_record, :type => Object |
#id ⇒ String
Returns OSM identifier for the field. Special ones are ‘dob’, ‘total’, ‘completed’, ‘age’, ‘firstname’ and ‘lastname’, user ones are of the format ‘f_NUMBER’.
140 |
# File 'lib/osm/flexi_record.rb', line 140 attribute :flexi_record, :type => Object |
#name ⇒ String
Returns Human readable name for the field.
140 |
# File 'lib/osm/flexi_record.rb', line 140 attribute :flexi_record, :type => Object |
Instance Method Details
#<=>(another) ⇒ Object
Compare Column based on flexi_record then id
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/osm/flexi_record.rb', line 214 def <=>(another) result = self.flexi_record <=> another.try(:flexi_record) if result == 0 if id.match(/\Af_\d+\Z/) # This is a user column unless another.try(:id).to_s.match(/\Af_\d+\Z/) return 1 end else # This is a system column if another.try(:id).to_s.match(/\Af_\d+\Z/) return -1 end end result = self.id <=> another.try(:id) end return result end |
#delete(api) ⇒ Boolean
Delete a column in OSM
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/osm/flexi_record.rb', line 191 def delete(api) require_ability_to(api, :write, :flexi, flexi_record.section_id) raise Osm::Forbidden, 'this column is not editable' unless self.editable data = api.perform_query("extras.php?action=deleteColumn§ionid=#{flexi_record.section_id}&extraid=#{flexi_record.id}", { 'columnId' => self.id, }) if (data.is_a?(Hash) && data.has_key?('config')) ActiveSupport::JSON.decode(data['config']).each do |f| if f['id'] == self.id # It wasn't deleted return false end end end # The cached columns for the flexi record will be out of date - remove them cache_delete(api, ['flexi_record_columns', flexi_record.id]) return true end |
#inspect ⇒ Object
233 234 235 |
# File 'lib/osm/flexi_record.rb', line 233 def inspect Osm.inspect_instance(self, ={:replace_with => {'flexi_record' => :id}}) end |
#update(api) ⇒ Boolean
Update a column in OSM
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/osm/flexi_record.rb', line 164 def update(api) raise Osm::ObjectIsInvalid, 'column is invalid' unless valid? require_ability_to(api, :write, :flexi, flexi_record.section_id) raise Osm::Forbidden, 'this column is not editable' unless self.editable data = api.perform_query("extras.php?action=renameColumn§ionid=#{flexi_record.section_id}&extraid=#{flexi_record.id}", { 'columnId' => self.id, 'columnName' => self.name, }) if (data.is_a?(Hash) && data.has_key?('config')) ActiveSupport::JSON.decode(data['config']).each do |f| if (f['id'] == self.id) && (f['name'] == self.name) reset_changed_attributes # The cached columns for the flexi record will be out of date - remove them cache_delete(api, ['flexi_record_columns', flexi_record.id]) return true end end end return false end |