Module: DbAgile::IO::Ruby

Defined in:
lib/dbagile/io/ruby.rb

Defined Under Namespace

Classes: Reader

Class Method Summary collapse

Class Method Details

.from_ruby(io, options = {}, &block) ⇒ Object

Interprets io as ruby code that returns an array of tuples (Hash instance). If a block if given, yields it with each tuple in turn. Otherwise returns it.



49
50
51
52
53
54
55
56
57
# File 'lib/dbagile/io/ruby.rb', line 49

def from_ruby(io, options = {}, &block)
  tuples = Reader.new(io, options).tuples
  if block
    tuples.each(&block)
    nil
  else
    tuples
  end
end

.to_ruby(data, columns = nil, buffer = "", options = {}) ⇒ ...

Outputs some data as a Ruby string

Returns:

  • (...)

    the buffer itself



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dbagile/io/ruby.rb', line 31

def to_ruby(data, columns = nil, buffer = "", options = {})
  require 'sbyc/type_system/ruby'
  buffer << "["
  first = true
  data.each{|t| 
    buffer << (first ? "\n  " : ",\n  ")
    buffer << SByC::TypeSystem::Ruby::to_literal(t)
    first = false
  }
  buffer << "\n]"
end