summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/rails
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/util/rails')
-rw-r--r--lib/puppet/util/rails/cache_accumulator.rb98
-rw-r--r--lib/puppet/util/rails/collection_merger.rb26
-rw-r--r--lib/puppet/util/rails/reference_serializer.rb52
3 files changed, 88 insertions, 88 deletions
diff --git a/lib/puppet/util/rails/cache_accumulator.rb b/lib/puppet/util/rails/cache_accumulator.rb
index 7c59a5d3f..4b3717f79 100644
--- a/lib/puppet/util/rails/cache_accumulator.rb
+++ b/lib/puppet/util/rails/cache_accumulator.rb
@@ -1,65 +1,65 @@
require 'puppet/util'
module Puppet::Util::CacheAccumulator
- def self.included(klass)
- klass.extend ClassMethods
- end
+ def self.included(klass)
+ klass.extend ClassMethods
+ end
- class Base
- attr_reader :klass, :attribute
+ class Base
+ attr_reader :klass, :attribute
- def initialize(klass, attribute)
- @klass = klass
- @attribute = attribute
- @find_or_create = "find_or_create_by_#{@attribute.to_s}".intern
- end
+ def initialize(klass, attribute)
+ @klass = klass
+ @attribute = attribute
+ @find_or_create = "find_or_create_by_#{@attribute.to_s}".intern
+ end
- def store
- @store || reset
- end
+ def store
+ @store || reset
+ end
- def reset
- @store = {}
- end
+ def reset
+ @store = {}
+ end
- def find(*keys)
- result = nil
- if keys.length == 1
- result = store[keys[0]] ||= @klass.send(@find_or_create, *keys)
- else
- found, missing = keys.partition {|k| store.include? k}
- result = found.length
- result += do_multi_find(missing) if missing.length > 0
- end
- result
- end
+ def find(*keys)
+ result = nil
+ if keys.length == 1
+ result = store[keys[0]] ||= @klass.send(@find_or_create, *keys)
+ else
+ found, missing = keys.partition {|k| store.include? k}
+ result = found.length
+ result += do_multi_find(missing) if missing.length > 0
+ end
+ result
+ end
- def do_multi_find(keys)
- result = 0
- @klass.find(:all, :conditions => {@attribute => keys}).each do |obj|
- store[obj.send(@attribute)] = obj
- result += 1
- end
- result
- end
+ def do_multi_find(keys)
+ result = 0
+ @klass.find(:all, :conditions => {@attribute => keys}).each do |obj|
+ store[obj.send(@attribute)] = obj
+ result += 1
+ end
+ result
end
+ end
- module ClassMethods
- def accumulates(*attributes)
- attributes.each {|attrib| install_accumulator(attrib)}
- end
+ module ClassMethods
+ def accumulates(*attributes)
+ attributes.each {|attrib| install_accumulator(attrib)}
+ end
- def accumulators
- @accumulators ||= {}
- end
+ def accumulators
+ @accumulators ||= {}
+ end
- def install_accumulator(attribute)
- self.accumulators[attribute] = Base.new(self, attribute)
- module_eval %{
- def self.accumulate_by_#{attribute.to_s}(*keys)
- accumulators[:#{attribute.to_s}].find(*keys)
- end
- }
+ def install_accumulator(attribute)
+ self.accumulators[attribute] = Base.new(self, attribute)
+ module_eval %{
+ def self.accumulate_by_#{attribute.to_s}(*keys)
+ accumulators[:#{attribute.to_s}].find(*keys)
end
+ }
end
+ end
end
diff --git a/lib/puppet/util/rails/collection_merger.rb b/lib/puppet/util/rails/collection_merger.rb
index 3a28bb304..f95d3d3bd 100644
--- a/lib/puppet/util/rails/collection_merger.rb
+++ b/lib/puppet/util/rails/collection_merger.rb
@@ -1,17 +1,17 @@
module Puppet::Util::CollectionMerger
- def ar_hash_merge(db_hash, mem_hash, args)
- (db_hash.keys | mem_hash.keys).each do |key|
- if (db_hash[key] && mem_hash[key])
- # in both, update value
- args[:modify].call(db_hash[key], mem_hash[key])
- elsif (db_hash[key])
- # in db, not memory, delete from database
- args[:delete].call(db_hash[key])
- else
- # in mem, not in db, insert into the database
- args[:create].call(key, mem_hash[key])
- end
- end
+ def ar_hash_merge(db_hash, mem_hash, args)
+ (db_hash.keys | mem_hash.keys).each do |key|
+ if (db_hash[key] && mem_hash[key])
+ # in both, update value
+ args[:modify].call(db_hash[key], mem_hash[key])
+ elsif (db_hash[key])
+ # in db, not memory, delete from database
+ args[:delete].call(db_hash[key])
+ else
+ # in mem, not in db, insert into the database
+ args[:create].call(key, mem_hash[key])
+ end
end
+ end
end
diff --git a/lib/puppet/util/rails/reference_serializer.rb b/lib/puppet/util/rails/reference_serializer.rb
index a23f2cbea..9beeb0048 100644
--- a/lib/puppet/util/rails/reference_serializer.rb
+++ b/lib/puppet/util/rails/reference_serializer.rb
@@ -1,32 +1,32 @@
module Puppet::Util::ReferenceSerializer
- def unserialize_value(val)
- case val
- when /^--- /
- YAML.load(val)
- when "true"
- true
- when "false"
- false
- else
- val
- end
+ def unserialize_value(val)
+ case val
+ when /^--- /
+ YAML.load(val)
+ when "true"
+ true
+ when "false"
+ false
+ else
+ val
end
+ end
- def serialize_value(val)
- case val
- when Puppet::Resource
- YAML.dump(val)
- when true, false
- # The database does this for us, but I prefer the
- # methods be their exact inverses.
- # Note that this means quoted booleans get returned
- # as actual booleans, but there doesn't appear to be
- # a way to fix that while keeping the ability to
- # search for parameters set to true.
- val.to_s
- else
- val
- end
+ def serialize_value(val)
+ case val
+ when Puppet::Resource
+ YAML.dump(val)
+ when true, false
+ # The database does this for us, but I prefer the
+ # methods be their exact inverses.
+ # Note that this means quoted booleans get returned
+ # as actual booleans, but there doesn't appear to be
+ # a way to fix that while keeping the ability to
+ # search for parameters set to true.
+ val.to_s
+ else
+ val
end
+ end
end