Class: Lurker::Json::Reader
- Inherits:
-
Object
- Object
- Lurker::Json::Reader
- Defined in:
- lib/lurker/json/reader.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Reader
constructor
A new instance of Reader.
- #read ⇒ Object (also: #payload)
Constructor Details
#initialize(path) ⇒ Reader
Returns a new instance of Reader.
6 7 8 9 |
# File 'lib/lurker/json/reader.rb', line 6 def initialize(path) @path = path @attempts_left = 1 end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/lurker/json/reader.rb', line 4 def path @path end |
Instance Method Details
#read ⇒ Object Also known as: payload
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lurker/json/reader.rb', line 11 def read return YAML.load_file(@path) unless @path.match(/\.erb$/) context = Lurker::ErbSchemaContext.new erb = ERB.new(IO.read @path).result(context.get_binding) YAML.load(erb) rescue Errno::ENOENT raise if @attempts_left.zero? @path = @path.sub(/\#\/?$/, '').sub(/\.json/, '.json.yml') @attempts_left -= 1 retry end |