Class: Row

Inherits:
Object
  • 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 (private)



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

#columnsObject

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

Raises:

  • (ArgumentError)


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_sqlObject



240
241
242
# File 'lib/lilit_sql.rb', line 240

def decl_sql
  @columns.map(&:decl_sql).join(', ')
end

#has?(name) ⇒ Boolean

Returns:

  • (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