Class: ExtraLoop::Storage::Model

Inherits:
Ohm::Model
  • Object
show all
Extended by:
IdKey
Defined in:
lib/extraloop/redis-storage/model.rb

Overview

Meta model designed to keep track of what types of records are associated to a Scraping session object.

Constant Summary

Constants included from IdKey

IdKey::ID_FORMAT, IdKey::KEY_SEPARATOR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IdKey

[], prefix

Class Method Details

.[](id, attributes = {}) ⇒ Object



10
11
12
13
14
# File 'lib/extraloop/redis-storage/model.rb', line 10

def [](id, attributes={})
  id = id.to_s.gsub(prefix, '')
  raise ArgumentError.new "model name must be a constant" unless ('A'..'Z').include?(id[0])
  send('_[]', id, attributes)
end

._[]Object



8
# File 'lib/extraloop/redis-storage/model.rb', line 8

alias_method :'_[]', :[]

.prefixObject



16
17
18
# File 'lib/extraloop/redis-storage/model.rb', line 16

def prefix
  ""
end

Instance Method Details

#to_hashObject



21
22
23
24
25
# File 'lib/extraloop/redis-storage/model.rb', line 21

def to_hash
  super.merge(attributes.reduce({}) { |memo, attribute| 
    memo.merge(attribute => send(attribute)) 
  })
end

#to_yamlObject



26
27
28
# File 'lib/extraloop/redis-storage/model.rb', line 26

def to_yaml
  to_hash.to_yaml
end