Class: ObjectCache::Reader
- Inherits:
-
Object
- Object
- ObjectCache::Reader
- Defined in:
- lib/object_cache/object_reader.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Instance Method Summary collapse
-
#grouped_objects ⇒ Object
creates a hashed key-value by the class names.
-
#initialize(source) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(source) ⇒ Reader
Returns a new instance of Reader.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/object_cache/object_reader.rb', line 8 def initialize(source) case source when nil raise Errno::ENOENT, "No file specified as ObjectCache source" when Hash self.hash = source else self.hash = YAML.load(ERB.new(open(source).read).result).to_hash end end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
6 7 8 |
# File 'lib/object_cache/object_reader.rb', line 6 def hash @hash end |
Instance Method Details
#grouped_objects ⇒ Object
creates a hashed key-value by the class names
22 23 24 25 26 27 28 29 |
# File 'lib/object_cache/object_reader.rb', line 22 def grouped_objects product = {} hash.each do |key,value| product[value["name"]] ||= [] product[value["name"]] << [key, value["id"]] end product end |