omf_oml 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+
2
+ require 'omf_common/lobject'
3
+ require 'omf_oml'
4
+ require 'omf_oml/schema'
5
+
6
+ module OMF::OML
7
+
8
+ # This class represents a tuple with an associated schema.
9
+ # It provides various methods to access the tuple elements.
10
+ #
11
+ # NOTE: Do not store the tuple itself, but make a copy as the instance may be
12
+ # reused over various rows by the sender.
13
+ #
14
+ # Use +OmlTuple+ if the schema is an OML one. +OmlTuple+ has additional convenience
15
+ # methods.
16
+ #
17
+ class Tuple < OMF::Common::LObject
18
+
19
+ # Return a specific element of the tuple identified either
20
+ # by it's name, or its col index
21
+ #
22
+ def [](name_or_index)
23
+ @vprocs[name_or_index].call(@raw)
24
+ end
25
+
26
+ # Return the elements of the tuple as an array
27
+ def to_a()
28
+ # res = []
29
+ # r = @raw
30
+ # @schema.each do |col|
31
+ # res << @vprocs[col[:name]].call(r)
32
+ # end
33
+ # res
34
+ @schema.cast_row(@raw)
35
+ end
36
+
37
+ # Return an array including the values for the names elements
38
+ # given as parameters.
39
+ #
40
+ def select(*col_names)
41
+ r = @raw
42
+ col_names.collect do |n|
43
+ p = @vprocs[n]
44
+ p ? p.call(r) : nil
45
+ end
46
+ end
47
+
48
+ attr_reader :schema
49
+ attr_reader :stream_name
50
+
51
+ def initialize(name, schema)
52
+ # if schema.kind_of? Array
53
+ # schema = OmlSchema.new(schema)
54
+ # end
55
+ @stream_name = name
56
+ @schema = OmlSchema.create(schema)
57
+
58
+ @raw = []
59
+ # puts "SCHEMA: #{schema.inspect}"
60
+ @on_new_tuple_procs = {}
61
+
62
+ super name
63
+ process_schema(@schema)
64
+ end
65
+
66
+
67
+ # Parse the array of strings into the proper typed vector elements
68
+ #
69
+ # NOTE: We assume that each element is only called at most once, with some
70
+ # never called. We therefore delay type-casting to the get function without
71
+ # keeping the casted values (would increase lookup time)
72
+ #
73
+ def parse_tuple(els)
74
+ @raw = els
75
+ @on_new_tuple_procs.each_value do |proc|
76
+ proc.call(self)
77
+ end
78
+ end
79
+
80
+ # Register a proc to be called when a new tuple arrived
81
+ #
82
+ def on_new_tuple(key = :_, &proc)
83
+ if proc
84
+ @on_new_tuple_procs[key] = proc
85
+ else
86
+ @on_new_tuple_procs.delete key
87
+ end
88
+ end
89
+
90
+
91
+ protected
92
+ def process_schema(schema)
93
+ i = 0
94
+ @vprocs = {}
95
+ schema.each_column do |col| #
96
+ name = col[:name] || raise("Ill-formed schema '#{schema}'")
97
+ type = col[:type] || raise("Ill-formed schema '#{schema}'")
98
+ @vprocs[name] = @vprocs[i] = case type
99
+ when :string
100
+ lambda do |r| r[i] end
101
+ when :float
102
+ lambda do |r| r[i].to_f end
103
+ else raise "Unrecognized Schema type '#{type}'"
104
+ end
105
+ i += 1
106
+ end
107
+ end
108
+
109
+ end # Tuple
110
+ end # OMF::OML
@@ -0,0 +1,6 @@
1
+
2
+ module OMF
3
+ module OML
4
+ VERSION = '0.9.3'
5
+ end
6
+ end
data/lib/omf_oml.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ module OMF
3
+ module OML; end
4
+ end
data/omf_oml.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omf_oml/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omf_oml"
7
+ # s.version = OmfWeb::VERSION
8
+ s.version = OMF::OML::VERSION
9
+ s.authors = ["NICTA"]
10
+ s.email = ["omf-user@lists.nicta.com.au"]
11
+ s.homepage = "https://www.mytestbed.net"
12
+ s.summary = %q{Glue between OMF and OML.}
13
+ s.description = %q{Glue functionality between OMF and OMF related libraries, such as OMF Web and Labwiki, and
14
+ OML.}
15
+
16
+ s.rubyforge_project = "omf_oml"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ # s.add_development_dependency "minitest", "~> 2.11.3"
25
+ s.add_runtime_dependency "sqlite3", "~> 1.3.6"
26
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omf_oml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - NICTA
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: &13713900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13713900
25
+ description: ! "Glue functionality between OMF and OMF related libraries, such as
26
+ OMF Web and Labwiki, and\n OML."
27
+ email:
28
+ - omf-user@lists.nicta.com.au
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - Rakefile
36
+ - lib/omf_oml.rb
37
+ - lib/omf_oml/endpoint.rb
38
+ - lib/omf_oml/indexed_table.rb
39
+ - lib/omf_oml/network.rb
40
+ - lib/omf_oml/oml_tuple.rb
41
+ - lib/omf_oml/schema.rb
42
+ - lib/omf_oml/sequel/sequel_server.rb
43
+ - lib/omf_oml/sql_row.rb
44
+ - lib/omf_oml/sql_source.rb
45
+ - lib/omf_oml/table.rb
46
+ - lib/omf_oml/tuple.rb
47
+ - lib/omf_oml/version.rb
48
+ - omf_oml.gemspec
49
+ homepage: https://www.mytestbed.net
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: omf_oml
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Glue between OMF and OML.
73
+ test_files: []