Skip to content

Commit

Permalink
Updated xml_parser, version, gemspec.
Browse files Browse the repository at this point in the history
  • Loading branch information
ginjo committed Nov 24, 2011
2 parents f77d757 + 8d6cffc commit dc4134d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.gemspec merge=ours
ginjo-rfm.gemspec merge=ours
VERSION merge=ours
4 changes: 2 additions & 2 deletions ginjo-rfm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = "ginjo-rfm"
s.version = "1.5.0.pre19"
s.version = "1.5.0.pre20"

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Geoff Coffey", "Mufaddal Khumri", "Atsushi Matsuo", "Larry Sprock", "Bill Richardson"]
s.date = "2011-11-23"
s.date = "2011-11-24"
s.description = "Rfm brings your FileMaker data to Ruby. Now your Ruby scripts and Rails applications can talk directly to your FileMaker server."
s.email = "http://groups.google.com/group/rfmcommunity"
s.extra_rdoc_files = [
Expand Down
2 changes: 1 addition & 1 deletion lib/rfm/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.0.pre19
1.5.0.pre20
28 changes: 17 additions & 11 deletions lib/rfm/utilities/xml_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Rfm
module XmlParser
require 'rubygems'
require 'active_support' unless defined? ActiveSupport

extend self
Expand All @@ -27,39 +26,46 @@ def new(string_or_file, opts={})
unless opts[:backend]
ActiveSupport::XmlMini.parse(string_or_file)
else
ActiveSupport::XmlMini.with_backend(get_backend(opts[:backend])) {ActiveSupport::XmlMini.parse(string_or_file)}
ActiveSupport::XmlMini.with_backend(get_backend_from_hash(opts[:backend])) {ActiveSupport::XmlMini.parse(string_or_file)}
end
end

# Shortcut to XmlMini config getter.
def backend
def backend(name=nil)
self.backend= name if name
ActiveSupport::XmlMini.backend
end

# Shortcut to XmlMini config setter.
def backend=(string_or_class)
ActiveSupport::XmlMini.backend = string_or_class
end
def backend=(name)
if name.is_a? Symbol
set_backend_via_hash name
else
ActiveSupport::XmlMini.backend = name
end
end

private

# Given name, return backend config from BACKENDS, including any preloading.
# Will raise LoadError if can't load backend.
def get_backend(name)
def get_backend_from_hash(name)
backend_hash = BACKENDS[name.to_sym]
require backend_hash[:require]
backend_hash[:class].is_a?(Proc) ? backend_hash[:class].call : backend_hash[:class]
end

# Set XmlMini backend, given symbol matching one of the BACKENDS.
def set_backend(name)
self.backend = get_backend(name)
def set_backend_via_hash(name)
ActiveSupport::XmlMini.backend = get_backend_from_hash(name)
end

# Select the best backend, returns backend config.
def decide_backend
string_or_class = catch(:done) do
BACKENDS.keys.each do |name|
begin
result = get_backend name
result = get_backend_from_hash name
throw(:done, result)
rescue LoadError
end
Expand All @@ -84,7 +90,7 @@ def ary

# Set XmlMini backend when this file loads.
begin
self.backend = get_backend FM_CONFIG[:backend]
self.backend = get_backend_from_hash FM_CONFIG[:backend]
rescue
self.backend = decide_backend
end
Expand Down

0 comments on commit dc4134d

Please sign in to comment.