Class: ExtraLoop::Storage::Model

Inherits:
Ohm::Model
  • Object
show all
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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](id) ⇒ Object



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

def self.[](id)
  raise ArgumentError.new "model Id should be capitalized" unless id.to_s[0] =~ /[A-Z]/
  super(id) || create(:id => id)
end

Instance Method Details

#to_hashObject



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

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

#to_yamlObject



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

def to_yaml
  to_hash.to_yaml
end