Class: ActiveRecord::CacheSQLQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/cachear.rb

Constant Summary collapse

RE_TABLES =
/FROM(.+?)(?:(WHERE)|(LIMIT)|($))/i
@@queries =
Hash.new { |hsh, query| hsh[query] = self.new(query) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ CacheSQLQuery

Returns a new instance of CacheSQLQuery.



84
85
86
# File 'lib/cachear.rb', line 84

def initialize(str)
  @sql = str.gsub(/[\r\n]/,' ')
end

Instance Attribute Details

#sqlObject (readonly)

Returns the value of attribute sql.



76
77
78
# File 'lib/cachear.rb', line 76

def sql
  @sql
end

Class Method Details

.create(str) ⇒ Object



80
81
82
# File 'lib/cachear.rb', line 80

def self.create(str)
  @@queries[str]
end

Instance Method Details

#==(oth) ⇒ Object



108
109
110
# File 'lib/cachear.rb', line 108

def == (oth)
  @sql == oth.sql
end

#eql?(oth) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/cachear.rb', line 112

def eql?(oth)
  self == oth
end

#inspectObject



104
105
106
# File 'lib/cachear.rb', line 104

def inspect
  "<sql: #{to_s.inspect}>"
end

#tablesObject



88
89
90
91
92
93
94
# File 'lib/cachear.rb', line 88

def tables
  return @tables if @tables
  raw = @sql.scan(RE_TABLES).flatten[0].strip.split(/,/)
  @tables = raw.map do |r|
    r.strip.gsub(/\s+.+$/,'').strip
  end.uniq
end

#to_sObject



96
97
98
# File 'lib/cachear.rb', line 96

def to_s
  @sql
end

#to_strObject



100
101
102
# File 'lib/cachear.rb', line 100

def to_str
  to_s
end