Class: Settings
- Inherits:
- BasicObject
- Defined in:
- lib/thecore_settings/settings.rb
Overview
we are inheriting from BasicObject so we don’t get a bunch of methods from Kernel or Object
Constant Summary collapse
- @@file_uploads_supported =
false
- @@file_uploads_engine =
false
- @@namespaces =
{}
- @@mutex =
::Mutex.new
- @@ns_default =
'main'
- @@ns_fallback =
nil
Class Method Summary collapse
- .apply_defaults!(file, verbose = false) ⇒ Object
- .create_setting(key, value, options = {}) ⇒ Object
- .destroy_all! ⇒ Object
- .get(key, options = {}) ⇒ Object
- .get_default_ns ⇒ Object
- .method_missing(*args) ⇒ Object
- .ns(name, options = {}) ⇒ Object
- .root_file_path ⇒ Object
- .save_default(key, value, options = {}) ⇒ Object
- .set(key, value = nil, options = {}) ⇒ Object
- .table_exists? ⇒ Boolean
- .unload! ⇒ Object
Class Method Details
.apply_defaults!(file, verbose = false) ⇒ Object
68 69 70 |
# File 'lib/thecore_settings/settings.rb', line 68 def apply_defaults!(file, verbose = false) ThecoreSettings.apply_defaults!(file, verbose) end |
.create_setting(key, value, options = {}) ⇒ Object
86 87 88 |
# File 'lib/thecore_settings/settings.rb', line 86 def create_setting(key, value, = {}) set(key, nil, .merge(overwrite: false)) end |
.destroy_all! ⇒ Object
55 56 57 58 |
# File 'lib/thecore_settings/settings.rb', line 55 def destroy_all! ThecoreSettings::Setting.destroy_all unload! end |
.get(key, options = {}) ⇒ Object
72 73 74 75 |
# File 'lib/thecore_settings/settings.rb', line 72 def get(key, = {}) .symbolize_keys! ns([:ns], ).get(key, ) end |
.get_default_ns ⇒ Object
36 37 38 |
# File 'lib/thecore_settings/settings.rb', line 36 def get_default_ns ns(nil, fallback: @@ns_fallback) end |
.method_missing(*args) ⇒ Object
90 91 92 |
# File 'lib/thecore_settings/settings.rb', line 90 def method_missing(*args) get_default_ns.__send__(*args) end |
.ns(name, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/thecore_settings/settings.rb', line 19 def ns(name, = {}) .symbolize_keys! if name.nil? || name == @@ns_default name = @@ns_default.to_s else name = name.to_s end if .key?(:type) [:kind] = .delete(:type) end @@mutex.synchronize do @@namespaces[name] ||= ::ThecoreSettings::Namespaced.new(name.to_s) end fallback = .key?(:fallback) ? [:fallback] : @@ns_fallback ::ThecoreSettings::Fallback.new(@@namespaces[name], fallback) end |
.root_file_path ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/thecore_settings/settings.rb', line 60 def root_file_path if defined?(Rails) Rails.root else Pathname.new(File.dirname(__FILE__)).join('../..') end end |
.save_default(key, value, options = {}) ⇒ Object
82 83 84 |
# File 'lib/thecore_settings/settings.rb', line 82 def save_default(key, value, = {}) set(key, value, .merge(overwrite: false)) end |
.set(key, value = nil, options = {}) ⇒ Object
77 78 79 80 |
# File 'lib/thecore_settings/settings.rb', line 77 def set(key, value = nil, = {}) .symbolize_keys! ns([:ns], ).set(key, value, ) end |
.table_exists? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/thecore_settings/settings.rb', line 40 def table_exists? ThecoreSettings.mongoid? || ThecoreSettings::Setting.table_exists? rescue ActiveRecord::NoDatabaseError false end |
.unload! ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/thecore_settings/settings.rb', line 46 def unload! @@mutex.synchronize do @@namespaces.values.map(&:unload!) @@namespaces = {} @@ns_default = 'main' @@ns_fallback = nil end end |