Class: AdminsController::UserSearch

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::Model, ActiveModel::Validations
Defined in:
app/controllers/admins_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ UserSearch

Returns a new instance of UserSearch.

Yields:

  • (_self)

Yield Parameters:


121
122
123
124
# File 'app/controllers/admins_controller.rb', line 121

def initialize(attributes={})
  assign_attributes(attributes)
  yield(self) if block_given?
end

Instance Attribute Details

#emailObject

Returns the value of attribute email


117
118
119
# File 'app/controllers/admins_controller.rb', line 117

def email
  @email
end

#guidObject

Returns the value of attribute guid


117
118
119
# File 'app/controllers/admins_controller.rb', line 117

def guid
  @guid
end

#under13Object

Returns the value of attribute under13


117
118
119
# File 'app/controllers/admins_controller.rb', line 117

def under13
  @under13
end

#usernameObject

Returns the value of attribute username


117
118
119
# File 'app/controllers/admins_controller.rb', line 117

def username
  @username
end

Instance Method Details

#any_searchfield_present?Boolean

Returns:

  • (Boolean)

132
133
134
135
136
# File 'app/controllers/admins_controller.rb', line 132

def any_searchfield_present?
  if %w(username email guid under13).all? { |attr| public_send(attr).blank? }
    errors.add :base, "no fields for search set"
  end
end

#assign_attributes(values) ⇒ Object


126
127
128
129
130
# File 'app/controllers/admins_controller.rb', line 126

def assign_attributes(values)
  values.each do |k, v|
    public_send("#{k}=", v)
  end
end

#performObject


138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/controllers/admins_controller.rb', line 138

def perform
  return User.none unless valid?

  users = User.arel_table
  people = Person.arel_table
  profiles = Profile.arel_table
  res = User.joins(person: :profile)
  res = res.where(users[:username].matches("%#{username}%")) unless username.blank?
  res = res.where(users[:email].matches("%#{email}%")) unless email.blank?
  res = res.where(people[:guid].matches("%#{guid}%")) unless guid.blank?
  res = res.where(profiles[:birthday].gt(Date.today-13.years)) if under13 == '1'
  res
end