Class: Osm::FlexiRecord::Data
Instance Attribute Summary collapse
-
#fields ⇒ DirtyHashy
Keys are the field’s id, values are the field values.
-
#flexi_record ⇒ Boolean
The FlexiRecord this column belongs to.
-
#grouping__id ⇒ Fixnum
OSM id for the grouping the member is in.
-
#member_id ⇒ Fixnum
OSM id for the member.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Data based on flexi_record, grouping_id then member_id.
- #inspect ⇒ Object
-
#update(api) ⇒ Boolean
Update data in OSM.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Instance Attribute Details
#fields ⇒ DirtyHashy
Returns Keys are the field’s id, values are the field values.
250 |
# File 'lib/osm/flexi_record.rb', line 250 attribute :flexi_record, :type => Object |
#flexi_record ⇒ Boolean
Returns The FlexiRecord this column belongs to.
250 |
# File 'lib/osm/flexi_record.rb', line 250 attribute :flexi_record, :type => Object |
#grouping__id ⇒ Fixnum
Returns OSM id for the grouping the member is in.
250 |
# File 'lib/osm/flexi_record.rb', line 250 attribute :flexi_record, :type => Object |
#member_id ⇒ Fixnum
Returns OSM id for the member.
250 |
# File 'lib/osm/flexi_record.rb', line 250 attribute :flexi_record, :type => Object |
Instance Method Details
#<=>(another) ⇒ Object
Compare Data based on flexi_record, grouping_id then member_id
322 323 324 325 326 327 |
# File 'lib/osm/flexi_record.rb', line 322 def <=>(another) result = self.flexi_record <=> another.try(:flexi_record) result = self.grouping_id <=> another.try(:grouping_id) if result == 0 result = self.member_id <=> another.try(:member_id) if result == 0 return result end |
#inspect ⇒ Object
329 330 331 |
# File 'lib/osm/flexi_record.rb', line 329 def inspect Osm.inspect_instance(self, ={:replace_with => {'flexi_record' => :id}}) end |
#update(api) ⇒ Boolean
Update data in OSM
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/osm/flexi_record.rb', line 282 def update(api) raise Osm::ObjectIsInvalid, 'data is invalid' unless valid? require_ability_to(api, :write, :flexi, flexi_record.section_id) term_id = Osm::Term.get_current_term_for_section(api, flexi_record.section_id).id updated = true editable_fields = flexi_record.get_columns(api).select{ |c| c.editable }.map{ |i| i.id } fields.changes.each do |field, (was,now)| if editable_fields.include?(field) data = api.perform_query("extras.php?action=updateScout", { 'termid' => term_id, 'scoutid' => self.member_id, 'column' => field, 'value' => now, 'sectionid' => flexi_record.section_id, 'extraid' => flexi_record.id, }) if (data.is_a?(Hash) && data['items'].is_a?(Array)) data['items'].each do |item| if item['scoutid'] == member_id.to_s # Find this member from the list of all members updated = false unless item[field] == now end end else updated = false end end end if updated fields.clean_up! # The cached datas for the flexi record will be out of date - remove them cache_delete(api, ['flexi_record_data', flexi_record.id]) end return updated end |