Sha256: 5e0fb60ccc9fdf4797894bf4b96483658300a2e8fb44ffef8b832c9a777392ef

Contents?: true

Size: 868 Bytes

Versions: 5

Compression:

Stored size: 868 Bytes

Contents

module RestfulAclModel

  def self.included(base)
    base.extend(ClassMethods)
    base.send :include, ClassMethods
  end

  module ClassMethods
    attr_accessor :mom, :singleton

    def logical_parent(model, *options)
      @mom = model
      @singleton = options.include?(:singleton)

      include RestfulAclModel::InstanceMethods
    end

    def has_parent?
      @mom.present?
    end

    def is_singleton?
      @singleton.present?
    end

  end


  module InstanceMethods

    def get_mom
      parent_klass.find(parent_id) if has_parent?
    end

    private

      def klass
        self.class
      end

      def mom
        klass.mom
      end

      def has_parent?
        !mom.nil?
      end

      def parent_klass
        mom.to_s.classify.constantize
      end

      def parent_id
        self.instance_eval("#{mom}_id")
      end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
restful_acl-2.1.3 lib/restful_acl/model.rb
restful_acl-2.1.2 lib/model.rb
restful_acl-2.1.1 lib/model.rb
restful_acl-2.1.0 lib/model.rb
restful_acl-2.1 lib/model.rb