Module: Hipbot::Storages::Hash::ClassMethods

Includes:
Cache
Defined in:
lib/hipbot/storages/hash.rb

Instance Method Summary collapse

Methods included from Cache

#_cache

Instance Method Details

#allObject



46
47
48
# File 'lib/hipbot/storages/hash.rb', line 46

def all
  collection.values
end

#create(params) ⇒ Object



50
51
52
# File 'lib/hipbot/storages/hash.rb', line 50

def create params
  collection[params[:id]] = new(params)
end

#find(id) ⇒ Object



70
71
72
# File 'lib/hipbot/storages/hash.rb', line 70

def find id
  where(id: id).first
end

#find_by(params) ⇒ Object



66
67
68
# File 'lib/hipbot/storages/hash.rb', line 66

def find_by params
  where(params).first
end

#find_or_create_by(params) ⇒ Object



58
59
60
# File 'lib/hipbot/storages/hash.rb', line 58

def find_or_create_by params
  find_by(params) || create(params)
end

#find_or_initialize_by(params) ⇒ Object



62
63
64
# File 'lib/hipbot/storages/hash.rb', line 62

def find_or_initialize_by params
  find_by(params) || self.new(params)
end

#where(param) ⇒ Object



74
75
76
77
78
# File 'lib/hipbot/storages/hash.rb', line 74

def where param
  collection.values.select do |item|
    param.all?{ |k, v| item.attributes[k] == v }
  end
end