Class: Relation::Custom
- Defined in:
- app/models/relation/custom.rb
Overview
Constant Summary collapse
- DEFAULT =
Default relations shipped with Social Stream
{ 'site' => {} }
- CONFIG_FILE =
Default relations are re-defined in this configuration file
File.join(::Rails.root, 'config', 'relations.yml')
Constants inherited from Relation
Class Method Summary collapse
-
.config ⇒ Object
Relations configuration.
- .defaults_for(actor) ⇒ Object
-
.strongest ⇒ Object
A relation in the top of a strength hierarchy.
Instance Method Summary collapse
-
#<=>(rel) ⇒ Object
Compare two relations.
-
#stronger ⇒ Object
Other relations above in the same hierarchy that this relation.
-
#stronger_or_equal ⇒ Object
Relations above or at the same level of this relation.
-
#weaker ⇒ Object
Other relations below in the same hierarchy that this relation.
-
#weaker_or_equal ⇒ Object
Relations below or at the same level of this relation.
Methods inherited from Relation
allow, allow?, create_activity?, #follow?, ids_shared_with, #mode, negative_names, normalize, normalize_id, #positive?, positive_names
Class Method Details
.config ⇒ Object
Relations configuration
28 29 30 |
# File 'app/models/relation/custom.rb', line 28 def config @config ||= build_config end |
.defaults_for(actor) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/relation/custom.rb', line 32 def defaults_for(actor) cfg_rels = config[actor.subject_type.underscore] if cfg_rels.nil? raise "Undefined relations for subject type #{ actor.subject_type }. Please, add an entry to #{ CONFIG_FILE }" end rels = {} cfg_rels.each_pair do |name, cfg_rel| rels[name] = create! :actor => actor, :name => cfg_rel['name'], :receiver_type => cfg_rel['receiver_type'] if (ps = cfg_rel['permissions']).present? ps.each do |p| p.push(nil) if p.size == 1 rels[name]. << Permission.find_or_create_by_action_and_object(*p) end end end # Parent, relations must be set after creation # FIXME: Can fix with ruby 1.9 and ordered hashes cfg_rels.each_pair do |name, cfg_rel| rels[name].update_attribute(:parent, rels[cfg_rel['parent']]) end rels.values end |
.strongest ⇒ Object
A relation in the top of a strength hierarchy
67 68 69 |
# File 'app/models/relation/custom.rb', line 67 def strongest roots end |
Instance Method Details
#<=>(rel) ⇒ Object
Compare two relations
81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/relation/custom.rb', line 81 def <=> rel return -1 if rel.is_a?(Public) if ancestor_ids.include?(rel.id) 1 elsif rel.ancestor_ids.include?(id) -1 else 0 end end |
#stronger ⇒ Object
Other relations above in the same hierarchy that this relation
104 105 106 |
# File 'app/models/relation/custom.rb', line 104 def stronger ancestors end |
#stronger_or_equal ⇒ Object
Relations above or at the same level of this relation
109 110 111 |
# File 'app/models/relation/custom.rb', line 109 def stronger_or_equal path end |
#weaker ⇒ Object
Other relations below in the same hierarchy that this relation
94 95 96 |
# File 'app/models/relation/custom.rb', line 94 def weaker descendants end |
#weaker_or_equal ⇒ Object
Relations below or at the same level of this relation
99 100 101 |
# File 'app/models/relation/custom.rb', line 99 def weaker_or_equal subtree end |