Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yuki24
Created April 8, 2014 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuki24/10082466 to your computer and use it in GitHub Desktop.
Save yuki24/10082466 to your computer and use it in GitHub Desktop.
NullUser written in meta-programming
class NullUser
User.reflections.each do |key, value|
name = key.to_s
if value.collection?
eval <<-RUBY
def #{name}
#{value.klass}.none
end
def #{name.singularize}_ids
[]
end
RUBY
else
eval <<-RUBY
def #{name}
nil
end
def #{name}_id
nil
end
def build_#{name}(*args, &block)
nil
end
def create_#{name}(*args, &block)
nil
end
def create_#{name}!(*args, &block)
nil
end
RUBY
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment