Module: FeatureCop::Whitelist::ClassMethods

Defined in:
lib/feature_cop/whitelist.rb

Instance Method Summary collapse

Instance Method Details

#whitelistObject



21
22
23
# File 'lib/feature_cop/whitelist.rb', line 21

def whitelist
  @whitelist ||= {}
end

#whitelist=(whitelist) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/feature_cop/whitelist.rb', line 25

def whitelist=(whitelist)
  if whitelist.is_a?(Array)
    @whitelist = { "default" => whitelist }
    return
  end
  @whitelist = whitelist
end

#whitelist_from_yaml(file = "feature_cop_whitelist.yml") ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/feature_cop/whitelist.rb', line 10

def whitelist_from_yaml(file = "feature_cop_whitelist.yml")
  if ::File.exist?(file)
    absolute_path = file
  elsif defined?(Rails)
    absolute_path = ::File.join(Rails.root, "config", file)
  end

  raise "#{file} not found!" unless ::File.exist?(absolute_path)
  self.whitelist = ::YAML.load_file(absolute_path)[env]
end

#whitelist_only(feature, identifier, options = {}) ⇒ Object



33
34
35
# File 'lib/feature_cop/whitelist.rb', line 33

def whitelist_only(feature, identifier, options = {})
  whitelisted?(feature, identifier, options)
end

#whitelisted?(feature, identifier, options = {}) ⇒ Boolean



37
38
39
40
41
# File 'lib/feature_cop/whitelist.rb', line 37

def whitelisted?(feature, identifier, options = {})
  feature = "default" if whitelist[feature].nil?
  return false if whitelist[feature].nil?
  whitelist[feature].include?(identifier)
end