Class: Feature::Repository::ActiveRecordRepository
- Inherits:
-
Object
- Object
- Feature::Repository::ActiveRecordRepository
- Defined in:
- lib/feature/repository/active_record_repository.rb
Overview
AcitveRecordRepository for active feature list Right now we assume you have at least name:string and active:boolean defined in your table.
Example usage:
repository = ActiveRecordRepository.new(FeatureToggle)
repository.add_active_feature(:feature_name)
# use repository with Feature
Instance Method Summary collapse
-
#active_features ⇒ Array<Symbol>
Returns list of active features.
-
#add_active_feature(feature) ⇒ Object
Add an active feature to repository.
-
#initialize(model) ⇒ ActiveRecordRepository
constructor
Constructor.
Constructor Details
#initialize(model) ⇒ ActiveRecordRepository
Constructor
15 16 17 |
# File 'lib/feature/repository/active_record_repository.rb', line 15 def initialize(model) @model = model end |
Instance Method Details
#active_features ⇒ Array<Symbol>
Returns list of active features
23 24 25 |
# File 'lib/feature/repository/active_record_repository.rb', line 23 def active_features @model.where(active: true).map { |f| f.name.to_sym } end |
#add_active_feature(feature) ⇒ Object
Add an active feature to repository
31 32 33 34 35 |
# File 'lib/feature/repository/active_record_repository.rb', line 31 def add_active_feature(feature) check_feature_is_not_symbol(feature) check_feature_already_in_list(feature) @model.create!(name: feature.to_s, active: true) end |