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
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 <<-METHOD, __FILE__, __LINE__ + 1 def #{name} self[:#{name}] end def #{name}=(value) self[:#{name}] = value end METHOD end end |
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 |
# 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_path] = path end |
#cache_file_readable? ⇒ Boolean
66 67 68 |
# File 'lib/firebolt/config.rb', line 66 def cache_file_readable? ::File.readable?(cache_file) end |
#namespace ⇒ Object
70 71 72 |
# File 'lib/firebolt/config.rb', line 70 def namespace @namespace ||= "firebolt.#{self[:namespace]}" end |
#use_file_warmer? ⇒ Boolean
74 75 76 |
# File 'lib/firebolt/config.rb', line 74 def use_file_warmer? cache_file_enabled? && cache_file_readable? end |
#warmer=(value) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/firebolt/config.rb', line 78 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 |