Module: Sapling::ActiveRecord::AdminAPI
- Included in:
- Sapling::ActiveRecord
- Defined in:
- lib/sapling/active_record.rb
Instance Method Summary collapse
- #activate_percentage(feature, percentage) ⇒ Object
- #activate_user(feature, user) ⇒ Object
- #deactivate_percentage(feature) ⇒ Object
- #deactivate_user(feature, user) ⇒ Object
Instance Method Details
#activate_percentage(feature, percentage) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/sapling/active_record.rb', line 43 def activate_percentage(feature, percentage) raise "invalid percentage #{percentage.inspect}" unless percentage.kind_of?(Integer) && percentage>=0 && percentage<=100 ActiveRecordModel.transaction do deactivate_percentage(feature) ActiveRecordModel.create(:feature => feature.to_s, :percentage => percentage) end reload end |
#activate_user(feature, user) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/sapling/active_record.rb', line 30 def activate_user(feature, user) ActiveRecordModel.transaction do deactivate_user(feature, user) ActiveRecordModel.create(:feature => feature.to_s, :user_id => user.id) end reload end |
#deactivate_percentage(feature) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/sapling/active_record.rb', line 52 def deactivate_percentage(feature) ActiveRecordModel.delete_all ["feature = ? AND percentage IS NOT NULL AND user_id IS NULL", feature.to_s ] reload end |
#deactivate_user(feature, user) ⇒ Object
38 39 40 41 |
# File 'lib/sapling/active_record.rb', line 38 def deactivate_user(feature, user) ActiveRecordModel.delete_all ["feature = ? AND percentage IS NULL and user_id = ?",feature.to_s,user.id] reload end |