Class: LinkedData::Client::Models::Ontology

Inherits:
Base
  • Object
show all
Includes:
Collection, ReadWrite
Defined in:
lib/ontologies_api_client/models/ontology.rb

Constant Summary

Constants included from ReadWrite

ReadWrite::HTTP

Constants inherited from Base

Base::HTTP

Instance Attribute Summary

Attributes inherited from Base

#context, #instance_values, #links

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReadWrite

#changed_values, #delete, #save, #update, #update_from_params

Methods included from Collection

included

Methods inherited from Base

#[], #[]=, attributes, class_for_type, #explore, #id, #initialize, #marshal_dump, #marshal_load, #method_missing, #respond_to?, #to_hash, #to_jsonld, #type

Constructor Details

This class inherits a constructor from LinkedData::Client::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LinkedData::Client::Base

Class Method Details

.find_by(attrs, *args) ⇒ Object

Find a resource by a combination of attributes Override to search for views as well by default Views get hidden on the REST service unless the ‘include_views` parameter is set to `true`



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ontologies_api_client/models/ontology.rb', line 80

def self.find_by(attrs, *args)
  params = args.shift
  if params.is_a?(Hash)
    params[:include_views] = params[:include_views] || true
  else
    # Stick params back and create a new one
    args.push({include_views: true})
  end
  args.unshift(params)
  super(attrs, *args)
end

Instance Method Details

#access?(user) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/ontologies_api_client/models/ontology.rb', line 42

def access?(user)
  return true if !viewing_restricted?
  return false if user.nil?
  return true if user.admin?
  return self.full_acl.any? {|u| u == user.id}
end

#acl_selectObject

For use with select lists, always includes the admin by default



67
68
69
70
71
72
73
# File 'lib/ontologies_api_client/models/ontology.rb', line 67

def acl_select
  select_opts = []
  self.full_acl.each do |userId|
    select_opts << [User.get(userId).username, userId]
  end
  select_opts
end

#admin?(user) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/ontologies_api_client/models/ontology.rb', line 49

def admin?(user)
  return false if user.nil?
  return true if user.admin?
  return administeredBy.any? {|u| u == user.id}
end

#find(id, params = {}) ⇒ Object

Find a resource by id Override to search for views as well by default Views get hidden on the REST service unless the ‘include_views` parameter is set to `true`



97
98
99
100
# File 'lib/ontologies_api_client/models/ontology.rb', line 97

def find(id, params = {})
  params[:include_views] = params[:include_views] || true
  super(id, params)
end

#flat?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ontologies_api_client/models/ontology.rb', line 14

def flat?
  self.flat
end

#full_aclObject

ACL with administrators



62
63
64
# File 'lib/ontologies_api_client/models/ontology.rb', line 62

def full_acl
  ((self.acl || []) + self.administeredBy).uniq
end

#invalidate_cacheObject



55
56
57
58
59
# File 'lib/ontologies_api_client/models/ontology.rb', line 55

def invalidate_cache
  self.class.all(invalidate_cache: true)
  self.class.all(invalidate_cache: true, include_views: true)
  HTTP.get(self.id, invalidate_cache: true) if self.id
end

#licensed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ontologies_api_client/models/ontology.rb', line 22

def licensed?
  viewingRestriction && viewingRestriction.downcase.eql?("licensed")
end

#private?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ontologies_api_client/models/ontology.rb', line 18

def private?
  viewingRestriction && viewingRestriction.downcase.eql?("private")
end

#purlObject



34
35
36
37
38
39
40
# File 'lib/ontologies_api_client/models/ontology.rb', line 34

def purl
  if self.acronym
    "#{LinkedData::Client.settings.purl_prefix}/#{acronym}"
  else
    ""
  end
end

#view?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ontologies_api_client/models/ontology.rb', line 30

def view?
  viewOf && viewOf.length > 1
end

#viewing_restricted?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ontologies_api_client/models/ontology.rb', line 26

def viewing_restricted?
  private? || licensed?
end