ginjo-rfm 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## Ginjo-Rfm 2.0.2
4
+
5
+ * Added configuration parameter ignore_bad_data to silence data mismatch errors when loading resultset into records.
6
+
7
+ * Added method to load a resultset from file or string. Rfm::Resultset.load_data(file_or_string).
8
+
9
+ * Added more specs for the above features and for the XmlParser module.
10
+
3
11
  ## Ginjo-Rfm 2.0.1
4
12
 
5
- * Fixed bug in Base.find where options weren't being passed to Layout#find correctly
13
+ * Fixed bug in Base.find where options weren't being passed to Layout#find correctly.
6
14
 
7
15
  * Fixed bug in rfm.rb when calling #models or #modelize.
8
16
 
9
17
  ## Ginjo-Rfm 2.0.0
10
18
 
11
- * ActiveModel compatibility allows Rails ActiveRecord-style models
19
+ * ActiveModel compatibility allows Rails ActiveRecord-style models.
12
20
 
13
- * Alternative XML parsers using ActiveSupport::XmlMini interface
21
+ * Alternative XML parsers using ActiveSupport::XmlMini interface.
14
22
 
15
- * Compound queries with multiple omitable find-requests
23
+ * Compound queries with multiple omitable find-requests.
16
24
 
17
- * Configuration API manages settings of multiple server/db/layout/etc setups
25
+ * Configuration API manages settings of multiple server/db/layout/etc setups.
18
26
 
19
- * Full Filemaker metadata support
27
+ * Full Filemaker metadata support.
20
28
 
21
29
  ## Ginjo-Rfm 1.4.4
22
30
 
data/README.md CHANGED
@@ -372,6 +372,7 @@ Following are all of the recognized configuration options, including defaults if
372
372
  :file_name => 'rfm.yml # name of configuration file to load yaml from
373
373
  :file_path => ['', 'config/'] # array of additional file paths to look for configuration file
374
374
  :parser => ActiveSupport::XmlMini_REXML # XmlParser to use if no other is specified or can be found
375
+ :ignore_bad_data => nil # Instruct Rfm to ignore data mismatch errors when loading a resultset
375
376
 
376
377
 
377
378
  ### Using Models
@@ -515,26 +516,31 @@ See the API documentation for the lowdown on new methods in Rfm Server, Database
515
516
 
516
517
  All Rfm methods that take a configuration hash have two possible shortcuts.
517
518
 
518
- If you pass a symbol before the hash, it is interpreted as subgroup specification or subgroup filter
519
+ (1) If you pass a symbol before the hash, it is interpreted as subgroup specification or subgroup filter
519
520
 
520
521
  config :mygroup, :layout => 'mylayout'
522
+ # This will add the following configuration options to the object you called 'config' on.
521
523
  # :use => :mygroup, :layout => 'mylayout'
522
524
 
523
525
  get_config :othergroup
526
+ # This will return global configuration options merged with configuration options from :othergroup.
524
527
  # :use => [:mygroup, :othergroup], :layout => 'mylayout'
525
528
 
526
- If you pass a string before any symbols or hashes, it is interepreted as one of several possible configuration settings - usually a layout name, a database name, or a server hostname. The interpretation is dependent on the method being called. Not all methods will make use of a string parameter.
529
+ (2) If you pass a string before any symbols or hashes, it is interpreted as one of several possible configuration settings - usually a layout name, a database name, or a server hostname. The interpretation is dependent on the method being called. Not all methods will make use of a string parameter.
527
530
 
528
531
  class MyModel < Rfm::Base
529
532
  config 'MyLayoutName'
530
- # :layout => 'MyLayoutName'
533
+ # In this context, this is the same as
534
+ # config :layout => 'MyLayoutName'
531
535
  end
532
536
 
533
537
  Rfm.database 'MyDatabaseName'
534
- # :database => 'MyDatabaseName'
538
+ # In this context, this is the same as
539
+ # Rfm.database :database => 'MyDatabaseName'
535
540
 
536
541
  Rfm.modelize 'MyDatabaseName', :group1
537
- # :database => 'MyDatabaseName', :use => :group1
542
+ # In this context, this is the same as
543
+ # Rfm.modelize :database => 'MyDatabaseName', :use => :group1
538
544
 
