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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile +2 -0
- data/lib/status-manager.rb +24 -1
- data/lib/status-manager/version.rb +1 -1
- data/spec/models/product.rb +12 -5
- data/spec/{status-manager_spec.rb → product1_spec.rb} +6 -0
- data/spec/spec_helper.rb +3 -0
- data/status-manager.gemspec +1 -1
- data/status_manager_test.sqlite3 +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395030fa5ab54f040bca94d41057376e3ab925f7
|
4
|
+
data.tar.gz: 01c3b7bfd0341680a6ae21d383dc84e680ffcfac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1bdef37a2ea4b70c887926e2aa709ae969575836c57a816ac9a119a0d9bd3acb0d97f8c2d6dd52875aad7880c82ec066daad36a99ed5610156f14029c3aad88
|
7
|
+
data.tar.gz: 53d592551c7d446b1d71a4a84b54389ad627fabfaa6bca75029badccf0638d5c416b3b15bd25c8c959c99086b032fd925906f7552817967ee82ece5e153b67a5
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/status-manager.rb
CHANGED
@@ -14,7 +14,23 @@ module StatusManager
|
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
|
-
def attr_as_status
|
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
|
|
data/spec/models/product.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/status-manager.gemspec
CHANGED
@@ -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-
|
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"
|
data/status_manager_test.sqlite3
CHANGED
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.
|
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-
|
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
|