Sha256: 062a87d2097203a6ec74307cf639a864a560c72bcbf4c26558a68883d7c6a151
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
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 def adjective_and_argument(*args) if args.size > 1 adjective = args[0] record = args[1] else adjective = nil record = args[0] end [adjective, record] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
consul-0.6.1 | lib/consul/util.rb |
consul-0.6.0 | lib/consul/util.rb |