Class: Row
- Inherits:
-
Object
show all
- Defined in:
- lib/lilit_sql.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(columns, origins = []) ⇒ Row
Returns a new instance of Row.
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/lilit_sql.rb', line 212
def initialize(columns, origins = [])
@columns = columns.zip(origins).map do |col, origin|
if col.is_a?(Symbol)
Column.new(col, origin)
elsif col.is_a?(Column)
col
else
raise NotImplementedError
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
246
247
248
249
250
|
# File 'lib/lilit_sql.rb', line 246
def method_missing(symbol, *args)
col(symbol)
rescue ArgumentError
super
end
|
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
210
211
212
|
# File 'lib/lilit_sql.rb', line 210
def columns
@columns
end
|
Instance Method Details
#col(name) ⇒ Object
224
225
226
227
228
229
230
|
# File 'lib/lilit_sql.rb', line 224
def col(name)
found = @columns.select { |c| c.name == name }.first
raise ArgumentError, "#{name} is not found in the columns: #{@columns.map(&:name).inspect}" if found.nil?
found
end
|
#decl_sql ⇒ Object
240
241
242
|
# File 'lib/lilit_sql.rb', line 240
def decl_sql
@columns.map(&:decl_sql).join(', ')
end
|
#has?(name) ⇒ Boolean
236
237
238
|
# File 'lib/lilit_sql.rb', line 236
def has?(name)
@columns.any? { |c| c.name == name }
end
|
#with_from(from) ⇒ Object
232
233
234
|
# File 'lib/lilit_sql.rb', line 232
def with_from(from)
Row.new(@columns.map { |c| c.with_from(from) })
end
|