Sha256: 8e7ff02cec42421e3d739ee214c74f6b9c70dec2e1cedbab11a1b3c13bef93d2

Contents?: true

Size: 956 Bytes

Versions: 18

Compression:

Stored size: 956 Bytes

Contents

# encoding: UTF-8

module Spontaneous::Permissions
  class AccessGroup < Sequel::Model(:spontaneous_groups)
    many_to_many :members, :class => :'Spontaneous::Permissions::User', :join_table => :spontaneous_groups_users, :left_key => :group_id, :right_key => :user_id

    def level_for(content)
      if selector.matches(content)
        level
      else
        UserLevel.none
      end
    end

    def selector
      @selector ||= Spontaneous::ContentQuery.new(access_selector)
    end

    def level_for(content)
      if selector.matches?(content)
        level
      else
        UserLevel.none
      end
    end

    def level
      if disabled
        UserLevel.none
      else
        UserLevel[level_name]
      end
    end

    def level=(level)
      self.level_name = level.to_s
    end

    def invisible?
      !user_id.blank?
    end

    def validate
      super
      errors.add(:name, 'is required') if name.blank?
    end
  end
end


Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta9 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta8 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta7 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta6 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta5 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta4 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta3 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta2 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.beta1 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha7 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha2 lib/spontaneous/permissions/access_group.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/permissions/access_group.rb
spontaneous-0.1.0.alpha1 lib/spontaneous/permissions/access_group.rb