Class: ActiveRecord::CacheSQLQuery
- Inherits:
-
Object
- Object
- ActiveRecord::CacheSQLQuery
- 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
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
Class Method Summary collapse
Instance Method Summary collapse
- #==(oth) ⇒ Object
- #eql?(oth) ⇒ Boolean
-
#initialize(str) ⇒ CacheSQLQuery
constructor
A new instance of CacheSQLQuery.
- #inspect ⇒ Object
- #tables ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
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
#sql ⇒ Object (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
112 113 114 |
# File 'lib/cachear.rb', line 112 def eql?(oth) self == oth end |
#inspect ⇒ Object
104 105 106 |
# File 'lib/cachear.rb', line 104 def inspect "<sql: #{to_s.inspect}>" end |
#tables ⇒ Object
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_s ⇒ Object
96 97 98 |
# File 'lib/cachear.rb', line 96 def to_s @sql end |
#to_str ⇒ Object
100 101 102 |
# File 'lib/cachear.rb', line 100 def to_str to_s end |