Class: Db2Query::Definitions
- Inherits:
-
Object
- Object
- Db2Query::Definitions
- Defined in:
- lib/db2_query/definitions.rb
Instance Attribute Summary collapse
-
#arguments_map ⇒ Object
readonly
Returns the value of attribute arguments_map.
-
#types ⇒ Object
Returns the value of attribute types.
-
#types_map ⇒ Object
Returns the value of attribute types_map.
Instance Method Summary collapse
- #describe ⇒ Object
-
#initialize(query_arguments_map, field_types_map) ⇒ Definitions
constructor
A new instance of Definitions.
- #lookup(query_name) ⇒ Object
- #lookup_query(*args) ⇒ Object
- #queries ⇒ Object
- #query_definition(query_name) {|definition| ... } ⇒ Object
Constructor Details
#initialize(query_arguments_map, field_types_map) ⇒ Definitions
Returns a new instance of Definitions.
8 9 10 11 12 13 |
# File 'lib/db2_query/definitions.rb', line 8 def initialize(query_arguments_map, field_types_map) @arguments_map = query_arguments_map @types_map = field_types_map describe initialize_types end |
Instance Attribute Details
#arguments_map ⇒ Object (readonly)
Returns the value of attribute arguments_map.
6 7 8 |
# File 'lib/db2_query/definitions.rb', line 6 def arguments_map @arguments_map end |
#types ⇒ Object
Returns the value of attribute types.
5 6 7 |
# File 'lib/db2_query/definitions.rb', line 5 def types @types end |
#types_map ⇒ Object
Returns the value of attribute types_map.
5 6 7 |
# File 'lib/db2_query/definitions.rb', line 5 def types_map @types_map end |
Instance Method Details
#describe ⇒ Object
15 16 17 |
# File 'lib/db2_query/definitions.rb', line 15 def describe raise Db2Query::Error, "Please describe query definitions at #{self.class.name}" end |
#lookup(query_name) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/db2_query/definitions.rb', line 29 def lookup(query_name) queries.fetch(query_name) rescue Exception => e if defined?(name) raise Db2Query::QueryDefinitionError.new(name, query_name) else raise Db2Query::Error, e. end end |
#lookup_query(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/db2_query/definitions.rb', line 39 def lookup_query(*args) query_name, sql = query_definitions(args) lookup(query_name).tap do |query| query.define_sql(sql) query.argument_keys.each do |key| key, key_def = query_arg_key(query, key) query.argument_types.store(key, data_type_instance(key_def)) rescue raise Db2Query::QueryArgumentError.new(query_name, key) end end end |
#queries ⇒ Object
19 20 21 |
# File 'lib/db2_query/definitions.rb', line 19 def queries @queries ||= {} end |