Sha256: 2a264e7c4d33438f0445a4ddee09269a300cd4cafd8dbe0dbaecfd5f607450a8

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

module TinyCore
  module Role
    module ClassMethods
      def allow(*things)
        things.each do |thing|
          define_method "can_#{thing}?" do
            true
          end
        end
      end
    
      def allow_if_owner(*things)
        things.each do |thing|
          define_method "can_#{thing}?" do |model|
            model.user == self
          end
        end
      end
    end
  
    def method_missing(method, *args)
      if method.to_s =~ /^can_.*\?$/
        false
      else
        super
      end
    end
  
    def self.included(base)
      base.extend ClassMethods
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tiny_core_users-0.0.1 lib/tiny_core/role.rb