Class: FixtureFox::Idr
- Inherits:
-
Object
- Object
- FixtureFox::Idr
- Defined in:
- lib/fixture_fox/idr.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #to_h)
readonly
Data as a hash from schema to table to id to record to field to value.
-
#ids ⇒ Object
readonly
Map from qualified table name to last used ID.
-
#materialized_views ⇒ Object
List of materialized views that depends on the tables.
Instance Method Summary collapse
-
#count ⇒ Object
Number of records.
- #dump ⇒ Object
-
#initialize ⇒ Idr
constructor
A new instance of Idr.
-
#put(schema, table, id = nil, field = nil, value = nil) ⇒ Object
Add a field to the data representation.
-
#tables ⇒ Object
Qualified names of controlled tables.
Constructor Details
#initialize ⇒ Idr
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
#data ⇒ Object (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 |
#ids ⇒ Object (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_views ⇒ Object
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
#count ⇒ Object
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 |
#dump ⇒ Object
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 |
#tables ⇒ Object
Qualified names of controlled tables
7 |
# File 'lib/fixture_fox/idr.rb', line 7 def tables() @tables_hash.keys end |