Class: ObjectCache::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/object_cache/object_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hashObject

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_objectsObject

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