Class: QueryBuilder::Core::Attribute

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

Overview

Describes the attribute of AST node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Attribute

Initializes the attribute with name and options

Parameters:

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

Options Hash (options):

  • :default (Object)

    The default value for the attribute

  • :required (Boolean)

    Whether the attribute is required



36
37
38
39
40
41
42
# File 'lib/query_builder/core/attribute.rb', line 36

def initialize(name, options = {})
  @name     = name
  @default  = options[:default]
  @required = options.fetch(:required) { false }

  IceNine.deep_freeze(self)
end

Instance Attribute Details

#defaultObject (readonly)

Returns The default value for the attribute.

Returns:

  • (Object)

    The default value for the attribute



21
22
23
# File 'lib/query_builder/core/attribute.rb', line 21

def default
  @default
end

#nameSymbol (readonly)

Returns The name of the attribute.

Returns:

  • (Symbol)

    The name of the attribute



15
16
17
# File 'lib/query_builder/core/attribute.rb', line 15

def name
  @name
end

#requiredBoolean (readonly)

Returns Whether the attribute is required or not.

Returns:

  • (Boolean)

    Whether the attribute is required or not



27
28
29
# File 'lib/query_builder/core/attribute.rb', line 27

def required
  @required
end

Instance Method Details

#argumentsArray

Returns arguments of the attribute initializer

Returns:

  • (Array)


48
49
50
# File 'lib/query_builder/core/attribute.rb', line 48

def arguments
  [name, default: default, required: required]
end