Class: ScopeSqlCounter::Syntax
- Inherits:
-
Object
- Object
- ScopeSqlCounter::Syntax
- Defined in:
- lib/scope_sql_counter/syntax.rb
Constant Summary collapse
- COUNTER_SQL_QUERY =
" (\n SELECT COUNT(:target.id)\n FROM :target\n WHERE :target.:foreign_key = :context.id\n :conditions\n ) AS :alias\n"
Instance Attribute Summary collapse
-
#association_key ⇒ Object
readonly
Returns the value of attribute association_key.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#count_alias ⇒ Object
readonly
Returns the value of attribute count_alias.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(context:, association_key:, conditions: nil, count_alias: nil) ⇒ Syntax
constructor
A new instance of Syntax.
Constructor Details
#initialize(context:, association_key:, conditions: nil, count_alias: nil) ⇒ Syntax
16 17 18 19 20 21 |
# File 'lib/scope_sql_counter/syntax.rb', line 16 def initialize(context:, association_key:, conditions: nil, count_alias: nil) @context = context @association_key = association_key @conditions = conditions @count_alias = count_alias end |
Instance Attribute Details
#association_key ⇒ Object (readonly)
Returns the value of attribute association_key.
14 15 16 |
# File 'lib/scope_sql_counter/syntax.rb', line 14 def association_key @association_key end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
14 15 16 |
# File 'lib/scope_sql_counter/syntax.rb', line 14 def conditions @conditions end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
14 15 16 |
# File 'lib/scope_sql_counter/syntax.rb', line 14 def context @context end |
#count_alias ⇒ Object (readonly)
Returns the value of attribute count_alias.
14 15 16 |
# File 'lib/scope_sql_counter/syntax.rb', line 14 def count_alias @count_alias end |
Instance Method Details
#call ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/scope_sql_counter/syntax.rb', line 23 def call if !context.respond_to?(:select_values) || context.select_values.blank? ["#{context.table_name}.*", query].join(', ') else query end end |