Module: DataBindings::Writers
- Includes:
- GemRequirement
- Defined in:
- lib/data_bindings/converters.rb
Overview
This defines the default writers used.
Instance Method Summary collapse
-
#file(data, path) ⇒ Object
Takes data and a file path and writes it’s contents to it.
-
#http(data, url, opts = {}) ⇒ Object
Takes a URL and posts the contents of your data to it.
-
#io(data, io) ⇒ Object
Takes data and an IO object and writes it’s contents to it.
Methods included from GemRequirement
Instance Method Details
#file(data, path) ⇒ Object
Takes data and a file path and writes it’s contents to it.
64 65 66 |
# File 'lib/data_bindings/converters.rb', line 64 def file(data, path) File.open(path, 'w') { |f| f << data } end |
#http(data, url, opts = {}) ⇒ Object
Takes a URL and posts the contents of your data to it. Uses HTTPParty underlyingly.
73 74 75 76 77 78 79 80 |
# File 'lib/data_bindings/converters.rb', line 73 def http(data, url, opts = {}) method = opts[:method] || :post opts[:data] = data response = HTTParty.send(method, url, opts) unless (200..299).include?(response.code) raise HttpError.new("Bad response: #{response.code} #{response.body}", response) end end |
#io(data, io) ⇒ Object
Takes data and an IO object and writes it’s contents to it.
57 58 59 |
# File 'lib/data_bindings/converters.rb', line 57 def io(data, io) io.write(obj) end |