Sha256: 1ea191a7bf3d5d3409e59198eaf9a34a604747b3d9d47f967135d9c14561e8de
Contents?: true
Size: 844 Bytes
Versions: 2
Compression:
Stored size: 844 Bytes
Contents
module Zuul module ValidRoles def self.included(base) base.extend ClassMethods end module ClassMethods def valid_roles(*roles) attr_protected :role write_inheritable_attribute(:roles, roles) include InstanceMethods end end module InstanceMethods def self.included(base) base.read_inheritable_attribute(:roles).each do |role| class_eval <<-CODE def #{role}? self.role.to_sym == :#{role} end CODE end end def role role_name = read_attribute(:role) role_name && role_name.to_sym end def role=(role) return unless self.class.read_inheritable_attribute(:roles).include?(role.to_sym) write_attribute(:role, role.to_s) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
zuul-0.1.1 | lib/zuul/valid_roles.rb |
zuul-0.1.0 | lib/zuul/valid_roles.rb |