class SeekParty::SeekPartyAttribute

Attributes

black_list[RW]
inspected_class[RW]
white_list[RW]

Public Class Methods

new(inspected_class, white_list, black_list) click to toggle source
# File lib/seek_party/seek_party_attribute.rb, line 7
def initialize(inspected_class, white_list, black_list)
  @inspected_class = inspected_class
  @white_list = white_list
  @black_list = black_list
end

Public Instance Methods

discover_attributes() click to toggle source

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.

# File lib/seek_party/seek_party_attribute.rb, line 17
def discover_attributes
  check_attributes @inspected_class.new
end

Private Instance Methods

black_listed?(attribute_name) click to toggle source
# File lib/seek_party/seek_party_attribute.rb, line 44
def black_listed?(attribute_name)
  @black_list.include? attribute_name
end
check_attributes(another_model) click to toggle source
# File lib/seek_party/seek_party_attribute.rb, line 23
def check_attributes(another_model)
  return nil if another_model.nil?

  sp_attribute = SPAttribute.new(table_name: get_table_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
get_table_name() click to toggle source
# File lib/seek_party/seek_party_attribute.rb, line 48
def get_table_name
  @inspected_class.table_name.underscore
end
white_listed?(attribute_name) click to toggle source
# File lib/seek_party/seek_party_attribute.rb, line 38
def white_listed?(attribute_name)
  return true if @white_list.nil?

  @white_list.include? attribute_name
end