Class: Relation::Single

Inherits:
Relation
  • Object
show all
Defined in:
app/models/relation/single.rb

Overview

Common methods for single relations, like Public and Reject

Unlike Custom, subjects have only one of these relations.

Direct Known Subclasses

Follow, Public, Reject

Constant Summary collapse

PERMISSIONS =
[]

Constants inherited from Relation

Negative, Positive

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Relation

allow, allow?, #follow?, ids_shared_with, #mode, negative_names, normalize, normalize_id, #positive?, positive_names

Class Method Details

.instanceObject



10
11
12
13
14
# File 'app/models/relation/single.rb', line 10

def instance
  @instance ||=
    first ||
      create!(:permissions => permissions)
end

.permissionsObject



16
17
18
19
20
# File 'app/models/relation/single.rb', line 16

def permissions
  self::PERMISSIONS.map{ |p|
    Permission.find_or_create_by_action_and_object p.first, p.last
  }
end

Instance Method Details

#nameObject

The name of public relation



25
26
27
# File 'app/models/relation/single.rb', line 25

def name
  I18n.t("relation_#{ self.class.name.split("::").last.underscore }.name")
end