Class: QueryBuilder::Core::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/query_builder/core/base.rb

Overview

This class is abstract.

The abstract base class for all nodes of AST: statemens, clauses, operators

Declares common attributes, ‘#initializer`, and `#to_s` instance methods.

Direct Known Subclasses

Clause, Statement

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Initializes the instance

Parameters:

  • attributes (Hash) (defaults to: {})

    The custom attributes of the instance



57
58
59
60
61
62
63
# File 'lib/query_builder/core/base.rb', line 57

def initialize(attributes = {})
  validate_unknown attributes
  validate_missing attributes

  @attributes = default_attributes.merge(attributes)
  IceNine.deep_freeze(self)
end

Instance Attribute Details

#attributesHash (readonly)

Returns The hash of the initialized attributes.

Returns:

  • (Hash)

    The hash of the initialized attributes



18
19
20
# File 'lib/query_builder/core/base.rb', line 18

def self.attributes
  @attributes ||= Set.new
end

Class Method Details

.attribute(name, options = {}) ⇒ undefined

Declares the attribute with optional default value

Parameters:

  • name (Symbol)

    The name of the attribute

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :default (Object)

Returns:

  • (undefined)


31
32
33
34
# File 'lib/query_builder/core/base.rb', line 31

def self.attribute(name, options = {})
  attributes << Attribute.new(name, options)
  define_method(name) { attributes.fetch(name) }
end

.attributesHash

The hash of default attributes of class’ instances

Returns:

  • (Hash)


18
19
20
# File 'lib/query_builder/core/base.rb', line 18

def self.attributes
  @attributes ||= Set.new
end

.inherited(subclass) ⇒ Object

Makes default attributes inheritable



40
41
42
43
44
# File 'lib/query_builder/core/base.rb', line 40

def self.inherited(subclass)
  attributes.each do |item|
    subclass.public_send(:attribute, *item.arguments)
  end
end

Instance Method Details

#attribute(name, options) ⇒ undefined

Declares the attribute with optional default value

Parameters:

  • name (Symbol)

    The name of the attribute

  • options (Hash)

Options Hash (options):

  • :default (Object)

Returns:

  • (undefined)


31
32
33
34
# File 'lib/query_builder/core/base.rb', line 31

def self.attribute(name, options = {})
  attributes << Attribute.new(name, options)
  define_method(name) { attributes.fetch(name) }
end

#to_sString

This method is abstract.

Returns the current chunk of CQL statement

Returns:

  • (String)


72
73
74
# File 'lib/query_builder/core/base.rb', line 72

def to_s
  ""
end