Class: Concept::Relation::Base

Inherits:
ApplicationRecord 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)


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

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
50
# 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))
                  .references(:concepts)
end

.by_target_origin(target_origin) ⇒ Object



52
53
54
55
# 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



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

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

.partial_name(obj) ⇒ Object



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

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

.publishedObject



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

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

.published_with_newer_versionsObject



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

def self.published_with_newer_versions
  includes(:target).merge(Concept::Base.published_with_newer_versions)
                   .references(:concepts)
end

.rankable?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'app/models/concept/relation/base.rb', line 126

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

.reverse_relation_classObject

********* Methods



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

def self.reverse_relation_class
  self
end

.singular?Boolean

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

Returns:

  • (Boolean)


106
107
108
# File 'app/models/concept/relation/base.rb', line 106

def self.singular?
  false
end

.target_editor_selectableObject



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

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

.target_in_edit_modeObject



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

def self.target_in_edit_mode
  joins(:target).merge(Concept::Base.unpublished).references(:concepts)
end

.unpublishedObject



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

def self.unpublished
  includes(:target).merge(Concept::Base.unpublished).references(:concepts)
end

.view_section(obj) ⇒ Object



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

def self.view_section(obj)
  'main'
end

.view_section_sort_key(obj) ⇒ Object



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

def self.view_section_sort_key(obj)
  200
end

Instance Method Details

#rankObject



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

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

#rank=(val) ⇒ Object



118
119
120
121
122
123
124
# File 'app/models/concept/relation/base.rb', line 118

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