Module: DataBindings::Readers
- Includes:
- GemRequirement
- Defined in:
- lib/data_bindings/converters.rb
Overview
This defines the default readers used.
Instance Method Summary collapse
-
#file(path) ⇒ Object
Takes a file path and returns it’s contents.
-
#http(url, opts = {}) ⇒ Object
Takes a URL and returns it’s contents.
-
#io(i) ⇒ Object
Takes an IO object and reads it’s contents.
Methods included from GemRequirement
Instance Method Details
#file(path) ⇒ Object
Takes a file path and returns it’s contents.
29 30 31 |
# File 'lib/data_bindings/converters.rb', line 29 def file(path) File.read(path) end |
#http(url, opts = {}) ⇒ Object
Takes a URL and returns it’s contents. Uses HTTPParty underlyingly.
38 39 40 41 42 43 44 45 46 |
# File 'lib/data_bindings/converters.rb', line 38 def http(url, opts = {}) method = opts[:method] || :get response = HTTParty.send(method, url, opts) if (200..299).include?(response.code) response.body else raise HttpError.new("Bad response: #{response.code} #{response.body}", response) end end |
#io(i) ⇒ Object
Takes an IO object and reads it’s contents.
21 22 23 24 |
# File 'lib/data_bindings/converters.rb', line 21 def io(i) i.rewind i.read end |