Class: Puppet::Pops::Model::BinaryExpression

Inherits:
Expression show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Positioned

#length, #locator, #offset

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Positioned

#file, #line, #pos

Methods inherited from PopsObject

#to_s

Methods included from Types::PuppetObject

#_pcore_type, #to_s

Constructor Details

#initialize(locator, offset, length, left_expr, right_expr) ⇒ BinaryExpression

Returns a new instance of BinaryExpression


184
185
186
187
188
189
# File 'lib/puppet/pops/model/ast.rb', line 184

def initialize(locator, offset, length, left_expr, right_expr)
  super(locator, offset, length)
  @hash = @hash ^ left_expr.hash ^ right_expr.hash
  @left_expr = left_expr
  @right_expr = right_expr
end

Instance Attribute Details

#left_exprObject (readonly)


181
182
183
# File 'lib/puppet/pops/model/ast.rb', line 181

def left_expr
  @left_expr
end

#right_exprObject (readonly)


182
183
184
# File 'lib/puppet/pops/model/ast.rb', line 182

def right_expr
  @right_expr
end

Class Method Details

._pcore_typeObject


147
148
149
150
151
152
153
154
155
# File 'lib/puppet/pops/model/ast.rb', line 147

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::BinaryExpression', {
    'parent' => Expression._pcore_type,
    'attributes' => {
      'left_expr' => Expression._pcore_type,
      'right_expr' => Expression._pcore_type
    }
  })
end

.create(locator, offset, length, left_expr, right_expr) ⇒ Object


170
171
172
173
174
175
176
177
178
179
# File 'lib/puppet/pops/model/ast.rb', line 170

def self.create(locator, offset, length, left_expr, right_expr)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Positioned[locator]', attrs['locator'].type, locator)
  ta.assert_instance_of('Puppet::AST::Positioned[offset]', attrs['offset'].type, offset)
  ta.assert_instance_of('Puppet::AST::Positioned[length]', attrs['length'].type, length)
  ta.assert_instance_of('Puppet::AST::BinaryExpression[left_expr]', attrs['left_expr'].type, left_expr)
  ta.assert_instance_of('Puppet::AST::BinaryExpression[right_expr]', attrs['right_expr'].type, right_expr)
  new(locator, offset, length, left_expr, right_expr)
end

.from_asserted_hash(init_hash) ⇒ Object


161
162
163
164
165
166
167
168
# File 'lib/puppet/pops/model/ast.rb', line 161

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['left_expr'],
    init_hash['right_expr'])
end

.from_hash(init_hash) ⇒ Object


157
158
159
# File 'lib/puppet/pops/model/ast.rb', line 157

def self.from_hash(init_hash)
  from_asserted_hash(Types::TypeAsserter.assert_instance_of('Puppet::AST::BinaryExpression initializer', _pcore_type.init_hash_type, init_hash))
end

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/puppet/pops/model/ast.rb', line 203

def _pcore_all_contents(path, &block)
  path << self
  unless @left_expr.nil?
    block.call(@left_expr, path)
    @left_expr._pcore_all_contents(path, &block)
  end
  unless @right_expr.nil?
    block.call(@right_expr, path)
    @right_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contents {|@left_expr| ... } ⇒ Object

Yields:


198
199
200
201
# File 'lib/puppet/pops/model/ast.rb', line 198

def _pcore_contents
  yield(@left_expr) unless @left_expr.nil?
  yield(@right_expr) unless @right_expr.nil?
end

#_pcore_init_hashObject


191
192
193
194
195
196
# File 'lib/puppet/pops/model/ast.rb', line 191

def _pcore_init_hash
  result = super
  result['left_expr'] = @left_expr
  result['right_expr'] = @right_expr
  result
end

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

216
217
218
219
220
# File 'lib/puppet/pops/model/ast.rb', line 216

def eql?(o)
  super &&
  @left_expr.eql?(o.left_expr) &&
  @right_expr.eql?(o.right_expr)
end