Sha256: b00e4efb3b9fbffa76cd7d9c7ceeac2bf2989436edbcda50068a5956056d52ee

Contents?: true

Size: 677 Bytes

Versions: 7

Compression:

Stored size: 677 Bytes

Contents

require 'active_model'
require 'active_attr'

class ActiveMimic
  extend ActiveModel::Callbacks
  extend ActiveModel::Naming
  include ActiveModel::Serialization
  include ActiveAttr::Attributes
  include ActiveAttr::MassAssignment
  
  attribute :id
  attribute :type
  
  define_model_callbacks :save
  define_model_callbacks :destroy
  
  def self.create(attrs)
    new(attrs).tap(&:save)
  end
  
  def type
    self.class.to_s
  end
  
  def save
    self.id = self.class.next_id
    run_callbacks :save do
      true
    end
  end
  
  def destroy
    run_callbacks :destroy do
      true
    end
  end
  
  def self.next_id
    @next_id ||= 0
    @next_id += 1
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
activesearch-0.0.12 spec/spec_helper.rb
activesearch-0.0.11 spec/spec_helper.rb
activesearch-0.0.10 spec/spec_helper.rb
activesearch-0.0.9 spec/spec_helper.rb
activesearch-0.0.8 spec/spec_helper.rb
activesearch-0.0.7 spec/spec_helper.rb
activesearch-0.0.6 spec/spec_helper.rb