539
545
  Just about anything you can do with a Rfm layout, you can also do with a Rfm model.
540
546
 
@@ -544,11 +550,28 @@ Just about anything you can do with a Rfm layout, you can also do with a Rfm mod
544
550
 
545
551
  There are a number of methods within Rfm that have been made accessible from the top-level Rfm module. Note that the server/database/layout methods are new to Rfm and are not the same as Rfm::Server, Rfm::Database, and Rfm::Layout. See the above section on "Getting Rfm Server, Database, and Layout Objects Manually" for an overview of how to use the new server/database/layout methods.
546
552
 
547
- # Any of these methods can be assed via Rfm.<method_name>
553
+ # Any of these methods can be accessed via Rfm.<method_name>
548
554
 
549
555
  Rfm::Factory :servers, :server, :db, :database, :layout, :models, :modelize
550
556
  Rfm::XmlParser :backend, :backend=
551
557
  Rfm::Config :config, :get_config, :config_clear
558
+ Rfm::Resultset :ignore_bad_data
559
+
560
+ If you are working with a Filemaker database that returns codes like '?' for a missing value in a date field, Rfm will throw an error. Set your main configuration, your server, or your layout to `ignore_bad_data true`, if you want Rfm to silently ignore data mismatch errors when loading resultset data. If ActiveRecord is loaded, and your resultset is loaded into a Rfm model, your model records will log these errors in the @errors attribute.
561
+
562
+ Rfm.config :ignore_bad_data => true
563
+
564
+ class MyModel < Rfm::Base
565
+ config 'my_layout'
566
+ end
567
+
568
+ result = MyModel.find(:name => 'mike')
569
+ # Assuming the Filemaker field 'some_date_field' contains a bad date value '?'
570
+ result[0].errors.full_messages
571
+ # ['some_date_field invalid date']
572
+
573
+ # To be more specific about what objects you want to ignore data errors
574
+ MyModel.layout.ignore_bad_data true
552
575
 
553
576
  ## Working with "Classic" Rfm Features
554
577
 
data/lib/rfm.rb CHANGED
@@ -61,6 +61,7 @@ module Rfm
61
61
  def_delegators 'Rfm::Factory', :servers, :server, :db, :database, :layout
62
62
  def_delegators 'Rfm::XmlParser', :backend, :backend=
63
63
  def_delegators 'Rfm::Config', :config, :get_config, :config_clear
64
+ def_delegators 'Rfm::Resultset', :load_data
64
65
 
65
66
  def models(*args)
66
67
  Rfm::Base
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -194,7 +194,7 @@ module Rfm
194
194
 
195
195
  # Access layout functions from base model
196
196
  def_delegators :layout, :db, :server, :field_controls, :field_names, :value_lists, :total_count,
197
- :query, :all, :delete, :portal_meta, :portal_names, :database, :table, :count
197
+ :query, :all, :delete, :portal_meta, :portal_names, :database, :table, :count, :ignore_bad_data
198
198
 
199
199
  def inherited(model)
200
200
  (Rfm::Factory.models << model).uniq unless Rfm::Factory.models.include? model
@@ -143,6 +143,7 @@ module Rfm
143
143
  @value_lists = Rfm::CaseInsensitiveHash.new
144
144
  # @portal_meta = nil
145
145
  # @field_names = nil
146
+ @ignore_bad_data = (db_obj.server.state[:ignore_bad_data] rescue nil)
146
147
  end
147
148
 
148
149
  meta_attr_reader :db
@@ -376,6 +377,11 @@ module Rfm
376
377
  @field_controls.freeze
377
378
  end
378
379
 
380
+ def ignore_bad_data(val = nil)
381
+ (@ignore_bad_data = val) unless val.nil?
382
+ @ignore_bad_data
383
+ end
384
+
379
385
  private :load, :get_records, :params
380
386
 
381
387
 
@@ -133,7 +133,12 @@ module Rfm
133
133
  data = field['data']; data = data.is_a?(Hash) ? [data] : data
134
134
  data.each do |x|
135
135
  next unless field_meta[field_name]
