lib/reuser/role.rb in reuser-3.1.0 vs lib/reuser/role.rb in reuser-3.1.1

- old
+ new

@@ -1,15 +1,8 @@ module ReUser class Role - attr_reader :name - - def permissions - @permissions.keys - end - - def initialize name, permissions=[] - @name = name + def initialize *permissions @permissions = {} self.can *permissions end def can *permissions @@ -17,18 +10,23 @@ @permissions[permission] = lambda {|*args| true } end end def can? permission - @permissions[permission].is_a? Proc + @permissions.has_key?(permission) && @permissions[permission].is_a?(Proc) end def could permission, &block raise "#could requires a block" unless block_given? @permissions[permission] = block end - def could? permission, block_args - @permissions[permission].call(block_args) + def could? permission, *block_args + if @permissions.has_key?(permission) + @permissions[permission].call(*block_args) + else + false + end end + alias_method :able_to?, :could? end end