state_store 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -2
- data/README.md +6 -4
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/state_store/binary_store.rb +14 -4
- data/spec/spec_helper.rb +1 -0
- data/state_store.gemspec +9 -8
- metadata +29 -13
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -7,11 +7,11 @@ source "http://rubygems.org"
|
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
9
|
gem "rdoc", "~> 3.12"
|
10
|
-
gem "bundler", "~> 1.
|
10
|
+
gem "bundler", "~> 1.1.3"
|
11
11
|
gem "jeweler", "~> 1.8.3"
|
12
12
|
end
|
13
13
|
|
14
14
|
group :test do
|
15
|
-
gem "rspec", "~>2
|
15
|
+
gem "rspec", "~>2"
|
16
16
|
end
|
17
17
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# State store
|
2
|
+
[![Build Status](https://secure.travis-ci.org/kalifs/state_store.png?branch=master)](http://travis-ci.org/kalifs/state_store)
|
3
|
+
[![Gemnasium status](https://gemnasium.com/kalifs/state_store.png)](https://gemnasium.com/kalifs/state_store)
|
4
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kalifs/state_store)
|
2
5
|
|
3
6
|
## Installation
|
4
7
|
|
@@ -8,7 +11,7 @@
|
|
8
11
|
|
9
12
|
For Bundler add this in you Gemfile
|
10
13
|
|
11
|
-
`gem state_store, '~>0.0.
|
14
|
+
`gem state_store, '~>0.0.4'`
|
12
15
|
|
13
16
|
And then run
|
14
17
|
|
@@ -50,7 +53,7 @@ When you need to add new states and you keep want to previous states configurati
|
|
50
53
|
has_states :big,:bad, :in => :characteristic, :as => :nature
|
51
54
|
end
|
52
55
|
|
53
|
-
wolf =
|
56
|
+
wolf = Wolf.new()
|
54
57
|
wolf.nature = [:bad]
|
55
58
|
wolf.characteristic #=> 1
|
56
59
|
|
@@ -68,7 +71,6 @@ Then if you decide to add _hungry_ then you change states as shown below and tha
|
|
68
71
|
wolf.nature = [:bad]
|
69
72
|
wolf.characteristic #=> 1
|
70
73
|
wolf.nature = [:hungry,:bad]
|
71
|
-
wolf.nature << :bad
|
72
74
|
wolf.has_charasteristic?(:bad) #=> true
|
73
75
|
wolf.characteristic #=> 5
|
74
76
|
```
|
@@ -93,7 +95,7 @@ It is possible to alter states Array and changes storage attribute will be updat
|
|
93
95
|
apple.status #=> 5
|
94
96
|
```
|
95
97
|
|
96
|
-
But remember if you will modify `states` with other methods, like
|
98
|
+
But remember if you will modify `states` with other methods, like `<<` or `delete` or others changes will not be stored in status.
|
97
99
|
|
98
100
|
|
99
101
|
## Copyright
|
data/Rakefile
CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
|
|
17
17
|
gem.name = "state_store"
|
18
18
|
gem.homepage = "http://github.com/kalifs/state_store"
|
19
19
|
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{
|
21
|
-
gem.description = %Q{
|
20
|
+
gem.summary = %Q{Store Array of states in single Integer.}
|
21
|
+
gem.description = %Q{It allows to store pre-defined set of states in one attribute as Integer}
|
22
22
|
gem.email = "arturs.meisters@gmail.com"
|
23
23
|
gem.authors = ["Arturs Meisters"]
|
24
24
|
# dependencies defined in Gemfile
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'observer'
|
2
2
|
|
3
3
|
module StateStore
|
4
|
+
# This class provides convertation between Array to binary number and vice versa.
|
5
|
+
# Each instance of class have its own set of statuses.
|
4
6
|
class BinaryStore
|
5
7
|
attr_reader :statuses, :states, :total_positions
|
6
8
|
|
@@ -11,6 +13,7 @@ module StateStore
|
|
11
13
|
@total_positions = 2**@states-1
|
12
14
|
end
|
13
15
|
|
16
|
+
# Method receives value and return Array of statuses that matches current number.
|
14
17
|
def humanize(value)
|
15
18
|
raise ArgumentError.new("Out of range") if self.total_positions < value
|
16
19
|
humanized_array = value_to_statuses(value)
|
@@ -18,24 +21,31 @@ module StateStore
|
|
18
21
|
humanized_array
|
19
22
|
end
|
20
23
|
|
24
|
+
# Method receives Array of statuses and create binary number that respresents this status for store statuses set.
|
25
|
+
# =====Example
|
26
|
+
# store = StateStore.new([:read,:write,:execute])
|
27
|
+
# store.value([:read,:execute]) # will be interpreted as 101 or 5
|
28
|
+
# store.value([:write,:execute]) # will be interpreted as 011 or 3
|
21
29
|
def value(humanized_array)
|
22
30
|
raise ArgumentError.new("Out of range") if self.states < humanized_array.size
|
23
31
|
statuses_to_values(humanized_array)
|
24
32
|
end
|
25
33
|
|
34
|
+
# It receives status and value and check if given value match given status.
|
35
|
+
# =====Example
|
36
|
+
# store = StateStore.new([:read,:write,:execute])
|
37
|
+
# store.has_status?(:read,4) # will be false because 4 is for :write only
|
38
|
+
# store.has_status?(:read,5) # will be true because 5 is for :read and :execute
|
26
39
|
def has_status?(symbol,value)
|
27
40
|
human_array = humanize(value)
|
28
41
|
human_array.include?(symbol)
|
29
42
|
end
|
30
43
|
|
44
|
+
# This method receives index and state and will retrun status with given index if state is "1"
|
31
45
|
def index(index,state)
|
32
46
|
statuses[index] if state.to_s == "1"
|
33
47
|
end
|
34
48
|
|
35
|
-
def index_by_state(state)
|
36
|
-
statuses[state]
|
37
|
-
end
|
38
|
-
|
39
49
|
private
|
40
50
|
|
41
51
|
def value_to_statuses(value)
|
data/spec/spec_helper.rb
CHANGED
data/state_store.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "state_store"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Arturs Meisters"]
|
12
|
-
s.date = "2012-
|
13
|
-
s.description = "
|
12
|
+
s.date = "2012-08-30"
|
13
|
+
s.description = "It allows to store pre-defined set of states in one attribute as Integer"
|
14
14
|
s.email = "arturs.meisters@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
|
+
".travis.yml",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -37,24 +38,24 @@ Gem::Specification.new do |s|
|
|
37
38
|
s.homepage = "http://github.com/kalifs/state_store"
|
38
39
|
s.licenses = ["MIT"]
|
39
40
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = "1.8.
|
41
|
-
s.summary = "
|
41
|
+
s.rubygems_version = "1.8.24"
|
42
|
+
s.summary = "Store Array of states in single Integer."
|
42
43
|
|
43
44
|
if s.respond_to? :specification_version then
|
44
45
|
s.specification_version = 3
|
45
46
|
|
46
47
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
48
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
|
49
50
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
50
51
|
else
|
51
52
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.3"])
|
53
54
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
54
55
|
end
|
55
56
|
else
|
56
57
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
-
s.add_dependency(%q<bundler>, ["~> 1.
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.3"])
|
58
59
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
59
60
|
end
|
60
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,31 @@ dependencies:
|
|
21
21
|
version: '3.12'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.12'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: bundler
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
31
36
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
37
|
+
version: 1.1.3
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.3
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: jeweler
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,8 +53,13 @@ dependencies:
|
|
43
53
|
version: 1.8.3
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.3
|
62
|
+
description: It allows to store pre-defined set of states in one attribute as Integer
|
48
63
|
email: arturs.meisters@gmail.com
|
49
64
|
executables: []
|
50
65
|
extensions: []
|
@@ -54,6 +69,7 @@ extra_rdoc_files:
|
|
54
69
|
files:
|
55
70
|
- .document
|
56
71
|
- .rspec
|
72
|
+
- .travis.yml
|
57
73
|
- Gemfile
|
58
74
|
- Gemfile.lock
|
59
75
|
- LICENSE.txt
|
@@ -83,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
99
|
version: '0'
|
84
100
|
segments:
|
85
101
|
- 0
|
86
|
-
hash: -
|
102
|
+
hash: -2532584141716833600
|
87
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
104
|
none: false
|
89
105
|
requirements:
|
@@ -92,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
108
|
version: '0'
|
93
109
|
requirements: []
|
94
110
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.24
|
96
112
|
signing_key:
|
97
113
|
specification_version: 3
|
98
|
-
summary:
|
114
|
+
summary: Store Array of states in single Integer.
|
99
115
|
test_files: []
|