lib/rfm/layout.rb in ginjo-rfm-3.0.1 vs lib/rfm/layout.rb in ginjo-rfm-3.0.4
- old
+ new
@@ -301,14 +301,26 @@
# Apply mapping from :field_mapping, to send correct params in URL.
prms = params.merge(extra_params)
map = field_mapping.invert
options.merge!({:field_mapping => map}) if map && !map.empty?
- # TODO: Make this part handle string AND symbol keys.
+ # TODO: Make this part handle string AND symbol keys. (isn't this already done?)
#map.each{|k,v| prms[k]=prms.delete(v) if prms[v]}
- prms.dup.each_key{|k| prms[map[k.to_s]]=prms.delete(k) if map[k.to_s]}
-
+
+ #prms.dup.each_key{|k| prms[map[k.to_s]]=prms.delete(k) if map[k.to_s]}
+ prms.dup.each_key do |k|
+ new_key = map[k.to_s] || k
+ if prms[new_key].is_a? Array
+ prms[new_key].each_with_index do |v, i|
+ prms["#{new_key}(#{i+1})"]=v
+ end
+ prms.delete new_key
+ else
+ prms[new_key]=prms.delete(k) if new_key != k
+ end
+ end
+
#c = Connection.new(action, prms, options, state.merge(:parent=>self))
c = Connection.new(action, prms, options, self)
rslt = c.parse(template || :fmresultset, Rfm::Resultset.new(self, self))
capture_resultset_meta(rslt) unless @resultset_meta
rslt
@@ -372,18 +384,28 @@
### Utility ###
def load_layout
- @loaded = true # This is first so parsing call to 'meta' wont cause infinite loop.
+ #@loaded = true # This is first so parsing call to 'meta' wont cause infinite loop,
+ # but I changed parsing template to refer directly to inst var instead of accessor method.
connection = Connection.new('-view', {'-db' => state[:database], '-lay' => name}, {:grammar=>'FMPXMLLAYOUT'}, self)
- rslt = connection.parse(:fmpxmllayout, self)
- #puts ["LAYOUT#load_layout result", rslt.class].join(', ')
- # @loaded = true
+ begin
+ connection.parse(:fmpxmllayout, self)
+ @loaded = true
+ rescue
+ @meta.clear
+ raise $!
+ end
@meta
end
+ def check_for_errors(code=@meta['error'].to_i, raise_401=state[:raise_401])
+ #puts ["\nRESULTSET#check_for_errors", code, raise_401]
+ raise Rfm::Error.getError(code) if code != 0 && (code != 401 || raise_401)
+ end
+
def field_mapping
@field_mapping ||= load_field_mapping(state[:field_mapping])
end
def load_field_mapping(mapping={})
@@ -415,10 +437,10 @@
#subs.collect{|s| s.model}
[@model]
end
- private :load_layout, :get_records, :params
+ private :load_layout, :get_records, :params, :check_for_errors
end # Layout
end # Rfm
\ No newline at end of file