Sha256: 15c4ce5c83f42ab7c5d9a2f3561b4204865879d7198e4451246d688a2ceb0592
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
require 'active_support/concern' require 'active_model/naming' require 'active_model/attribute_methods' module Circuit module Storage module MemoryModel extend ActiveSupport::Concern include ActiveModel::AttributeMethods include Compatibility::ActiveModel31 attr_reader :attributes, :errors attr_accessor :name included do extend ActiveModel::Naming class_attribute :all self.all = Array.new end module ClassMethods def setup_attributes(*attrs) attribute_method_suffix '?' attribute_method_suffix '=' define_attribute_methods attrs.collect(&:to_sym) end end def attributes=(hash) @attributes = hash.with_indifferent_access end def save! self.save ? true : raise("Invalid %s: %p"%[self.class, self.errors]) end def persisted? @persisted end def persisted!(val=true) @persisted = val end def eql?(obj) obj.instance_of?(self.class) && obj.attributes == self.attributes end protected def attribute(key) attributes[key] end def attribute=(key, val) attributes[key] = val end def attribute?(attr) !attributes[attr.to_sym].blank? end def memory_model_setup @persisted = false @attributes = HashWithIndifferentAccess.new @errors = ActiveModel::Errors.new(self) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
circuit-0.2.0 | lib/circuit/storage/memory_model.rb |