Class: RysFeatureRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rys_feature_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activate!(*full_keys) ⇒ Object


32
33
34
35
# File 'app/models/rys_feature_record.rb', line 32

def self.activate!(*full_keys)
  request_store.clear
  RysFeatureRecord.where(name: full_keys).update_all(active: true)
end

.active?(full_key) ⇒ Boolean

Returns:

  • (Boolean)

27
28
29
30
# File 'app/models/rys_feature_record.rb', line 27

def self.active?(full_key)
  record = (request_store[full_key] ||= find_by(name: full_key))
  record && record.active?
end

.migrate_newObject


8
9
10
11
12
13
14
15
16
17
# File 'app/models/rys_feature_record.rb', line 8

def self.migrate_new
  return unless table_exists?

  saved_names = pluck(:name)
  unsaved_names = Rys::Feature.all_features.keys - saved_names

  unsaved_names.each do |name|
    create!(name: name, active: true)
  end
end

.request_storeObject


19
20
21
22
23
24
25
# File 'app/models/rys_feature_record.rb', line 19

def self.request_store
  if !RequestStore.store.has_key?(:rys_features_request_store)
    RequestStore.store[:rys_features_request_store] = {}
  end

  RequestStore.store[:rys_features_request_store]
end

Instance Method Details

#featureObject


37
38
39
# File 'app/models/rys_feature_record.rb', line 37

def feature
  Rys::Feature.all_features[name]
end