Module: Comply::WhitelistConstantize

Defined in:
lib/comply/whitelist_constantize.rb

Defined Under Namespace

Classes: MatcherFactory, NotWhitelistedError

Constant Summary collapse

DEFAULT_PROC =
MatcherFactory.new(ActiveModel::Validations, include_inheritance: true).to_matcher

Class Method Summary collapse

Class Method Details

.allow(obj, opts = {}) ⇒ Object

obj can be a Class, Module or Proc. For classes and modules, optionally add ‘include_inheritance: true` to also match subclasses. Procs should accept one argument.



46
47
48
# File 'lib/comply/whitelist_constantize.rb', line 46

def allow(obj, opts = {})
  whitelist << MatcherFactory.new(obj, opts).to_matcher
end

.constantize(str) ⇒ Object



34
35
36
# File 'lib/comply/whitelist_constantize.rb', line 34

def constantize(str)
  whitelist!(str.classify.constantize)
end

.whitelistObject



38
39
40
# File 'lib/comply/whitelist_constantize.rb', line 38

def whitelist
  @whitelist ||= [DEFAULT_PROC]
end