Class: FixtureFox::Idr

Inherits:
Object
  • Object
show all
Defined in:
lib/fixture_fox/idr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIdr

Returns a new instance of Idr.



20
21
22
23
# File 'lib/fixture_fox/idr.rb', line 20

def initialize
  @tables_hash = {}
  @data = {}
end

Instance Attribute Details

#dataObject (readonly) Also known as: to_h

Data as a hash from schema to table to id to record to field to value. Ie. { “schema” => { “table” => { 1 => { id: 1, name: “Alice” } } } }



15
16
17
# File 'lib/fixture_fox/idr.rb', line 15

def data
  @data
end

#idsObject (readonly)

Map from qualified table name to last used ID. FIXME: Unused?



18
19
20
# File 'lib/fixture_fox/idr.rb', line 18

def ids
  @ids
end

#materialized_viewsObject

List of materialized views that depends on the tables. Assigned by the analyzer FIXME: Is this in use?



11
12
13
# File 'lib/fixture_fox/idr.rb', line 11

def materialized_views
  @materialized_views
end

Instance Method Details

#countObject

Number of records



26
27
28
29
30
# File 'lib/fixture_fox/idr.rb', line 26

def count()
  count = 0
  @data.each { |_, tables| tables.each { |_, records| count += records.size } }
  count
end

#dumpObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fixture_fox/idr.rb', line 49

def dump
  data.sort_by(&:first).each { |schema, tables|
    puts schema
    tables.each { |table, records|
      puts "  #{table}"
      records.each { |id, fields|
        puts "    #{fields.inspect}"
      }
    }
  }
end

#put(schema, table, id = nil, field = nil, value = nil) ⇒ Object

Add a field to the data representation. If field and value are nil, an empty record will be created. If id is also nil, an empty table is created



36
37
38
39
40
41
42
43
44
45
# File 'lib/fixture_fox/idr.rb', line 36

def put(schema, table, id = nil, field = nil, value = nil)
#     puts "Idr.put(#{schema}, #{table}, #{id.inspect}, #{field.inspect}, #{value.inspect})"
  !id.nil? || field.nil? or raise ArgumentError
  raise if table.to_s =~ /[A-Z]/
  uid = "#{schema}.#{table}"
  @tables_hash[uid] = true
  return if id.nil?
  tuple = ((@data[schema] ||= {})[table] ||= {})[id] ||= {id: id}
  tuple[field.to_sym] = value if field
end

#tablesObject

Qualified names of controlled tables



7
# File 'lib/fixture_fox/idr.rb', line 7

def tables() @tables_hash.keys end