Class: OFFS::Flags

Inherits:
Array
  • Object
show all
Defined in:
lib/offs/flags.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*flags, value_sources: {}) ⇒ Flags

Returns a new instance of Flags.



21
22
23
24
# File 'lib/offs/flags.rb', line 21

def initialize(*flags, value_sources: {})
  self.value_sources = array_wrap(value_sources)
  __setobj__(flags)
end

Class Method Details

.instance(*args) ⇒ Object



9
10
11
12
13
14
# File 'lib/offs/flags.rb', line 9

def instance(*args)
  unless @instance.nil? || args.empty?
    raise AlreadyInitializedError
  end
  @instance ||= new(*args)
end

.reset_instance!Object



16
17
18
# File 'lib/offs/flags.rb', line 16

def reset_instance!
  @instance = nil
end

Instance Method Details

#enabled?(flag) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/offs/flags.rb', line 31

def enabled?(flag)
  validate!(flag)
  !!final_values[flag]
end

#validate!(flag) ⇒ Object

Raises:



26
27
28
29
# File 'lib/offs/flags.rb', line 26

def validate!(flag)
  return true if include?(flag)
  raise UndefinedFlagError, "The #{flag} flag has not been defined."
end