class Tablescript::Namespace
Attributes
namespaces[R]
parent[R]
tables[R]
Public Class Methods
new(name = '', parent = nil)
click to toggle source
# File lib/tablescript/namespace.rb, line 25 def initialize(name = '', parent = nil) @name = name @parent = parent @namespaces = {} @tables = {} end
Public Instance Methods
add(table)
click to toggle source
# File lib/tablescript/namespace.rb, line 32 def add(table) raise Exception, "Table #{table.name} already defined" if @tables.key?(table.name) @tables[table.name] = table end
each_namespace(&blk)
click to toggle source
# File lib/tablescript/namespace.rb, line 77 def each_namespace(&blk) @namespaces.each_value(&blk) end
each_table(&blk)
click to toggle source
# File lib/tablescript/namespace.rb, line 81 def each_table(&blk) @tables.each_value(&blk) end
name()
click to toggle source
# File lib/tablescript/namespace.rb, line 72 def name return 'global' if @parent.nil? @name end
namespace(name)
click to toggle source
# File lib/tablescript/namespace.rb, line 68 def namespace(name) @namespaces[name] ||= Namespace.new(name, self) end
resolve(path)
click to toggle source
# File lib/tablescript/namespace.rb, line 46 def resolve(path) parts = path.split('/') return table(path) if parts.size == 1 if parts[0] == @name return table(parts[1]) if parts.size == 2 raise Exception, "Namespace #{parts[1]} not found in #{name} namespace (#{path})" unless @namespaces.key?(parts[1]) return @namespaces[parts[1]].resolve(parts[1..-1].join('/')) else raise Exception, "Namespace #{parts[0]} not found in #{name} namespace (#{path})" unless @namespaces.key?(parts[0]) return @namespaces[parts[0]].resolve(parts[1..-1].join('/')) end end
resolve?(path)
click to toggle source
# File lib/tablescript/namespace.rb, line 37 def resolve?(path) begin resolve(path) rescue Tablescript::Exception return false end true end
table(table_name)
click to toggle source
# File lib/tablescript/namespace.rb, line 59 def table(table_name) raise Exception, "No such table #{table_name} in #{name}" unless @tables.key?(table_name) @tables[table_name] end
table?(table_name)
click to toggle source
# File lib/tablescript/namespace.rb, line 64 def table?(table_name) @tables.key?(table_name) end