Class: FixtureFox::Analyzer
- Inherits:
-
Object
- Object
- FixtureFox::Analyzer
- Defined in:
- lib/fixture_fox/analyzer.rb
Instance Attribute Summary collapse
-
#anchors ⇒ Object
readonly
Anchors object.
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#defined_anchors ⇒ Object
readonly
Map from anchor name to anchors defined by the sources.
-
#fields ⇒ Object
readonly
[AstField].
-
#idr ⇒ Object
readonly
Initialized by #call.
-
#ids ⇒ Object
readonly
Map from qualified table name to maximum record ID.
-
#record_refs ⇒ Object
readonly
[AstRecordRef].
-
#records ⇒ Object
readonly
[AstRecord].
-
#referenced_anchors ⇒ Object
readonly
Map from anchor name to anchors referenced by the sources.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#assign_types ⇒ Object
Assign types and collect fields, records, and anchors.
-
#assigned? ⇒ Boolean
True iff types have been assigned.
-
#call ⇒ Object
TODO: Also generate data.
-
#check_types(anchors: nil) ⇒ Object
Check types.
-
#checked? ⇒ Boolean
True iff types have been checked.
-
#data_tables ⇒ Object
List of non-empty tables (PgGraph::Type::Table objects).
-
#generate(ids: nil) ⇒ Object
Generate IDR.
-
#generated? ⇒ Boolean
True iff data has been generated.
-
#initialize(type, ast, ids: {}, anchors: Anchors.new(type)) ⇒ Analyzer
constructor
A new instance of Analyzer.
-
#tables ⇒ Object
List of all known tables whether empty or not (PgGraph::Type::Table objects).
Constructor Details
#initialize(type, ast, ids: {}, anchors: Anchors.new(type)) ⇒ Analyzer
Returns a new instance of Analyzer.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fixture_fox/analyzer.rb', line 42 def initialize(type, ast, ids: {}, anchors: Anchors.new(type)) constrain type, PgGraph::Type constrain ast, Ast constrain anchors, Anchors @type = type @ast = ast @tables = {} @data_tables = {} @records = [] @record_refs = [] @fields = [] # List of all fields @ids = Hash.new(0) ids.each { |k,v| @ids[k] = v } # copy but preserve default value @anchors = anchors @defined_anchors = {} @referenced_anchors = {} @assigned = false @checked = false end |
Instance Attribute Details
#anchors ⇒ Object (readonly)
Anchors object. This includes both anchors defined in the sources and anchors supplied to #initialize
25 26 27 |
# File 'lib/fixture_fox/analyzer.rb', line 25 def anchors @anchors end |
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
3 4 5 |
# File 'lib/fixture_fox/analyzer.rb', line 3 def ast @ast end |
#defined_anchors ⇒ Object (readonly)
Map from anchor name to anchors defined by the sources
28 29 30 |
# File 'lib/fixture_fox/analyzer.rb', line 28 def defined_anchors @defined_anchors end |
#fields ⇒ Object (readonly)
- AstField
15 16 17 |
# File 'lib/fixture_fox/analyzer.rb', line 15 def fields @fields end |
#idr ⇒ Object (readonly)
Initialized by #call
5 6 7 |
# File 'lib/fixture_fox/analyzer.rb', line 5 def idr @idr end |
#ids ⇒ Object (readonly)
Map from qualified table name to maximum record ID
18 19 20 |
# File 'lib/fixture_fox/analyzer.rb', line 18 def ids @ids end |
#record_refs ⇒ Object (readonly)
- AstRecordRef
14 15 16 |
# File 'lib/fixture_fox/analyzer.rb', line 14 def record_refs @record_refs end |
#records ⇒ Object (readonly)
- AstRecord
13 14 15 |
# File 'lib/fixture_fox/analyzer.rb', line 13 def records @records end |
#referenced_anchors ⇒ Object (readonly)
Map from anchor name to anchors referenced by the sources. FIXME: Unused
31 32 33 |
# File 'lib/fixture_fox/analyzer.rb', line 31 def referenced_anchors @referenced_anchors end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/fixture_fox/analyzer.rb', line 4 def type @type end |
Instance Method Details
#assign_types ⇒ Object
Assign types and collect fields, records, and anchors. Note that #assign_types and #check_types are separate methods to make it possible to analyze the AST just up to the point where external anchors are needed for further processing. This is used in the caching mechanism in Postspec
75 76 77 78 79 |
# File 'lib/fixture_fox/analyzer.rb', line 75 def assign_types @assigned = true assign_table_types self end |
#assigned? ⇒ Boolean
True iff types have been assigned
34 |
# File 'lib/fixture_fox/analyzer.rb', line 34 def assigned?() @assigned end |
#call ⇒ Object
TODO: Also generate data
65 66 67 68 69 |
# File 'lib/fixture_fox/analyzer.rb', line 65 def call assign_types check_types self end |
#check_types(anchors: nil) ⇒ Object
Check types. Merges anchors: into self.anchors
82 83 84 85 86 87 88 |
# File 'lib/fixture_fox/analyzer.rb', line 82 def check_types(anchors: nil) @checked = true @anchors.merge!(anchors) if anchors check_field_types check_record_ref_types self end |
#checked? ⇒ Boolean
True iff types have been checked
37 |
# File 'lib/fixture_fox/analyzer.rb', line 37 def checked?() @checked end |
#data_tables ⇒ Object
List of non-empty tables (PgGraph::Type::Table objects)
11 |
# File 'lib/fixture_fox/analyzer.rb', line 11 def data_tables() @data_tables.values end |
#generate(ids: nil) ⇒ Object
Generate IDR. Use self.ids if ids: is nil
91 92 93 94 95 96 |
# File 'lib/fixture_fox/analyzer.rb', line 91 def generate(ids: nil) ids.each { |k,v| @ids[k] = v } if ids # copy while preserving default value in hash generate_record_ids generate_idr @idr end |
#generated? ⇒ Boolean
True iff data has been generated
40 |
# File 'lib/fixture_fox/analyzer.rb', line 40 def generated?() !@idr.nil? end |
#tables ⇒ Object
List of all known tables whether empty or not (PgGraph::Type::Table objects)
8 |
# File 'lib/fixture_fox/analyzer.rb', line 8 def tables() @tables.values end |