Class: Policial::ConfigLoader
- Inherits:
-
Object
- Object
- Policial::ConfigLoader
- Defined in:
- lib/policial/config_loader.rb
Overview
Public: Load and parse config files from GitHub repo.
Instance Method Summary collapse
-
#initialize(commit) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #json(filename) ⇒ Object
- #raw(filename) ⇒ Object
- #yaml(filename) ⇒ Object
Constructor Details
#initialize(commit) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
6 7 8 |
# File 'lib/policial/config_loader.rb', line 6 def initialize(commit) @commit = commit end |
Instance Method Details
#json(filename) ⇒ Object
14 15 16 17 18 |
# File 'lib/policial/config_loader.rb', line 14 def json(filename) JSON.parse(raw(filename)) rescue JSON::ParserError {} end |
#raw(filename) ⇒ Object
10 11 12 |
# File 'lib/policial/config_loader.rb', line 10 def raw(filename) blank?(filename) ? '' : @commit.file_content(filename) end |
#yaml(filename) ⇒ Object
20 21 22 23 24 |
# File 'lib/policial/config_loader.rb', line 20 def yaml(filename) YAML.load(raw(filename)) || {} rescue Psych::SyntaxError {} end |