Class: SQL::Composer::Tokens
- Inherits:
-
Object
- Object
- SQL::Composer::Tokens
- Includes:
- Dry::Core::Constants
- Defined in:
- lib/sql/composer/tokens.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add(key, node) ⇒ Object
-
#initialize(data: {}, counter: 0) ⇒ Tokens
constructor
A new instance of Tokens.
- #new ⇒ Object
- #next_id ⇒ Object
- #set(key, value) ⇒ Object
- #value(id, default) ⇒ Object
Constructor Details
#initialize(data: {}, counter: 0) ⇒ Tokens
Returns a new instance of Tokens.
10 11 12 13 |
# File 'lib/sql/composer/tokens.rb', line 10 def initialize(data: {}, counter: 0) @data = data @counter = counter end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/sql/composer/tokens.rb', line 8 def data @data end |
Instance Method Details
#add(key, node) ⇒ Object
15 16 17 18 |
# File 'lib/sql/composer/tokens.rb', line 15 def add(key, node) data[key[1..-2].to_sym] = [node.id, Undefined] self end |
#new ⇒ Object
26 27 28 |
# File 'lib/sql/composer/tokens.rb', line 26 def new self.class.new(data: data.dup, counter: @counter) end |
#next_id ⇒ Object
35 36 37 |
# File 'lib/sql/composer/tokens.rb', line 35 def next_id @counter += 1 end |
#set(key, value) ⇒ Object
20 21 22 23 24 |
# File 'lib/sql/composer/tokens.rb', line 20 def set(key, value) tuple = [data[key][0], value] data[key] = tuple self end |
#value(id, default) ⇒ Object
30 31 32 33 |
# File 'lib/sql/composer/tokens.rb', line 30 def value(id, default) entry = data.detect { |_, (node_id, value)| node_id.equal?(id) } entry ? entry[1][1] : default end |