Class: EasySettings

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/easy_settings.rb,
lib/easy_settings/rails.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

SourceFileNotExist =
Class.new(StandardError)

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &blk) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/easy_settings.rb', line 84

def method_missing(method_name, *args, &blk)
  return self.[](method_name, &blk) if key?(method_name)
  name, suffix = method_name_and_suffix(method_name)
  case suffix
  when "="
    assign_property(name, args.first)
  when "?"
    !!self[name]
  when "!"
    initializing_reader(name)
  when "_"
    underbang_reader(name)
  else
    if !args[0].nil? || (args[1] && args[1][:nil])
      assign_property(name, args.first)
    else
      self[method_name]
    end
  end
end

Class Attribute Details

.default_filesObject

Returns the value of attribute default_files.



8
9
10
# File 'lib/easy_settings.rb', line 8

def default_files
  @default_files
end

.namespaceObject

Returns the value of attribute namespace.



8
9
10
# File 'lib/easy_settings.rb', line 8

def namespace
  @namespace
end

.source_fileObject

Returns the value of attribute source_file.



8
9
10
# File 'lib/easy_settings.rb', line 8

def source_file
  @source_file
end

.source_hashObject

Returns the value of attribute source_hash.



8
9
10
# File 'lib/easy_settings.rb', line 8

def source_hash
  @source_hash
end

Class Method Details

.[](key) ⇒ Object



32
33
34
# File 'lib/easy_settings.rb', line 32

def [](key)
  instance[key]
end

.[]=(key, val) ⇒ Object



36
37
38
# File 'lib/easy_settings.rb', line 36

def []=(key, val)
  instance[key] = val
end

.inherited(child_class) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/easy_settings.rb', line 10

def inherited(child_class)
  child_class.class_eval do
    define_singleton_method(:default_files) do
      instance_variable_get(:@default_files) || superclass.default_files
    end
  end
end

.instanceObject



18
19
20
# File 'lib/easy_settings.rb', line 18

def instance
  @instance ||= new(namespace ? _source[namespace] : _source)
end

.load!Object



22
23
24
25
# File 'lib/easy_settings.rb', line 22

def load!
  instance
  true
end

.reload!Object



27
28
29
30
# File 'lib/easy_settings.rb', line 27

def reload!
  @instance = nil
  load!
end

Instance Method Details

#assign_property(name, value) ⇒ Object



79
80
81
82
# File 'lib/easy_settings.rb', line 79

def assign_property(name, value)
  super
  self[name]
end