Created
October 26, 2011 19:01
-
-
Save rondy/1317425 to your computer and use it in GitHub Desktop.
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 "active_support/inflector" | |
module Modularizable | |
def modularize(target, params={}) | |
ancestors = params[:in] || [] | |
ancestors << target | |
ancestors.collect { |item| item.to_s.camelize }.join("::").constantize | |
end | |
end | |
module UserPermissions | |
extend Modularizable | |
def self.factory(role) | |
modularize role, :in => [:user_permissions, :roles] | |
end | |
module Roles | |
module Admin;end | |
module Guest;end | |
end | |
end | |
puts UserPermissions.factory :admin # => UserPermissions::Roles::Admin | |
puts UserPermissions.factory :guest # => UserPermissions::Roles::Guest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment