Sha256: da03426e1ce92487e71ae4dfc195dbd00c24c6436f8e1306721619c7ccf6d603
Contents?: true
Size: 902 Bytes
Versions: 1
Compression:
Stored size: 902 Bytes
Contents
module Consul module Util extend self def scope_to_sql(scope) if scope.respond_to?(:to_sql) scope.to_sql else scope.send(:construct_finder_sql, {}) end end def scope_selects_all_records?(scope) scope = scope.scoped({}) scope_sql = scope_to_sql(scope) quoted_table_name = Regexp.quote(scope.connection.quote_table_name(scope.table_name)) all_sql_pattern = /\ASELECT (#{quoted_table_name}\.)?\* FROM #{quoted_table_name}\z/ scope_sql.squish =~ all_sql_pattern end def scope?(value) value.respond_to?(:scoped) end def collection?(value) value.is_a?(Array) || value.is_a?(Set) end def define_scope(klass, name, options) if Rails.version.to_i < 3 klass.send(:named_scope, name, options) else klass.send(:scope, name, options) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
consul-0.5.0 | lib/consul/util.rb |