Sha256: 463a6ab83a7273666c06661c1e9ea1df68a74688ad1f3d55ae4b2a0c3ba3f902

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

module CanTango
  module PermissionEngine
    class Permission
      # rules is a Hashie, a Hash where keys can also be accessed as method calls
      attr_accessor :name, :static_rules, :compiled_rules

      def initialize name
        @name = name
        @static_rules = Hashie::Mash.new
        @compiled_rules = Hashie::Mash.new
      end

      def key
        name.to_s
      end

      def to_hash
        {key => static_rules.to_hash}
      end

      def to_compiled_hash
        {key => compiled_rules}
      end

      def compiled_rules
        compile_rules!
        @compiled_rules
      end

      def compile_rules!
        compiler.compile! self 
        @compiled_rules = compiler.to_hashie
      end

      def compiler
        @compiler ||= CanTango::PermissionEngine::Compiler.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 lib/cantango/permission_engine/permission.rb