Class: BlazerJsonAPI::ProcessStatementVariables
- Inherits:
-
Object
- Object
- BlazerJsonAPI::ProcessStatementVariables
- Defined in:
- lib/blazer_json_api/process_statement_variables.rb
Instance Attribute Summary collapse
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(statement, data_source, params) ⇒ ProcessStatementVariables
constructor
A new instance of ProcessStatementVariables.
Constructor Details
#initialize(statement, data_source, params) ⇒ ProcessStatementVariables
Returns a new instance of ProcessStatementVariables.
10 11 12 13 14 |
# File 'lib/blazer_json_api/process_statement_variables.rb', line 10 def initialize(statement, data_source, params) @statement = statement @data_source = data_source @params = params end |
Instance Attribute Details
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
8 9 10 |
# File 'lib/blazer_json_api/process_statement_variables.rb', line 8 def data_source @data_source end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/blazer_json_api/process_statement_variables.rb', line 8 def params @params end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
8 9 10 |
# File 'lib/blazer_json_api/process_statement_variables.rb', line 8 def statement @statement end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/blazer_json_api/process_statement_variables.rb', line 16 def call bind_variables.each do |variable| value = params[variable].presence if value if variable.end_with?('_at') begin value = Blazer.time_zone.parse(value) rescue StandardError # do nothing end end if /\A\d+\z/.match?(value.to_s) value = value.to_i elsif /\A\d+\.\d+\z/.match?(value.to_s) value = value.to_f end end if Blazer.transform_variable value = Blazer.transform_variable.call(variable, value) end statement.gsub!("{#{variable}}", ActiveRecord::Base.connection.quote(value)) end end |