Class: OracleSqlParser::Ast::Hash

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/oracle-sql-parser/ast/hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #ast, find_different_value

Constructor Details

#initialize(value) ⇒ Hash

Returns a new instance of Hash.



8
9
10
11
# File 'lib/oracle-sql-parser/ast/hash.rb', line 8

def initialize(value)
  raise "only ::Hash instance" unless value.instance_of? ::Hash
  @ast = value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



39
40
41
42
# File 'lib/oracle-sql-parser/ast/hash.rb', line 39

def method_missing(name, *args)
  return @ast.send(:[], name) if @ast.has_key? name
  raise "no method:#{name}, #{@ast.class} in #{self.class}"
end

Class Method Details

.[](value) ⇒ Object



35
36
37
# File 'lib/oracle-sql-parser/ast/hash.rb', line 35

def self.[](value)
  self.new(value)
end

Instance Method Details

#inspectObject



19
20
21
22
23
# File 'lib/oracle-sql-parser/ast/hash.rb', line 19

def inspect
  "#<#{self.class.name}\n" + 
  @ast.map{|k,v| "#{k.inspect} => #{v.inspect}"}.join(",\n").gsub(/^/, '  ') +
  "}>\n"
end

#remove_nil_values!Object



13
14
15
16
17
# File 'lib/oracle-sql-parser/ast/hash.rb', line 13

def remove_nil_values!
  @ast.delete_if{|k, v| v.nil?}
  @ast.each {|k, v| v.remove_nil_values! if v.respond_to? :remove_nil_values!}
  self
end

#to_sqlObject



25
26
27
28
29
30
31
32
33
# File 'lib/oracle-sql-parser/ast/hash.rb', line 25

def to_sql
  @ast.map do |k,v|
    if v.respond_to? :to_sql
      v.to_sql
    else
      v.to_s
    end
  end.compact.join(" ")
end