Class: Poke::Config
- Inherits:
-
Object
- Object
- Poke::Config
- Defined in:
- lib/poke/config.rb
Defined Under Namespace
Classes: NotFound
Constant Summary collapse
- ROOT_PATH =
"#{Dir.home}/.poke".freeze
Class Method Summary collapse
- .aliases ⇒ Object
- .aliases_path ⇒ Object
- .find_alias_by_request_name(value) ⇒ Object
- .find_request_name_by_alias(value) ⇒ Object
- .lru_path ⇒ Object
- .response_path ⇒ Object
- .root_path ⇒ Object
- .set_alias!(value, path) ⇒ Object
- .valid? ⇒ Boolean
Class Method Details
.aliases ⇒ Object
34 35 36 |
# File 'lib/poke/config.rb', line 34 def self.aliases @aliases ||= JSON.parse(File.read(aliases_path)) end |
.aliases_path ⇒ Object
30 31 32 |
# File 'lib/poke/config.rb', line 30 def self.aliases_path [root_path, 'aliases.json'].join('/') end |
.find_alias_by_request_name(value) ⇒ Object
46 47 48 |
# File 'lib/poke/config.rb', line 46 def self.find_alias_by_request_name(value) aliases.find { |_k, v| v == value }&.first end |
.find_request_name_by_alias(value) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/poke/config.rb', line 38 def self.find_request_name_by_alias(value) result = aliases[value] raise NotFound unless result result end |
.lru_path ⇒ Object
26 27 28 |
# File 'lib/poke/config.rb', line 26 def self.lru_path [root_path, 'lru.json'].join('/') end |
.response_path ⇒ Object
22 23 24 |
# File 'lib/poke/config.rb', line 22 def self.response_path [root_path, 'response.json'].join('/') end |
.root_path ⇒ Object
11 12 13 |
# File 'lib/poke/config.rb', line 11 def self.root_path ROOT_PATH end |
.set_alias!(value, path) ⇒ Object
50 51 52 53 54 |
# File 'lib/poke/config.rb', line 50 def self.set_alias!(value, path) aliases.delete_if { |_k, v| v == path.to_s } aliases[value] = path.to_s File.write(aliases_path, aliases.to_json) end |
.valid? ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/poke/config.rb', line 15 def self.valid? Dir.exist?("#{Dir.home}/.poke") && File.exist?("#{Dir.home}/.poke/aliases.json") && File.exist?("#{Dir.home}/.poke/lru.json") && File.exist?("#{Dir.home}/.poke/response.json") end |