Created
August 23, 2014 18:00
-
-
Save nozpheratu/3bf79d8c3e19c5e8181c to your computer and use it in GitHub Desktop.
Exhibit class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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