Class: Setti::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/setti/settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Settings

Returns a new instance of Settings.



5
6
7
8
# File 'lib/setti/settings.rb', line 5

def initialize(path)
  assert File.exist?(path), error: "No such file or directory: #{path}"
  @settings = Oj.load(IO.read(path), mode: :compat)
end

Instance Method Details

#[](name) ⇒ Object



21
22
23
# File 'lib/setti/settings.rb', line 21

def [](name)
  with_indifferent_hash lookup_property(name)
end

#validate(name, *args, &block) ⇒ Object



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

def validate(name, *args, &block)
  value = lookup_property(name)
  case args.first
  when nil      then nil_check!(name, value, block)
  when :number  then number_check!(name, value)
  when :float   then float_check!(name, value)
  when :integer then int_check!(name, value)
  when :regex   then regex_check!(name, value, args.last)
  end
end