status-manager 0.8.3 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48d814f9533ce9e07a91e5b07510619551f1f2c3
4
- data.tar.gz: 53f76760593ce0b882f30e2a078e62e267704e5b
3
+ metadata.gz: 395030fa5ab54f040bca94d41057376e3ab925f7
4
+ data.tar.gz: 01c3b7bfd0341680a6ae21d383dc84e680ffcfac
5
5
  SHA512:
6
- metadata.gz: b1c682886b99ab3fc04eb6c992bdfda67b2b1e697ce2fd3429d48b264bdc7c218e4e0da56254ed0f08bd2b4d3c56d7dd300da501454fbc08a4d7f3551a0d4df5
7
- data.tar.gz: 240863dab42f535ebec142e2cb1ef695018300358aba18b7bbf71df99f08bb9221a635b3ebd1a38737f9438f0d9a72a2311e0fc7fa963a4c927b0d3dd4c32ef0
6
+ metadata.gz: b1bdef37a2ea4b70c887926e2aa709ae969575836c57a816ac9a119a0d9bd3acb0d97f8c2d6dd52875aad7880c82ec066daad36a99ed5610156f14029c3aad88
7
+ data.tar.gz: 53d592551c7d446b1d71a4a84b54389ad627fabfaa6bca75029badccf0638d5c416b3b15bd25c8c959c99086b032fd925906f7552817967ee82ece5e153b67a5
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ *.sqlite3
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -15,3 +16,4 @@ spec/reports
15
16
  test/tmp
16
17
  test/version_tmp
17
18
  tmp
19
+ coverage
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem "rake"
5
+ gem "simplecov", :require => false, :group => :test
6
+
@@ -14,7 +14,23 @@ module StatusManager
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- def attr_as_status (status_attribute, status_sets={})
17
+ def attr_as_status(status_attribute, status_sets, options={})
18
+ register_status_sets(status_attribute, status_sets)
19
+ status_group(status_attribute, options[:group]) if options.key?(:group)
20
+ set_default_status(status_attribute, options[:default]) if options.key?(:default)
21
+ end
22
+
23
+ def register_status_sets(status_attribute, status_sets, default_status=nil)
24
+ # if status_sets parameter is array.
25
+ # ex) register_status_sets(status, [:onsale, :soldout, :reject])
26
+ raise "Not defined statuses" if status_sets.empty?
27
+ if status_sets.instance_of?(Array)
28
+ raise Exception, "#{status_attribute} column type must be :string or :text in this case, if you want to specify column value use Hash class" unless [:string, :text].include?(self.columns_hash[status_attribute.to_s].type)
29
+ _status_sets = {}
30
+ status_sets.each { |status_set| _status_sets[status_set] = status_set.to_s }
31
+ status_sets = _status_sets
32
+ end
33
+
18
34
  status_store = StatusStore.new(status_attribute, status_sets)
19
35
  status_store_list.add(status_store)
20
36
 
@@ -90,6 +106,12 @@ module StatusManager
90
106
  end
91
107
  end
92
108
 
109
+ def set_default_status(status_attribute, status)
110
+ before_create do |obj|
111
+ obj.send("#{status_attribute.to_s}=", obj.class.send(status_attribute.to_s.pluralize)[status]) unless obj.send(status_attribute.to_s)
112
+ end
113
+ end
114
+
93
115
  def status_store_list
94
116
  if self.class_variable_defined?(:@@status_store_list)
95
117
  self.class_variable_get(:@@status_store_list)
@@ -97,6 +119,7 @@ module StatusManager
97
119
  self.class_variable_set(:@@status_store_list, StatusStoreList.new)
98
120
  end
99
121
  end
122
+
100
123
  end
101
124
  end
102
125
 
@@ -1,3 +1,3 @@
1
1
  module StatusManager
2
- VERSION = '0.8.3'
2
+ VERSION = '0.8.5'
3
3
  end
@@ -2,11 +2,18 @@ class Product < ActiveRecord::Base
2
2
  attr_accessible :title, :sale_status
3
3
 
4
4
  # acts_as_status :status_attribute in model, {:status_value => 'status_value that is saved in database'}
5
- attr_as_status :sale_status, :onsale => 'onsale', :reject => 'reject', :pending => 'pending', :soldout => 'soldout'
6
- status_group :sale_status, {
7
- :close => [:reject, :pending],
8
- :display => [:onsale, :soldout]
9
- }
5
+
6
+ # attr_as_status :sale_status, :onsale => 'onsale', :reject => 'reject', :pending => 'pending', :soldout => 'soldout'
7
+ # attr_as_status :sale_status, [:onsale, :reject, :pending, :soldout]
8
+
9
+ attr_as_status :sale_status,
10
+ [:onsale, :reject, :pending, :soldout],
11
+ :default => :onsale,
12
+ :group => {
13
+ :close => [:pending, :reject],
14
+ :open => [:soldout, :onsale],
15
+ :display => [:onsale, :soldout]
16
+ }
10
17
 
11
18
  before_status_update :sale_status, :close => :onsale do |product|
12
19
  puts "display #{product.title}"
@@ -3,6 +3,12 @@ require 'models/product'
3
3
 
4
4
  describe StatusManager do
5
5
 
6
+ it "should set default status" do
7
+ product = Product.new
8
+ product.save
9
+ product.should be_sale_status(:onsale)
10
+ end
11
+
6
12
  it "should check chages with hash" do
7
13
  product = Product.sale_status(:onsale).first
8
14
  product.should_not be_sale_status_changed
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  require 'active_record'
3
3
  require 'active_record/fixtures'
4
4
  require 'status-manager'
5
+ require 'simplecov'
5
6
 
6
7
  lib = File.expand_path(__dir__)
7
8
  ActiveRecord::Base.configurations = YAML::load_file("#{lib}/config/database.yml")['test']
@@ -13,3 +14,5 @@ ActiveRecord::Fixtures.create_fixtures 'spec/fixtures', 'products'
13
14
  RSpec.configure do |config|
14
15
 
15
16
  end
17
+
18
+ SimpleCov.start
@@ -6,7 +6,7 @@ require 'status-manager/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "status-manager"
8
8
  spec.version = StatusManager::VERSION
9
- spec.date = "2014-04-10"
9
+ spec.date = "2014-04-14"
10
10
  spec.authors = ["keepcosmos"]
11
11
  spec.email = ["keepcosmos@gmail.com"]
12
12
  spec.description = "ActiveRecord Model Status Manager"
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: status-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - keepcosmos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,8 +60,8 @@ files:
60
60
  - spec/config/schema.rb
61
61
  - spec/fixtures/products.yml
62
62
  - spec/models/product.rb
63
+ - spec/product1_spec.rb
63
64
  - spec/spec_helper.rb
64
- - spec/status-manager_spec.rb
65
65
  - status-manager.gemspec
66
66
  - status_manager_test.sqlite3
67
67
  homepage: https://github.com/keepcosmos/status-manager
@@ -94,5 +94,5 @@ test_files:
94
94
  - spec/config/schema.rb
95
95
  - spec/fixtures/products.yml
96
96
  - spec/models/product.rb
97
+ - spec/product1_spec.rb
97
98
  - spec/spec_helper.rb
98
- - spec/status-manager_spec.rb