Class: TableQuery::QuerySchema
- Inherits:
-
Object
- Object
- TableQuery::QuerySchema
- Defined in:
- lib/table-query/query-schema.rb
Overview
QuerySchema defines query’s input and output field relation.
Instance Attribute Summary collapse
-
#inputs ⇒ Array<Field>
readonly
input field list.
-
#name ⇒ Symbol
readonly
query name.
-
#outputs ⇒ Array<Field>
readonly
output field list.
-
#values ⇒ Array<Field>
readonly
preset value list.
Class Method Summary collapse
-
.define(name, &b) ⇒ QuerySchema
Define a new query schema.
Instance Method Summary collapse
-
#initialize(name) ⇒ QuerySchema
constructor
Create a query schema object.
-
#input(name, options = {}) ⇒ void
Define an input field.
-
#output(name, options = {}) ⇒ void
Define an output field.
-
#set_table(table) ⇒ void
private
Set target table for query.
-
#value(name, val, options = {}) ⇒ void
Define pre set value of the query.
Constructor Details
#initialize(name) ⇒ QuerySchema
Create a query schema object.
34 35 36 37 38 39 40 |
# File 'lib/table-query/query-schema.rb', line 34 def initialize(name) @name = name @inputs = [] @outputs = [] @values = [] @table = nil end |
Instance Attribute Details
#inputs ⇒ Array<Field> (readonly)
input field list
20 21 22 |
# File 'lib/table-query/query-schema.rb', line 20 def inputs @inputs end |
#name ⇒ Symbol (readonly)
query name
16 17 18 |
# File 'lib/table-query/query-schema.rb', line 16 def name @name end |
#outputs ⇒ Array<Field> (readonly)
output field list
24 25 26 |
# File 'lib/table-query/query-schema.rb', line 24 def outputs @outputs end |
#values ⇒ Array<Field> (readonly)
preset value list
28 29 30 |
# File 'lib/table-query/query-schema.rb', line 28 def values @values end |
Class Method Details
.define(name, &b) ⇒ QuerySchema
Define a new query schema.
10 11 12 |
# File 'lib/table-query/query-schema.rb', line 10 def self.define(name, &b) new(name).tap {|x| x.instance_eval(&b)} end |
Instance Method Details
#input(name, options = {}) ⇒ void
This method returns an undefined value.
Define an input field.
49 50 51 |
# File 'lib/table-query/query-schema.rb', line 49 def input(name, ={}) @inputs << Field.new(name, nil, nil, nil, ) end |
#output(name, options = {}) ⇒ void
This method returns an undefined value.
Define an output field.
60 61 62 |
# File 'lib/table-query/query-schema.rb', line 60 def output(name, ={}) @outputs << Field.new(name, nil, nil, nil, ) end |
#set_table(table) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Set target table for query.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/table-query/query-schema.rb', line 83 def set_table(table) @table = table @table.table_schema.fields.each do |field| (@inputs + @outputs + @values).each do |item| if field.name == item.name item.pos = field.pos item.type = @table.types[field.type] end end end end |
#value(name, val, options = {}) ⇒ void
This method returns an undefined value.
Define pre set value of the query.
73 74 75 |
# File 'lib/table-query/query-schema.rb', line 73 def value(name, val, ={}) @values << Field.new(name, nil, nil, val, ) end |