Sha256: 124d10c8b5aecb8a35d826fc0682b66895f28f870c551800754823f1159234b6
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
module SearchCop class Reflection attr_accessor :attributes, :options, :aliases, :scope, :generators def initialize self.attributes = {} self.options = {} self.aliases = {} self.generators = {} end def default_attributes keys = options.select { |_key, value| value[:default] == true }.keys keys = attributes.keys.reject { |key| options[key] && options[key][:default] == false } if keys.empty? keys = keys.to_set attributes.select { |key, _value| keys.include? key } end end class SearchScope attr_accessor :name, :model, :reflection def initialize(name, model) self.model = model self.reflection = Reflection.new end def attributes(*args) args.each do |arg| attributes_hash arg.is_a?(Hash) ? arg : { arg => arg } end end def options(key, options = {}) reflection.options[key.to_s] = (reflection.options[key.to_s] || {}).merge(options) end def aliases(hash) hash.each do |key, value| reflection.aliases[key.to_s] = value.is_a?(Class) ? value : value.to_s end end def scope(&block) reflection.scope = block end def generator(name, &block) reflection.generators[name] = block end private def attributes_hash(hash) hash.each do |key, value| reflection.attributes[key.to_s] = Array(value).collect do |column| table, attribute = column.to_s =~ /\./ ? column.to_s.split(".") : [model.table_name, column] "#{table}.#{attribute}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
search_cop-1.2.2 | lib/search_cop/search_scope.rb |