chirrin-chirrion 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +14 -3
- data/chirrin-chirrion.gemspec +4 -0
- data/lib/chirrin-chirrion.rb +69 -6
- data/lib/chirrin-chirrion/database_adapters/redis_adapter.rb +80 -14
- data/lib/chirrin-chirrion/errors.rb +5 -0
- data/lib/chirrin-chirrion/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d34f28e02a066217d57127952a738c16a063633
|
4
|
+
data.tar.gz: 2e994e2b1944278d18d92d14d2b58b9eeec512ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b24a43447ce15121881e6aaecaf294a4d984ebb07af6abb594825e50cbe4dc8ef2e8bc456d0a54417ffbfb2ceddc50ecde6a494695388099d6e357d61c79722
|
7
|
+
data.tar.gz: abc8efa436aa6f7e91a32fec113b2652a7e5aeb4ef6f974d53be90115ffe92bd2aa5b28eacc9bccb6af0038ab340744354b3e13324c3c694eb48f60bdd2c2d0b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes of the project you will find here.
|
3
|
+
|
4
|
+
## [0.2.0] - 2015-03-30
|
5
|
+
### Changed
|
6
|
+
- Redis adaper inside of the module ChirrinChirrion::DatabaseAdapters
|
7
|
+
- Redis adaper changed to manage togles inside a Hash.
|
8
|
+
- Now is possible to define a description for the toggle, which can let other people know what this toggle does
|
9
|
+
- Way to register toggles, but keep them inactives.
|
10
|
+
|
11
|
+
## [0.1.0] - 2015-03-23
|
12
|
+
### Changed
|
13
|
+
- First release of the gem.
|
14
|
+
- Simple way to add and remove toggles. Toggles in the Redis database are active, and are inactive if there is no toggle in the database.
|
15
|
+
methods to check if toggle is active, inactive or give procs to gem defines which proc will be executed when the toggle is active and inactive.
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Where there is a magic object which the the key word 'chirrin' gives a new thing
|
|
7
7
|
|
8
8
|
## Intall
|
9
9
|
|
10
|
-
gem install chirrin-
|
10
|
+
gem install chirrin-chirrion
|
11
11
|
|
12
12
|
## How to use
|
13
13
|
|
@@ -15,13 +15,14 @@ Where there is a magic object which the the key word 'chirrin' gives a new thing
|
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
require 'chirrin-chirrion'
|
18
|
-
|
18
|
+
redis_connection = Redis.new
|
19
|
+
redis_adapter = RedisAdapter.new(redis_connection)
|
19
20
|
ChirrinChirrion.config(database_adapter: redis_adapter)
|
20
21
|
```
|
21
22
|
|
22
23
|
### Adding a toggle
|
23
24
|
```ruby
|
24
|
-
ChirrinChirrion.add_toggle('new_user_register_validation')
|
25
|
+
ChirrinChirrion.add_toggle('new_user_register_validation', {active: true, description: 'When this is active, gender, age and phone number are not required'})
|
25
26
|
```
|
26
27
|
|
27
28
|
### Removing a toggle
|
@@ -29,6 +30,16 @@ ChirrinChirrion.add_toggle('new_user_register_validation')
|
|
29
30
|
ChirrinChirrion.remove_toggle('new_user_register_validation')
|
30
31
|
```
|
31
32
|
|
33
|
+
### Making a toggle active
|
34
|
+
```ruby
|
35
|
+
ChirrinChirrion.chirrin('new_user_register_validation')
|
36
|
+
```
|
37
|
+
|
38
|
+
### Making a toggle inactive
|
39
|
+
```ruby
|
40
|
+
ChirrinChirrion.chirrion('new_user_register_validation')
|
41
|
+
```
|
42
|
+
|
32
43
|
### Using a toggle with if else
|
33
44
|
```ruby
|
34
45
|
if ChirrinChirrion.chirrin?('new_user_register_validation')
|
data/chirrin-chirrion.gemspec
CHANGED
@@ -22,8 +22,12 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
23
|
end
|
24
24
|
|
25
|
+
#Development dependencies
|
25
26
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
26
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
28
|
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
28
29
|
spec.add_development_dependency 'redis', '~> 3.2.1'
|
30
|
+
|
31
|
+
#Runtime dependencies
|
32
|
+
spec.add_runtime_dependency 'json', '~> 1.8.2'
|
29
33
|
end
|
data/lib/chirrin-chirrion.rb
CHANGED
@@ -1,31 +1,94 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'chirrin-chirrion/version'
|
2
|
+
require 'chirrin-chirrion/errors'
|
3
|
+
require 'chirrin-chirrion/database_adapters/redis_adapter'
|
4
|
+
require 'json'
|
3
5
|
|
4
6
|
module ChirrinChirrion
|
7
|
+
|
8
|
+
# Defines the configuration for Chirrin Chirrion.
|
9
|
+
# The config are:
|
10
|
+
# - database_adapter, an adapter which wrap the database management to provide the correct service
|
11
|
+
#
|
12
|
+
# redis_connection = Redis.new
|
13
|
+
# redis_adapter = RedisAdapter.new(redis_connection)
|
14
|
+
# ChirrinChirrion.config(database_adapter: redis_adapter)
|
15
|
+
#
|
5
16
|
def self.config(options)
|
6
17
|
@database_adapter = options[:database_adapter]
|
7
18
|
end
|
8
19
|
|
20
|
+
# Private mehtod which returns the Chirrin Chirrion config
|
21
|
+
#
|
9
22
|
def self.database_adapter
|
10
23
|
@database_adapter
|
11
24
|
end
|
12
25
|
|
13
|
-
|
14
|
-
|
26
|
+
# Adds a toggle to the database
|
27
|
+
#
|
28
|
+
# ChirrinChirrion.add_toggle('my_active_feature')
|
29
|
+
# ChirrinChirrion.add_toggle('my_inactive_feature')
|
30
|
+
#
|
31
|
+
def self.add_toggle(toggle_name, toggle_info = {})
|
32
|
+
database_adapter.add_toggle(toggle_name, toggle_info)
|
15
33
|
end
|
16
34
|
|
35
|
+
# Removes a toggle from the database
|
36
|
+
#
|
37
|
+
# ChirrinChirrion.remove_toggle('my_active_feature')
|
38
|
+
# ChirrinChirrion.remove_toggle('my_inactive_feature')
|
39
|
+
#
|
17
40
|
def self.remove_toggle(toggle_name)
|
18
41
|
database_adapter.remove_toggle(toggle_name)
|
19
42
|
end
|
20
43
|
|
44
|
+
# Makes a toggle active (the toggle must already be registered)
|
45
|
+
#
|
46
|
+
# ChirrinChirrion.chirrin('my_inactive_feature')
|
47
|
+
# ChirrinChirrion.chirrin?('my_inactive_feature') #=> true
|
48
|
+
#
|
49
|
+
def self.chirrin(toggle_name)
|
50
|
+
database_adapter.activate(toggle_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Makes a toggle inactive
|
54
|
+
#
|
55
|
+
# ChirrinChirrion.chirrion('my_active_feature')
|
56
|
+
# ChirrinChirrion.chirrion?('my_active_feature') #=> false
|
57
|
+
#
|
58
|
+
def self.chirrion(toggle_name)
|
59
|
+
database_adapter.inactivate(toggle_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Checks if a toggle active (the toggle must already be registered)
|
63
|
+
#
|
64
|
+
# ChirrinChirrion.chirrin?('my_active_feature') #=> true
|
65
|
+
# ChirrinChirrion.chirrin?('my_inactive_feature') #=> false
|
66
|
+
# ChirrinChirrion.chirrin?('my_unregistered_toggle') #=> false
|
67
|
+
#
|
21
68
|
def self.chirrin?(toggle_name)
|
22
|
-
database_adapter.
|
69
|
+
database_adapter.active?(toggle_name)
|
23
70
|
end
|
24
71
|
|
72
|
+
# Checks if a toggle inactive
|
73
|
+
#
|
74
|
+
# ChirrinChirrion.chirrion?('my_active_feature') #=> false
|
75
|
+
# ChirrinChirrion.chirrion?('my_inactive_feature') #=> true
|
76
|
+
# ChirrinChirrion.chirrin?('my_unregistered_toggle') #=> true
|
77
|
+
#
|
25
78
|
def self.chirrion?(toggle_name)
|
26
|
-
|
79
|
+
database_adapter.inactive?(toggle_name)
|
27
80
|
end
|
28
81
|
|
82
|
+
# Executes determinated action if the toggle chirrin, if not executes another achtion
|
83
|
+
#
|
84
|
+
# ChirrinChirrion.chirrin('mult_for_2')
|
85
|
+
# ten_numbers = (1..10).to_a
|
86
|
+
# actiction_for_chirrin = lambda { ten_numbers.map{|number| number * 2 } }
|
87
|
+
# actiction_for_chirrion = lambda { ten_numbers.map{|number| number * 4 } }
|
88
|
+
# ChirrinChirrion.chirrin_chirrion('mult_for_2', action_for_chirrin, action_for_chirrion) #=> [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]
|
89
|
+
# ChirrinChirrion.chirrin('mult_for_2')
|
90
|
+
# ChirrinChirrion.chirrin_chirrion('mult_for_2', action_for_chirrin, action_for_chirrion) #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
|
91
|
+
#
|
29
92
|
def self.chirrin_chirrion(toggle_name, for_chirrin, for_chirrion)
|
30
93
|
if chirrin?(toggle_name)
|
31
94
|
for_chirrin.respond_to?(:call) ? for_chirrin.call : for_chirrin
|
@@ -1,20 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module ChirrinChirrion
|
2
|
+
module DatabaseAdapters
|
3
|
+
class RedisAdapter
|
4
|
+
TOGGLES_HASH_KEY = 'chirrin-chirrion-toggles'
|
5
|
+
attr_reader :redis_database
|
6
|
+
private :redis_database
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
def initialize(redis_database)
|
9
|
+
@redis_database = redis_database
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
# Adds a toggle to the database:
|
13
|
+
#
|
14
|
+
# redis_adapter.add_toggle('my_active_feature', {active: true, description: 'What other people must know to understand what this toggle activates'})
|
15
|
+
# redis_adapter.add_toggle('my_inactive_feature', {description: 'What other people must know to understand what this toggle activates'})
|
16
|
+
# redis_adapter.add_toggle('my_inactive_feature')
|
17
|
+
#
|
18
|
+
def add_toggle(toggle_name, toggle_info = {})
|
19
|
+
toggle_info[:active] ||= false
|
20
|
+
redis_database.hset(TOGGLES_HASH_KEY, toggle_name, toggle_info.to_json)
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
# Removes a toggle from the database:
|
26
|
+
#
|
27
|
+
# redis_adapter.remove_toggle('my_active_feature')
|
28
|
+
# redis_adapter.remove_toggle('my_inactive_feature')
|
29
|
+
#
|
30
|
+
def remove_toggle(toggle_name)
|
31
|
+
redis_database.hdel(TOGGLES_HASH_KEY, toggle_name)
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
# Makes a toggle, existent or not, active:
|
37
|
+
#
|
38
|
+
# redis_adapter.activate('my_feature')
|
39
|
+
#
|
40
|
+
def activate(toggle_name)
|
41
|
+
toggle_info = get_toggle_info(toggle_name)
|
42
|
+
raise ChirrinChirrion::Errors::ToggleNotFound, "The toggle #{toggle_name} was not found" unless toggle_info
|
43
|
+
toggle_info['active'] = true
|
44
|
+
|
45
|
+
redis_database.hset(TOGGLES_HASH_KEY, toggle_name, toggle_info.to_json)
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
# Makes a toggle, existent or not, iactive:
|
51
|
+
#
|
52
|
+
# redis_adapter.inactivate('my_feature')
|
53
|
+
#
|
54
|
+
def inactivate(toggle_name)
|
55
|
+
toggle_info = get_toggle_info(toggle_name)
|
56
|
+
raise ChirrinChirrion::Errors::ToggleNotFound, "The toggle #{toggle_name} was not found" unless toggle_info
|
57
|
+
toggle_info['active'] = false
|
58
|
+
|
59
|
+
redis_database.hset(TOGGLES_HASH_KEY, toggle_name, toggle_info.to_json)
|
60
|
+
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def active?(toggle_name)
|
65
|
+
toggle_info = redis_database.hget(TOGGLES_HASH_KEY, toggle_name)
|
66
|
+
return false unless toggle_info
|
67
|
+
toggle_info = JSON.parse(toggle_info)
|
68
|
+
|
69
|
+
toggle_info['active'].eql?(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
def inactive?(toggle_name)
|
73
|
+
!active?(toggle_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def get_toggle_info(toggle_name)
|
79
|
+
toggle_info = redis_database.hget(TOGGLES_HASH_KEY, toggle_name)
|
80
|
+
return nil unless toggle_info
|
16
81
|
|
17
|
-
|
18
|
-
|
82
|
+
JSON.parse(toggle_info)
|
83
|
+
end
|
84
|
+
end
|
19
85
|
end
|
20
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chirrin-chirrion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Vicenzo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.2.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.8.2
|
69
83
|
description: Chirrin for the new code apears, Chirrion for the new code desapears
|
70
84
|
(by Chapolim)
|
71
85
|
email:
|
@@ -77,6 +91,7 @@ files:
|
|
77
91
|
- ".gitignore"
|
78
92
|
- ".rspec"
|
79
93
|
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
80
95
|
- Gemfile
|
81
96
|
- LICENSE
|
82
97
|
- README.md
|
@@ -86,6 +101,7 @@ files:
|
|
86
101
|
- chirrin-chirrion.gemspec
|
87
102
|
- lib/chirrin-chirrion.rb
|
88
103
|
- lib/chirrin-chirrion/database_adapters/redis_adapter.rb
|
104
|
+
- lib/chirrin-chirrion/errors.rb
|
89
105
|
- lib/chirrin-chirrion/version.rb
|
90
106
|
homepage: https://github.com/bvicenzo/chirrin-chirrion
|
91
107
|
licenses: []
|