Module: SqlTagger::Initializer

Defined in:
lib/sql_tagger.rb

Overview

Mixin that monkey patches the receiver’s initialize method to set @sql_tagger.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sql_taggerSqlTagger

Returns the SqlTagger used to tag queries for this instance.

Returns:

  • (SqlTagger)

    the SqlTagger used to tag queries for this instance



75
76
77
# File 'lib/sql_tagger.rb', line 75

def sql_tagger
  @sql_tagger
end

Class Method Details

.included(base) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/sql_tagger.rb', line 63

def self.included(base)
  base.send(:alias_method, :initialize_without_sql_tagger, :initialize)
  base.send(:alias_method, :initialize, :initialize_with_sql_tagger)

  # This is for the odd case where a SQL gem/library is used before
  # sql_tagger is required.
  ObjectSpace.each_object(base) do |obj|
    obj.sql_tagger ||= SqlTagger.default
  end
end

Instance Method Details

#initialize_with_sql_tagger(*args, &block) ⇒ Object



77
78
79
80
# File 'lib/sql_tagger.rb', line 77

def initialize_with_sql_tagger(*args, &block)
  @sql_tagger = SqlTagger.default
  initialize_without_sql_tagger(*args, &block)
end