Class: Twb::DataSource
- Inherits:
-
Object
- Object
- Twb::DataSource
- Defined in:
- lib/twb/datasource.rb
Constant Summary collapse
- @@hasher =
Digest::SHA256.new
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#connHash ⇒ Object
readonly
Returns the value of attribute connHash.
-
#dsclass ⇒ Object
readonly
Returns the value of attribute dsclass.
-
#localfields ⇒ Object
readonly
Returns the value of attribute localfields.
-
#metadatafields ⇒ Object
readonly
Returns the value of attribute metadatafields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#uiname ⇒ Object
readonly
Returns the value of attribute uiname.
Instance Method Summary collapse
-
#initialize(dataSourceNode) ⇒ DataSource
constructor
A new instance of DataSource.
- #loadTables(connection) ⇒ Object
- #Parameters? ⇒ Boolean
- #processConnection ⇒ Object
- #processFields ⇒ Object
-
#setConnectionHash ⇒ Object
Notes: - TODO: need to determine which, if any, of the connection attributes should be included in the hash in order to identify it unambiguously - without local values that obscure the data source’s ‘real’ identity - attributes with value ” don’t contribute to the hash.
Constructor Details
#initialize(dataSourceNode) ⇒ DataSource
Returns a new instance of DataSource.
27 28 29 30 31 32 33 34 35 |
# File 'lib/twb/datasource.rb', line 27 def initialize dataSourceNode @node = dataSourceNode @name = @node.attr('name') @caption = @node.attr('caption') @uiname = if @caption.nil? || @caption == '' then @name else @caption end processConnection processFields return self end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def @caption end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def connection @connection end |
#connHash ⇒ Object (readonly)
Returns the value of attribute connHash.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def connHash @connHash end |
#dsclass ⇒ Object (readonly)
Returns the value of attribute dsclass.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def dsclass @dsclass end |
#localfields ⇒ Object (readonly)
Returns the value of attribute localfields.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def localfields @localfields end |
#metadatafields ⇒ Object (readonly)
Returns the value of attribute metadatafields.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def @metadatafields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def node @node end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def tables @tables end |
#uiname ⇒ Object (readonly)
Returns the value of attribute uiname.
25 26 27 |
# File 'lib/twb/datasource.rb', line 25 def uiname @uiname end |
Instance Method Details
#loadTables(connection) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/twb/datasource.rb', line 61 def loadTables connection @tables = {} nodes = connection.xpath(".//relation[@type='table']") nodes.each do |node| @tables[node.attr('name')] = node.attr('table') end end |
#Parameters? ⇒ Boolean
69 70 71 |
# File 'lib/twb/datasource.rb', line 69 def Parameters? @name == 'Parameters' end |
#processConnection ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/twb/datasource.rb', line 37 def processConnection @connection = @node.at_xpath('./connection') unless @connection.nil? @dsclass = @connection.attribute('class').text # note: must use "dsclass" as "class" would override Rubys ".class" Kernel method setConnectionHash loadTables @connection end end |
#processFields ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/twb/datasource.rb', line 73 def processFields # -- @localfields = {} @metadatafields = {} return if @connection.nil? ## load local fields connClass = @node.at_xpath('./connection').attribute('class').text fxpath = case connClass when 'dataengine' then './column' else './connection/relation/columns/column' end nodes = @node.xpath(fxpath) # puts "DATASOURCE ::=>> @node: connClass: '#{connClass.class}' ::: #{connClass.eql?('dataengine')} fxpath: #{fxpath} :: #{nodes.length}" nodes.each do |node| field = Twb::LocalField.new(node) @localfields[field.name] = field end ## load metadata fields nodes = @node.xpath("./connection/metadata-records/metadata-record[@class='column']") # note: there are other nodes "<metadata-record class='capability'>" whose nature is unclear # these nodes have no value for their <name node, so we're not loading them nodes.each do |node| field = Twb::MetadataField.new(node) @metadatafields[field.name] = field end end |
#setConnectionHash ⇒ Object
Notes:
- TODO: need to determine which, if any, of the connection attributes should be
included in the hash in order to identify it unambiguously - without
local values that obscure the data source's 'real' identity
- attributes with value '' don't contribute to the hash
52 53 54 55 56 57 58 59 |
# File 'lib/twb/datasource.rb', line 52 def setConnectionHash dsAttributes = @node.xpath('./connection/@*') dsConnStr = '' dsAttributes.each do |attr| dsConnStr += attr.text end @connHash = Digest::MD5.hexdigest(dsConnStr) end |