Sha256: 04fcd8a9ea26234680937dddd5c1dbd68fafc07cad25d5b8b69ac99704dd0521

Contents?: true

Size: 817 Bytes

Versions: 2

Compression:

Stored size: 817 Bytes

Contents

class Product < ActiveRecord::Base
	attr_accessible :title, :sale_status

	# acts_as_status :status_attribute in model, {:status_value => 'status_value that is saved in database'}
	attr_as_status :sale_status, :onsale => 'onsale', :reject => 'reject', :pending => 'pending', :soldout => 'soldout'
	status_group :sale_status, {
		:close => [:reject, :pending],
		:display => [:onsale, :soldout]
	}

	before_status_update :sale_status, :close => :onsale do |product|
		puts "display #{product.title}"
	end

	after_status_update :sale_status, :pending => :onsale do |product|
		puts "release #{product.title}"
	end

	after_status_update :sale_status, :onsale do |product|
		puts "onsale #{product.title}"
	end

	after_status_update :sale_status, :display => :close do |product|
		puts "close #{product.title}"
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
status-manager-0.8.3 spec/models/product.rb
status-manager-0.8.1 test/models/product.rb