Class: Rfm::Result::Record
- Inherits:
-
Hash
- Object
- Hash
- Rfm::Result::Record
- Defined in:
- lib/rfm_result.rb
Instance Attribute Summary collapse
-
#mod_id ⇒ Object
readonly
Returns the value of attribute mod_id.
-
#portals ⇒ Object
readonly
Returns the value of attribute portals.
-
#record_id ⇒ Object
readonly
Returns the value of attribute record_id.
Instance Method Summary collapse
- #[]=(name, value) ⇒ Object
-
#initialize(row_element, resultset, fields, layout, portal = nil) ⇒ Record
constructor
A new instance of Record.
- #method_missing(symbol, *attrs) ⇒ Object
- #respond_to?(symbol, include_private = false) ⇒ Boolean
- #save ⇒ Object
- #save_if_not_modified ⇒ Object
Constructor Details
#initialize(row_element, resultset, fields, layout, portal = nil) ⇒ Record
Returns a new instance of Record.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rfm_result.rb', line 49 def initialize(row_element, resultset, fields, layout, portal=nil) @record_id = row_element.attributes['record-id'] @mod_id = row_element.attributes['mod-id'] @mods = {} @resultset = resultset @layout = layout @loaded = false row_element.each_element('field') { |field| field_name = field.attributes['name'] field_name.sub!(Regexp.new(portal + '::'), '') if portal datum = [] field.each_element('data') {|x| datum.push(fields[field_name].coerce(x.text))} if datum.length == 1 self[field_name] = datum[0] elsif datum.length == 0 self[field_name] = nil else self[field_name] = datum end } @portals = {} row_element.each_element('relatedset') { || table = .attributes['table'] records = [] .each_element('record') { |record| records << Record.new(record, @resultset, @resultset.portals[table], @layout, table) } @portals[table] = records } @loaded = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *attrs) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rfm_result.rb', line 106 def method_missing (symbol, *attrs) # check for simple getter val = self[symbol.to_s] return val if val != nil # check for setter symbol_name = symbol.to_s if symbol_name[-1..-1] == '=' && self.has_key?(symbol_name[0..-2]) return @mods[symbol_name[0..-2]] = attrs[0] end super end |
Instance Attribute Details
#mod_id ⇒ Object (readonly)
Returns the value of attribute mod_id.
85 86 87 |
# File 'lib/rfm_result.rb', line 85 def mod_id @mod_id end |
#portals ⇒ Object (readonly)
Returns the value of attribute portals.
85 86 87 |
# File 'lib/rfm_result.rb', line 85 def portals @portals end |
#record_id ⇒ Object (readonly)
Returns the value of attribute record_id.
85 86 87 |
# File 'lib/rfm_result.rb', line 85 def record_id @record_id end |
Instance Method Details
#[]=(name, value) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/rfm_result.rb', line 97 def []=(name, value) return super if !@loaded if self[name] != nil @mods[name] = val else raise "No such field: #{name}" end end |
#respond_to?(symbol, include_private = false) ⇒ Boolean
119 120 121 122 |
# File 'lib/rfm_result.rb', line 119 def respond_to?(symbol, include_private = false) return true if self[symbol.to_s] != nil super end |
#save ⇒ Object
87 88 89 90 |
# File 'lib/rfm_result.rb', line 87 def save self.merge(@layout.edit(self.record_id, @mods)[0]) if @mods.size > 0 @mods.clear end |
#save_if_not_modified ⇒ Object
92 93 94 95 |
# File 'lib/rfm_result.rb', line 92 def save_if_not_modified self.merge(@layout.edit(@record_id, @mods, {'-modid' => @mod_id})[0]) if @mods.size > 0 @mods.clear end |