Module: ChirrinChirrion
- Defined in:
- lib/chirrin-chirrion.rb,
lib/chirrin-chirrion/errors.rb,
lib/chirrin-chirrion/version.rb,
lib/chirrin-chirrion/database_adapters/redis_adapter.rb
Defined Under Namespace
Modules: DatabaseAdapters, Errors
Constant Summary collapse
- VERSION =
"0.5.1"
Class Method Summary collapse
-
.add_toggle(toggle_name, toggle_info = {}) ⇒ Object
Adds a toggle to the database.
-
.chirrin!(toggle_name) ⇒ Object
Makes a toggle active (the toggle must already be registered).
-
.chirrin?(toggle_name) ⇒ Boolean
Checks if a toggle active (the toggle must already be registered).
-
.chirrin_chirrion(toggle_name, for_chirrin, for_chirrion) ⇒ Object
Executes determinated action if the toggle chirrin, if not executes another achtion.
-
.chirrion!(toggle_name) ⇒ Object
Makes a toggle inactive.
-
.chirrion?(toggle_name) ⇒ Boolean
Checks if a toggle inactive.
-
.config(options) ⇒ Object
Defines the configuration for Chirrin Chirrion.
-
.list ⇒ Object
Returns a list of registered toggles The objects of the list respond to the following basic methods: - name - active - description.
-
.remove_toggle(toggle_name) ⇒ Object
Removes a toggle from the database.
Class Method Details
.add_toggle(toggle_name, toggle_info = {}) ⇒ Object
Adds a toggle to the database
ChirrinChirrion.add_toggle(‘my_active_feature’) ChirrinChirrion.add_toggle(‘my_inactive_feature’)
31 32 33 34 |
# File 'lib/chirrin-chirrion.rb', line 31 def self.add_toggle(toggle_name, toggle_info = {}) fail(ChirrinChirrion::Errors::ToggleIsRequired, 'Toggle name has not been sent.') if toggle_name.nil? || toggle_name.empty? database_adapter.add_toggle(toggle_name, toggle_info) end |
.chirrin!(toggle_name) ⇒ Object
Makes a toggle active (the toggle must already be registered)
ChirrinChirrion.chirrin!(‘my_inactive_feature’) ChirrinChirrion.chirrin?(‘my_inactive_feature’) #=> true
50 51 52 |
# File 'lib/chirrin-chirrion.rb', line 50 def self.chirrin!(toggle_name) database_adapter.activate!(toggle_name) end |
.chirrin?(toggle_name) ⇒ Boolean
Checks if a toggle active (the toggle must already be registered)
ChirrinChirrion.chirrin?(‘my_active_feature’) #=> true ChirrinChirrion.chirrin?(‘my_inactive_feature’) #=> false ChirrinChirrion.chirrin?(‘my_unregistered_toggle’) #=> false
69 70 71 |
# File 'lib/chirrin-chirrion.rb', line 69 def self.chirrin?(toggle_name) database_adapter.active?(toggle_name) end |
.chirrin_chirrion(toggle_name, for_chirrin, for_chirrion) ⇒ Object
Executes determinated action if the toggle chirrin, if not executes another achtion
ChirrinChirrion.chirrin(‘mult_for_2’) ten_numbers = (1..10).to_a actiction_for_chirrin = lambda { ten_numbers.map{|number| number * 2 } } actiction_for_chirrion = lambda { ten_numbers.map{|number| number * 4 } } ChirrinChirrion.chirrin_chirrion(‘mult_for_2’, action_for_chirrin, action_for_chirrion) #=> [4, 8, 12, 16, 20, 24, 28, 32, 36, 40] ChirrinChirrion.chirrin(‘mult_for_2’) ChirrinChirrion.chirrin_chirrion(‘mult_for_2’, action_for_chirrin, action_for_chirrion) #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
93 94 95 96 97 98 99 |
# File 'lib/chirrin-chirrion.rb', line 93 def self.chirrin_chirrion(toggle_name, for_chirrin, for_chirrion) if chirrin?(toggle_name) for_chirrin.respond_to?(:call) ? for_chirrin.call : for_chirrin else for_chirrion.respond_to?(:call) ? for_chirrion.call : for_chirrion end end |
.chirrion!(toggle_name) ⇒ Object
Makes a toggle inactive
ChirrinChirrion.chirrion!(‘my_active_feature’) ChirrinChirrion.chirrion?(‘my_active_feature’) #=> false
59 60 61 |
# File 'lib/chirrin-chirrion.rb', line 59 def self.chirrion!(toggle_name) database_adapter.inactivate!(toggle_name) end |
.chirrion?(toggle_name) ⇒ Boolean
Checks if a toggle inactive
ChirrinChirrion.chirrion?(‘my_active_feature’) #=> false ChirrinChirrion.chirrion?(‘my_inactive_feature’) #=> true ChirrinChirrion.chirrin?(‘my_unregistered_toggle’) #=> true
79 80 81 |
# File 'lib/chirrin-chirrion.rb', line 79 def self.chirrion?(toggle_name) database_adapter.inactive?(toggle_name) end |
.config(options) ⇒ Object
Defines the configuration for Chirrin Chirrion. The config are:
- database_adapter, an adapter which wrap the database management to provide the correct service
redis_connection = Redis.new redis_adapter = RedisAdapter.new(redis_connection) ChirrinChirrion.config(database_adapter: redis_adapter)
16 17 18 |
# File 'lib/chirrin-chirrion.rb', line 16 def self.config() @database_adapter = [:database_adapter] end |
.list ⇒ Object
Returns a list of registered toggles The objects of the list respond to the following basic methods:
- name
- active
- description
106 107 108 |
# File 'lib/chirrin-chirrion.rb', line 106 def self.list database_adapter.list end |
.remove_toggle(toggle_name) ⇒ Object
Removes a toggle from the database
ChirrinChirrion.remove_toggle(‘my_active_feature’) ChirrinChirrion.remove_toggle(‘my_inactive_feature’)
41 42 43 |
# File 'lib/chirrin-chirrion.rb', line 41 def self.remove_toggle(toggle_name) database_adapter.remove_toggle(toggle_name) end |