Class: RolloutService::Models::Feature
- Inherits:
-
Object
- Object
- RolloutService::Models::Feature
- Includes:
- ActiveAttr::Model
- Defined in:
- lib/rollout_service/models/feature.rb
Constant Summary collapse
- MAX_HISTORY_RECORDS =
50
Class Method Summary collapse
- .exist?(name) ⇒ Boolean
- .find(name) ⇒ Object
- .parse(name) ⇒ Object
- .set_users_to_feature(rollout, users) ⇒ Object
Instance Method Summary collapse
Class Method Details
.exist?(name) ⇒ Boolean
48 49 50 51 |
# File 'lib/rollout_service/models/feature.rb', line 48 def self.exist?(name) features = Config::rollout.features features.include?(name.to_sym) end |
.find(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rollout_service/models/feature.rb', line 31 def self.find(name) return nil unless exist?(name) feature = Config::rollout.get(name) feature_data = feature.data.deep_symbolize_keys! feature_data.merge!({ name: feature.name, percentage: feature.percentage, users: feature.users }) feature_data.delete_if {|key, _| !self.method_defined?(key)} self.new(feature_data) end |
.parse(name) ⇒ Object
25 26 27 28 29 |
# File 'lib/rollout_service/models/feature.rb', line 25 def self.parse(name) instance = find(name) raise 'Feature is not exist' if instance.nil? instance end |
.set_users_to_feature(rollout, users) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rollout_service/models/feature.rb', line 53 def self.set_users_to_feature(rollout, users) return if users.nil? || rollout.nil? users = users.to_a current_active_users = rollout.users users_to_remove = current_active_users - users Config::rollout.deactivate_users(rollout.name ,users_to_remove) Config::rollout.activate_users(rollout.name ,users) rollout.users = users users end |
Instance Method Details
#active?(user_id) ⇒ Boolean
83 84 85 |
# File 'lib/rollout_service/models/feature.rb', line 83 def active?(user_id) Config::rollout.active?(self.name, user_id) end |
#delete ⇒ Object
87 88 89 |
# File 'lib/rollout_service/models/feature.rb', line 87 def delete Config::rollout.delete(self.name) end |
#save! ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rollout_service/models/feature.rb', line 65 def save! set_history_attribute raise 'Feature is not valid!' unless self.valid? Config::rollout.activate_percentage(self.name, self.percentage) feature_data = { history: self.history, description: self.description, author: self., author_mail: self., created_at: self.created_at } feature_data.delete_if { |_, value| value.blank? } Config::rollout.set_feature_data(self.name, feature_data) end |