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)


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

def self.bidirectional?
  !!self.reverse_relation_class
end

.by_owner(owner_id) ⇒ Object

********* Scopes



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

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

.by_owner_origin(owner_origin) ⇒ Object



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

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

.by_target_origin(target_origin) ⇒ Object



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

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

.edit_partial_name(obj) ⇒ Object



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

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

.partial_name(obj) ⇒ Object



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

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

.publishedObject



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

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

.rankable?Boolean

Returns:

  • (Boolean)


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

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

.reverse_relation_classObject

********* Methods



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

def self.reverse_relation_class
  self
end

.singular?Boolean

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

Returns:

  • (Boolean)


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

def self.singular?
  false
end

.target_editor_selectableObject



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

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

.target_in_edit_modeObject



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

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

.view_section(obj) ⇒ Object



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

def self.view_section(obj)
  'relations'
end

.view_section_sort_key(obj) ⇒ Object



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

def self.view_section_sort_key(obj)
  100
end

Instance Method Details

#rankObject



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

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

#rank=(val) ⇒ Object



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

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