Class: Ronin::Code::SQL::Field
- Inherits:
-
Object
- Object
- Ronin::Code::SQL::Field
- Defined in:
- lib/ronin/code/sql/field.rb
Overview
Represents a SQL column, table or database name.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the field.
-
#parent ⇒ Field?
readonly
The parent of the field name.
Class Method Summary collapse
-
.parse(name) ⇒ Field
Parses a field.
Instance Method Summary collapse
-
#initialize(name, parent = nil) ⇒ Field
constructor
Initializes the new field.
-
#method_missing(name, *arguments) ⇒ Field
protected
Allows accessing columns from tables or tables from databases.
-
#respond_to_missing?(name) ⇒ Boolean
Determines if the field responds to the given method.
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.
56 57 58 59 |
# File 'lib/ronin/code/sql/field.rb', line 56 def initialize(name,parent=nil) @name = name.to_s @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments) ⇒ Field (protected)
Allows accessing columns from tables or tables from databases.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ronin/code/sql/field.rb', line 120 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 columns from other columns") end end |
Instance Attribute Details
#name ⇒ String (readonly)
The name of the field.
40 41 42 |
# File 'lib/ronin/code/sql/field.rb', line 40 def name @name end |
#parent ⇒ Field? (readonly)
The parent of the field name.
45 46 47 |
# File 'lib/ronin/code/sql/field.rb', line 45 def parent @parent end |
Class Method Details
.parse(name) ⇒ Field
Parses a field.
69 70 71 72 73 74 75 76 |
# File 'lib/ronin/code/sql/field.rb', line 69 def self.parse(name) names = name.to_s.split('.',3) field = nil names.each { |keyword| field = new(keyword,field) } return field end |
Instance Method Details
#respond_to_missing?(name) ⇒ Boolean
Determines if the field responds to the given method.
90 91 92 |
# File 'lib/ronin/code/sql/field.rb', line 90 def respond_to_missing?(name) self.parent.nil? || self.parent.parent.nil? end |