Class: Concept::Relation::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/concept/relation/base.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

SKOS::Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bidirectional?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/concept/relation/base.rb', line 76

def self.bidirectional?
  !!self.reverse_relation_class
end

.by_owner(owner_id) ⇒ Object

********* Scopes



44
45
46
# File 'app/models/concept/relation/base.rb', line 44

def self.by_owner(owner_id)
  where(:owner_id => owner_id)
end

.by_owner_origin(owner_origin) ⇒ Object



48
49
50
# File 'app/models/concept/relation/base.rb', line 48

def self.by_owner_origin(owner_origin)
  includes(:owner).merge(Concept::Base.by_origin(owner_origin))
end

.by_target_origin(target_origin) ⇒ Object



52
53
54
55
56
# File 'app/models/concept/relation/base.rb', line 52

def self.by_target_origin(target_origin)
  includes(:target).
  merge(Concept::Base.by_origin(target_origin)).
  references(:concepts)
end

.edit_partial_name(obj) ⇒ Object



92
93
94
# File 'app/models/concept/relation/base.rb', line 92

def self.edit_partial_name(obj)
  "partials/concept/relation/edit_base"
end

.partial_name(obj) ⇒ Object



88
89
90
# File 'app/models/concept/relation/base.rb', line 88

def self.partial_name(obj)
  "partials/concept/relation/base"
end

.publishedObject



62
63
64
# File 'app/models/concept/relation/base.rb', line 62

def self.published
  includes(:target).merge(Concept::Base.published)
end

.rankable?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'app/models/concept/relation/base.rb', line 117

def self.rankable?
  self.class.included_modules.include?(Iqvoc::Rankable)
end

.reverse_relation_classObject

********* Methods



72
73
74
# File 'app/models/concept/relation/base.rb', line 72

def self.reverse_relation_class
  self
end

.singular?Boolean

if ‘singular` is true, only a single occurrence is allowed per instance

Returns:

  • (Boolean)


97
98
99
# File 'app/models/concept/relation/base.rb', line 97

def self.singular?
  false
end

.target_editor_selectableObject



58
59
60
# File 'app/models/concept/relation/base.rb', line 58

def self.target_editor_selectable
  includes(:target).merge(Concept::Base.editor_selectable)
end

.target_in_edit_modeObject



66
67
68
# File 'app/models/concept/relation/base.rb', line 66

def self.target_in_edit_mode
  joins(:target).merge(Concept::Base.in_edit_mode)
end

.view_section(obj) ⇒ Object



80
81
82
# File 'app/models/concept/relation/base.rb', line 80

def self.view_section(obj)
  "relations"
end

.view_section_sort_key(obj) ⇒ Object



84
85
86
# File 'app/models/concept/relation/base.rb', line 84

def self.view_section_sort_key(obj)
  100
end

Instance Method Details

#rankObject



101
102
103
104
105
106
107
# File 'app/models/concept/relation/base.rb', line 101

def rank
  unless self.class.rankable?
    raise "Use `include Rankable` to make a concept relation rankable."
  else
    super
  end
end

#rank=(val) ⇒ Object



109
110
111
112
113
114
115
# File 'app/models/concept/relation/base.rb', line 109

def rank=(val)
  unless self.class.rankable?
    raise "Use `include Rankable` to make a concept relation rankable."
  else
    super
  end
end