Class: OracleSqlParser::Ast::Base
- Includes:
- Util::Parameterizable
- Defined in:
- lib/oracle-sql-parser/ast/base.rb
Class Method Summary collapse
- .[](value) ⇒ Object
- .deep_dup(original) ⇒ Object
- .find_different_value(left, right, &block) ⇒ Object
Instance Method Summary collapse
- #==(value) ⇒ Object
- #ast ⇒ Object
- #deep_dup ⇒ Object
-
#initialize(arg) ⇒ Base
constructor
A new instance of Base.
- #initialize_copy(original) ⇒ Object
- #inspect ⇒ Object (also: #to_s)
- #map_ast(&block) ⇒ Object
- #map_ast!(&block) ⇒ Object
- #remove_nil_values! ⇒ Object
- #to_sql(options = {}) ⇒ Object
Methods included from Util::Parameterizable
#to_parameterized, #to_parameternized
Constructor Details
Class Method Details
.[](value) ⇒ Object
131 132 133 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 131 def self.[](value) self.new(value) end |
.deep_dup(original) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 74 def self.deep_dup(original) if original.is_a? OracleSqlParser::Ast::Base original.deep_dup elsif original.is_a? ::Hash ::Hash[ original.map {|k, v| [k, deep_dup(v)]} ] elsif original.is_a? ::Array original.map {|v| deep_dup(v)} elsif original.duplicable? original.dup else original end end |
.find_different_value(left, right, &block) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 135 def self.find_different_value(left, right, &block) if left.class != right.class block.call(left, right) if block_given? return true end result = false case left when Base result ||= self.find_different_value( left.instance_variable_get(:@ast), right.instance_variable_get(:@ast), &block) when Hash (left.keys + right.keys).uniq.each do |key| result ||= self.find_different_value(left[key], right[key], &block) end when OracleSqlParser::Ast::Array if left.size == right.size left.each_with_index do |value, index| result ||= self.find_different_value(value, right[index], &block) end else block.call(left, right) if block_given? result = true end else if left != right block.call(left, right) if block_given? result = true end end result end |
Instance Method Details
#==(value) ⇒ Object
170 171 172 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 170 def ==(value) self.class.find_different_value(self, value) != true end |
#ast ⇒ Object
119 120 121 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 119 def ast raise "do not call ast method" end |
#deep_dup ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 88 def deep_dup copy = self.class.new original_ast = self.instance_variable_get(:@ast) copy_ast = self.class.deep_dup(original_ast) copy.instance_variable_set(:@ast, copy_ast) copy end |
#initialize_copy(original) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 66 def initialize_copy(original) if @ast.nil? self.class.new else self.class.new(original.instance_variable_get(:@ast).dup) end end |
#inspect ⇒ Object Also known as: to_s
114 115 116 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 114 def inspect "#<#{self.class.name} #{@ast.inspect}>" end |
#map_ast(&block) ⇒ Object
96 97 98 99 100 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 96 def map_ast(&block) duplicated = self.deep_dup duplicated.map_ast!(&block) duplicated end |
#map_ast!(&block) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 102 def map_ast!(&block) if @ast.is_a? OracleSqlParser::Ast::Base @ast.map_ast!(&block) end @ast = block.call(@ast) end |
#remove_nil_values! ⇒ Object
109 110 111 112 |
# File 'lib/oracle-sql-parser/ast/base.rb', line 109 def remove_nil_values! @ast.remove_nil_values! if @ast.respond_to? :remove_nil_values! self end |