Skip to content

Instantly share code, notes, and snippets.

@nozpheratu
Created August 23, 2014 18:00
Show Gist options
  • Save nozpheratu/3bf79d8c3e19c5e8181c to your computer and use it in GitHub Desktop.
Save nozpheratu/3bf79d8c3e19c5e8181c to your computer and use it in GitHub Desktop.
Exhibit class
require "delegate"
class Exhibit < SimpleDelegator
include Pundit
def self.exhibits
[
RegistrationExhibit,
EliminationExhibit,
RoundRobinExhibit
]
end
def self.exhibit(object, context, options = [])
exhibits.inject(object) do |object, exhibit|
exhibit.exhibit_if_applicable(object, context)
end
end
def self.exhibit_if_applicable(object, context)
if applicable_to?(object)
new(object, context)
else
object
end
end
def initialize(model, context)
@context = context
super(model)
end
def to_model
__getobj__
end
def class
__getobj__.class
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment