Class: Qdsl::FormatCall
- Inherits:
-
Object
- Object
- Qdsl::FormatCall
- Defined in:
- lib/format_call.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #as(name) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(source, format, parameters, name = nil) ⇒ FormatCall
constructor
A new instance of FormatCall.
- #render_sql(context, id) ⇒ Object
Constructor Details
#initialize(source, format, parameters, name = nil) ⇒ FormatCall
Returns a new instance of FormatCall.
5 6 7 8 9 10 |
# File 'lib/format_call.rb', line 5 def initialize(source, format, parameters, name = nil) @source = source @format = format @parameters = parameters @name = name.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/format_call.rb', line 3 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/format_call.rb', line 3 def source @source end |
Instance Method Details
#as(name) ⇒ Object
12 13 14 |
# File 'lib/format_call.rb', line 12 def as(name) FormatCall.new(@source, @format, @parameters, name) end |
#exists? ⇒ Boolean
16 17 18 |
# File 'lib/format_call.rb', line 16 def exists? @parameters.all? { |x| x.exists? } end |
#render_sql(context, id) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/format_call.rb', line 20 def render_sql(context, id) parameter_results = @parameters.collect { |x| x.render_sql(context, id) } query_parameters = parameter_results.collect(&:parameters).inject({}) { |acc, x| acc.merge!(x) } call = do_format(@format, parameter_results.collect(&:sql)) SimpleRenderResult.new(@name ? "#{call} AS #{@name}" : call, query_parameters) end |