class ActivePStore::Base

Public Class Methods

all() click to toggle source
# File lib/active_pstore/base.rb, line 36
def all
  use_connection {|connection|
    ActivePStore::Collection.new(connection[self.pstore_key] || [])
  }
end
build(attributes = nil)
Alias for: new
create(attributes = nil, &block) click to toggle source
# File lib/active_pstore/base.rb, line 42
def create(attributes = nil, &block)
  if attributes.is_a?(Array)
    attributes.map {|attr| create(attr, &block) }
  else
    build(attributes, &block).tap do |obj|
      obj.save
    end
  end
end
find_or_create_by(attributes, &block) click to toggle source
# File lib/active_pstore/base.rb, line 56
def find_or_create_by(attributes, &block)
  find_by(attributes) || create(attributes, &block)
end
find_or_initialize_by(attributes, &block) click to toggle source
# File lib/active_pstore/base.rb, line 60
def find_or_initialize_by(attributes, &block)
  find_by(attributes) || new(attributes, &block)
end
first_or_create(attributes = nil, &block) click to toggle source
# File lib/active_pstore/base.rb, line 52
def first_or_create(attributes = nil, &block)
  first || create(attributes, &block)
end
new(attributes = nil) { |self| ... } click to toggle source
# File lib/active_pstore/base.rb, line 19
def initialize(attributes = nil)
  if attributes.present?
    attributes.each do |attr, val|
      if respond_to? "#{attr}=".to_sym
        self.public_send("#{attr}=", val)
      else
        raise "undefined method `#{attr}='"
      end
    end
  end

  yield self if block_given?
end
Also aliased as: build