Sha256: b7e668df0d41c60f74cdde0cb1bc03edae484fe440b7f1504c2cd729c68f113c
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
module ActiveHashRelation class FilterApplier include ColumnFilters include AssociationFilters include ScopeFilters def initialize(resource, params, include_associations: false, model: nil) @resource = resource @params = HashWithIndifferentAccess.new(params) @include_associations = include_associations @model = model end def apply_filters unless @model @model = model_class_name(@resource) end table_name = @model.table_name @model.columns.each do |c| next if @params[c.name.to_s].nil? @resource = filter_primary(@resource, c.name, @params[c.name]) and next if c.primary case c.type when :integer @resource = filter_integer(@resource, c.name, table_name, @params[c.name]) when :float @resource = filter_float(@resource, c.name, table_name, @params[c.name]) when :decimal @resource = filter_decimal(@resource, c.name, table_name, @params[c.name]) when :string @resource = filter_string(@resource, c.name, table_name, @params[c.name]) when :date @resource = filter_date(@resource, c.name, table_name, @params[c.name]) when :datetime, :timestamp @resource = filter_datetime(@resource, c.name, table_name, @params[c.name]) when :boolean @resource = filter_boolean(@resource, c.name, @params[c.name]) end end @resource = filter_scopes(@resource, @params[:scopes]) if @params.include?(:scopes) @resource = filter_associations(@resource, @params) return @resource end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_hash_relation-0.0.1 | lib/active_hash_relation/filter_applier.rb |