136
- datum.push(field_meta[field_name].coerce(x['__content__'], resultset_obj))
136
+ begin
137
+ datum.push(field_meta[field_name].coerce(x['__content__'], resultset_obj))
138
+ rescue StandardError => error
139
+ self.errors.add(field_name, error) if self.respond_to? :errors
140
+ raise error unless @layout.ignore_bad_data
141
+ end
137
142
  end if data
138
143
 
139
144
  if datum.length == 1
@@ -72,22 +72,22 @@ module Rfm
72
72
  @portal_meta ||= Rfm::CaseInsensitiveHash.new
73
73
  @include_portals = portals
74
74
 
75
- doc = XmlParser.new(xml_response, :namespace=>false, :parser=>server.state[:parser])
75
+ doc = XmlParser.new(xml_response, :namespace=>false, :parser=>(server.state[:parser] rescue nil))
76
76
 
77
77
  error = doc['fmresultset']['error']['code'].to_i
78
- check_for_errors(error, server.state[:raise_on_401])
78
+ check_for_errors(error, (server.state[:raise_on_401] rescue nil))
79
79
 
80
- datasource = doc['fmresultset']['datasource']
80
+ @datasource = doc['fmresultset']['datasource']
81
81
  meta = doc['fmresultset']['metadata']
82
82
  resultset = doc['fmresultset']['resultset']
83
83
 
84
- @date_format = convert_date_time_format(datasource['date-format'].to_s)
85
- @time_format = convert_date_time_format(datasource['time-format'].to_s)
86
- @timestamp_format = convert_date_time_format(datasource['timestamp-format'].to_s)
84
+ @date_format = convert_date_time_format(@datasource['date-format'].to_s)
85
+ @time_format = convert_date_time_format(@datasource['time-format'].to_s)
86
+ @timestamp_format = convert_date_time_format(@datasource['timestamp-format'].to_s)
87
87
 
88
88
  @foundset_count = resultset['count'].to_s.to_i
89
- @total_count = datasource['total-count'].to_s.to_i
90
- @table = datasource['table']
89
+ @total_count = @datasource['total-count'].to_s.to_i
90
+ @table = @datasource['table']
91
91
 
92
92
  (layout.table = @table) if layout and layout.table_no_load.blank?
93
93
 
@@ -97,6 +97,17 @@ module Rfm
97
97
  # See Record for control of portal data loading.
98
98
  parse_portals(meta)
99
99
 
100
+ # These were added for loading resultset from file
101
+ unless @layout
102
+ @layout = @datasource['layout']
103
+ @layout.instance_variable_set '@database', @datasource['database']
104
+ @layout.instance_eval do
105
+ def database
106
+ @database
107
+ end
108
+ end
109
+ end
110
+
100
111
  return if resultset['record'].nil?
101
112
  Rfm::Record.build_records(resultset['record'].rfm_force_array, self, @field_meta, @layout)
102
113
  end
@@ -109,6 +120,10 @@ module Rfm
109
120
  portal_meta.keys
110
121
  end
111
122
 
123
+ # Load Resultset data from file-spec or string
124
+ def self.load_data(file_or_string)
125
+ self.new(nil, file_or_string, nil)
126
+ end
112
127
 
113
128
  private
114
129
 
@@ -209,7 +209,8 @@ module Rfm
209
209
  :log_parser => false,
210
210
  :warn_on_redirect => true,
211
211
  :raise_on_401 => false,
212
- :timeout => 60
212
+ :timeout => 60,
213
+ :ignore_bad_data => false
213
214
  }.merge(options)
214
215
 
215
216
  @state.freeze
@@ -18,6 +18,7 @@ module Rfm
18
18
  password
19
19
  database
20
20
  layout
21
+ ignore_bad_data
21
22
  ssl
22
23
  root_cert
23
24
  root_cert_name
@@ -6,7 +6,7 @@ module Rfm
6
6
 
7
7
  extend self
8
8
 
9
- # Backend configurations
9
+ # Backend definitions & configurations
10
10
  BACKENDS = ActiveSupport::OrderedHash.new
11
11
 
12
12
  BACKENDS[:jdom] = {:require=>'jdom', :class => 'JDOM'}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ginjo-rfm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoff Coffey
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2012-04-19 00:00:00 Z
22
+ date: 2012-04-24 00:00:00 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: activesupport