lib/xamplr/persister.rb in xamplr-1.9.13 vs lib/xamplr/persister.rb in xamplr-1.9.14
- old
+ new
@@ -70,21 +70,13 @@
end
has_changed(xampl) if xampl.is_changed
end
def has_changed(xampl)
- #raise XamplException.new(:live_across_rollback) if @rolled_back
- # puts "!!!! has_changed #{xampl} #{xampl.get_the_index} -- persist required: #{xampl.persist_required}"
if xampl.persist_required && xampl.is_changed then
- unless self == xampl.persister
- raise MixedPersisters.new(xampl.persister, self)
- end
+ raise MixedPersisters.new(xampl.persister, self) unless self == xampl.persister
@changed[xampl] = xampl
-# puts "!!!! change recorded ==> #{@changed.size}/#{count_changed} #{@changed.object_id} !!!!"
- # @changed.each{ | thing, ignore |
- # puts " changed: #{thing}, index: #{thing.get_the_index}, changed: #{thing.is_changed}"
- # }
end
end
def has_not_changed(xampl)
# puts "!!!! has_not_changed #{xampl} #{xampl.get_the_index} -- in @changed: #{nil != @changed[xampl]}"
@@ -130,37 +122,29 @@
new_xampl.pid = pid
@@persister.introduce(new_xampl)
end
def represent(xampl, mentions=[])
- #puts "REPRESENT #{xampl} load needed: #{xampl.load_needed}"
- # return nil if xampl.load_needed
- rep = nil
- case xampl.default_persister_format || @format
- when nil, :xml_format then
- rep = xampl.persist("", mentions)
- when :ruby_format then
- rep = xampl.to_ruby(mentions)
- end
+ rep = xampl.persist("", mentions)
return rep
rescue => e
msg = "Failed to represent #{ xampl } due to: #{ e }"
puts msg
puts e.backtrace
raise msg
end
def realise(representation, target=nil)
- # Normally we'd expect to see the representation in the @format format, but
- # that isn't necessarily the case. Try to work out what the format might be...
-
- #TODO -- this is a bit brutal, but it should work (it is the rule is that this is supposed to be UTF-8)
+ # This is a bit brutal, but it works (and, anyway, it *is* the rule is that this is supposed to be UTF-8)
representation_fixed = representation.encode('UTF-8', :invalid => :replace, :undef => :replace)
-# puts "#{ ::File.basename __FILE__ }:#{ __LINE__ } [#{__method__}] ENCODING: #{ representation.encoding } -> #{ representation_fixed.encoding }"
xampl = nil
- if representation_fixed =~ /^</ then
+
+ # These days 'new' representations can only be XML. Historically it could have been Ruby. Check the
+ # representations (quickly) and choose appropriately.
+ if '<' == representation_fixed[0] then
+ # well it isn't ruby, so it must be XML. Of course this means no leading whitespace, which happens to be true.
xampl = XamplObject.realise_from_xml_string(representation_fixed, target)
else
xampl = XamplObject.from_ruby(representation_fixed, target)
end
return xampl.note_realised
@@ -362,15 +346,16 @@
rescue
# Well. No Tokyo Cabinet.
end
begin
- if require 'mongo' then
- require "xamplr/persisters/mongo"
+ if require 'redis' then
+ require 'weakref'
+ require "xamplr/persisters/redis"
end
rescue LoadError => e
- # Well. No MongoDB.
+ # Well. No redis.
rescue
- # Well. No MongoDB.
+ # Well. No redis.
end
end