Class: Sqlyzer::Parameter::List
- Inherits:
-
Array
- Object
- Array
- Sqlyzer::Parameter::List
- Defined in:
- lib/sqlyzer/parameters.rb
Overview
Overloaded Array class to store Default class list.
Instance Method Summary collapse
-
#fetch_parameter(key) ⇒ Object
(also: #[])
Search trough contained Default classes for key.
-
#initialize(elements = nil) ⇒ List
constructor
Create a new instance of List with given elements considered as an Array of Symbol or a List.
-
#join(separator = ', ', suffix = '') ⇒ Object
(also: #join_parameters)
Overloaded version on Array#join to handle suffix on each element.
-
#push(symbol) ⇒ Object
(also: #push_parameter, #<<)
Push a symbol on the top of the Array.
-
#push_parameters(data) ⇒ Object
(also: #+)
Push each item of data Array by calling previous push_paramether method.
-
#to_sql(owner) ⇒ Object
Return a new Array class containing each contained Default class Sql representation from values retreived in owner.
Constructor Details
#initialize(elements = nil) ⇒ List
Create a new instance of List with given elements considered as an Array of Symbol or a List. If no parameter is given, create an empty List.
351 352 353 |
# File 'lib/sqlyzer/parameters.rb', line 351 def initialize(elements = nil) push_parameters elements if elements end |
Instance Method Details
#fetch_parameter(key) ⇒ Object Also known as: []
Search trough contained Default classes for key. key should be a Default class, a Symbol or a String.
See Default#<=> for more informations.
375 376 377 378 379 380 381 382 383 |
# File 'lib/sqlyzer/parameters.rb', line 375 def fetch_parameter(key) each { |parameter| if parameter == key yield parameter if block_given? return parameter end } nil end |
#join(separator = ', ', suffix = '') ⇒ Object Also known as: join_parameters
Overloaded version on Array#join to handle suffix on each element.
419 420 421 |
# File 'lib/sqlyzer/parameters.rb', line 419 def join(separator = ', ', suffix = '') "#{super("#{suffix}#{separator}")}#{suffix}" end |
#push(symbol) ⇒ Object Also known as: push_parameter, <<
Push a symbol on the top of the Array. symbol should be Default class or a Symbol. If symbol is a Symbol, it will be automatically converted to a Default class extended with Text Sql type handling.
394 395 396 397 398 399 400 401 |
# File 'lib/sqlyzer/parameters.rb', line 394 def push(symbol) return if include?(symbol) if symbol.kind_of?(Default) super symbol else super(symbol/Sqlyzer::Parameter::Types::Text) end end |
#push_parameters(data) ⇒ Object Also known as: +
Push each item of data Array by calling previous push_paramether method.
408 409 410 411 412 413 |
# File 'lib/sqlyzer/parameters.rb', line 408 def push_parameters(data) data.each { |symbol| push symbol } self end |
#to_sql(owner) ⇒ Object
Return a new Array class containing each contained Default class Sql representation from values retreived in owner.
361 362 363 364 365 |
# File 'lib/sqlyzer/parameters.rb', line 361 def to_sql(owner) collect { |symbol| symbol.to_sql owner } end |