Sha256: 4c1e906be535963a2225dd3dd133cd3ec4fba15f315c79a2cebf453064a91f02
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
module SeekParty class SeekPartyAttribute attr_accessor :inspected_class, :white_list, :black_list def initialize(inspected_class, white_list, black_list) @inspected_class = inspected_class @white_list = white_list @black_list = black_list end # Compare attributes to params passed # If only search is present, query against all params # If both search and other attributes match against the # params hash, query against them too. def discover_attributes check_attributes @inspected_class.new end private def check_attributes(another_model) return nil if another_model.nil? sp_attribute = SPAttribute.new(table_name: pluralize_and_snake_case_class_name) another_model.attributes.keys.each do |attribute| next unless another_model.has_attribute? attribute next if black_listed? attribute sp_attribute.add_attribute(attribute) if white_listed? attribute end sp_attribute end def white_listed?(attribute_name) return true if @white_list.nil? @white_list.include? attribute_name end def black_listed?(attribute_name) @black_list.include? attribute_name end def pluralize_and_snake_case_class_name @inspected_class.name.pluralize.underscore end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
seek_party-0.0.3 | lib/seek_party/seek_party_attribute.rb |