Class: Firebolt::Config
- Inherits:
-
Hash
- Object
- Hash
- Firebolt::Config
- Defined in:
- lib/firebolt/config.rb
Constant Summary collapse
- CACHE_FILENAME =
"firebolt.cache.json".freeze
Class Method Summary collapse
-
.hash_accessor(*names) ⇒ Object
Creates an accessor that simply sets and reads a key in the hash:.
Instance Method Summary collapse
-
#cache_file ⇒ Object
Public instance methods.
- #cache_file_enabled? ⇒ Boolean
- #cache_file_path=(path) ⇒ Object
- #cache_file_readable? ⇒ Boolean
-
#initialize(options = {}) ⇒ Config
constructor
Constructor!.
- #namespace ⇒ Object
- #use_file_warmer? ⇒ Boolean
- #warmer=(value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Constructor!
8 9 10 11 12 13 |
# File 'lib/firebolt/config.rb', line 8 def initialize( = {}) merge!() self[:cache_file_path] ||= '/tmp' self[:namespace] ||= ::SecureRandom.hex end |
Class Method Details
.hash_accessor(*names) ⇒ Object
Creates an accessor that simply sets and reads a key in the hash:
class Config < Hash
hash_accessor :app
end
config = Config.new
config.app = Foo
config[:app] #=> Foo
config[:app] = Bar
config.app #=> Bar
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/firebolt/config.rb', line 32 def self.hash_accessor(*names) #:nodoc: names.each do |name| class_eval " def \#{name}\n self[:\#{name}]\n end\n\n def \#{name}=(value)\n self[:\#{name}] = value\n end\n METHOD\n end\nend\n", __FILE__, __LINE__ + 1 |
Instance Method Details
#cache_file ⇒ Object
Public instance methods
52 53 54 |
# File 'lib/firebolt/config.rb', line 52 def cache_file ::File.join(self[:cache_file_path], CACHE_FILENAME) end |
#cache_file_enabled? ⇒ Boolean
56 57 58 |
# File 'lib/firebolt/config.rb', line 56 def cache_file_enabled? !! ::Firebolt.config.cache_file_enabled end |
#cache_file_path=(path) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/firebolt/config.rb', line 60 def cache_file_path=(path) raise ArgumentError, "Directory '#{path}' does not exist or is not writable." unless ::File.writable?(path) self[:cache_file_enabled] = true self[:cache_file_path] = path end |
#cache_file_readable? ⇒ Boolean
67 68 69 |
# File 'lib/firebolt/config.rb', line 67 def cache_file_readable? ::File.readable?(cache_file) end |
#namespace ⇒ Object
71 72 73 |
# File 'lib/firebolt/config.rb', line 71 def namespace @namespace ||= "firebolt.#{self[:namespace]}" end |
#use_file_warmer? ⇒ Boolean
75 76 77 |
# File 'lib/firebolt/config.rb', line 75 def use_file_warmer? cache_file_enabled? && cache_file_readable? end |
#warmer=(value) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/firebolt/config.rb', line 79 def warmer=(value) raise ArgumentError, "Warmer must include the ::Firebolt::Warmer module." unless value.ancestors.include?(::Firebolt::Warmer) raise ArgumentError, "Warmer must respond to #perform." unless value.instance_methods.include?(:perform) self[:warmer] = value end |