Class: Ronin::SQL::Field

Inherits:
Struct
  • Object
show all
Includes:
Emittable, Operators
Defined in:
lib/ronin/sql/field.rb

Overview

Represents a SQL column, table or database name.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Emittable

#emitter, #inspect, #to_s, #to_sql

Methods included from Operators

#!, #!=, #%, #&, #*, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #and, #as, #glob, #in, #is, #is_not, #like, #match, #not, #or, #regexp, #|, #~

Constructor Details

#initialize(name, parent = nil) ⇒ Field

Initializes the new field.

Parameters:

  • name (String)

    The name of the field.

  • parent (Field) (defaults to: nil)

    The parent of the field.



47
48
49
# File 'lib/ronin/sql/field.rb', line 47

def initialize(name,parent=nil)
  super(name.to_s,parent)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments) ⇒ Object (protected)

Allows accessing columns from tables or tables from databases.

Examples:

db.users
users.id

Parameters:

  • name (Symbol)

    The sub-field name.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ronin/sql/field.rb', line 84

def method_missing(name,*arguments)
  unless arguments.empty?
    raise(ArgumentError,"canot access columns or tables with arguments")
  end

  if (self.parent.nil? || self.parent.parent.nil?)
    Field.new(name,self)
  else
    raise(NoMethodError,"cannot access coumns from other columns")
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



33
34
35
# File 'lib/ronin/sql/field.rb', line 33

def name
  @name
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



33
34
35
# File 'lib/ronin/sql/field.rb', line 33

def parent
  @parent
end

Class Method Details

.parse(name) ⇒ Field

Parses a field.

Parameters:

Returns:

  • (Field)

    The parsed field.



59
60
61
62
63
64
65
66
# File 'lib/ronin/sql/field.rb', line 59

def self.parse(name)
  names = name.to_s.split('.',3)
  field = nil

  names.each { |name| field = new(name,field) }

  return field
end