Skip to content

Instantly share code, notes, and snippets.

@maxehmookau
Created January 15, 2016 11:52
Show Gist options
  • Save maxehmookau/cb3cf6923c1ba7aab996 to your computer and use it in GitHub Desktop.
Save maxehmookau/cb3cf6923c1ba7aab996 to your computer and use it in GitHub Desktop.
class HierarchyProcessor
attr_reader :input, :user
def initialize(input, user)
raise ArgumentError, "user expected User, was #{ user.class }" unless user.is_a?(User)
@input = JSON.parse(input)
@user = user
end
[:service_groups, :locations, :roles, :employment_types].each do |type|
define_method(type) do
class_name = type.to_s.classify.constantize
class_name.where(id: @input[type.to_s].map{ |s| s['id'] })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment