Sha256: cbd7298ee3997f667b836c811822659dfa9413229b089b4c0b338cd7dccb28e4
Contents?: true
Size: 1.08 KB
Versions: 12
Compression:
Stored size: 1.08 KB
Contents
require 'coercible' require 'active_support/hash_with_indifferent_access' require 'active_support/core_ext/hash' module Admino module Query class SearchField attr_reader :params attr_reader :config def initialize(config, params) @config = config @params = ActiveSupport::HashWithIndifferentAccess.new(params) end def augment_scope(scope) if present? scope.send(scope_name, value) else scope end end def value value = params.fetch(:query, {}).fetch(param_name, nil) if config.coerce_to value = begin coercer = Coercible::Coercer.new coercer[value.class].send(config.coerce_to, value) rescue Coercible::UnsupportedCoercion nil end end value || config.default_value end def present? value.present? end def param_name config.name end def scope_name config.name end end end end
Version data entries
12 entries across 12 versions & 1 rubygems