Class: Specify::UserType

Inherits:
Object
  • Object
show all
Defined in:
lib/specify/user_type.rb

Overview

A UserType represents a lvel to which .views.xml files can be uploaded. This is the only level that is not represented by a proper Model class, the others being Specify::Model::Collection, Specify::Model::Discipline, and Specify::Model::User. Like the model classes, a UserType implements #view_set_dir and #view_set to give access to the correct Specify::Model::AppResourceDir and Specify::Model::ViewSetObject instances.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ UserType

Returns a new UserType. name must be a valid #name.



20
21
22
23
24
# File 'lib/specify/user_type.rb', line 20

def initialize(name)
  @name = name.downcase
  @view_set_dir = nil
  valid?
end

Instance Attribute Details

#nameObject (readonly)

A String, must be either manager, fullaccess, limitedaccess, or guest



16
17
18
# File 'lib/specify/user_type.rb', line 16

def name
  @name
end

#view_set_dir(collection) ⇒ Object

Returns the Specify::Model::AppResourceDir for this user type (#name) in collection (a Specify::Model::Collection).



48
49
50
51
52
53
# File 'lib/specify/user_type.rb', line 48

def view_set_dir(collection)
  Model::AppResourceDir.first(collection: collection,
                              discipline: collection.discipline,
                              UserType: @name.to_s,
                              IsPersonal: false)
end

Instance Method Details

#add_app_resource_dir(values) ⇒ Object

Returns a new instance of Specify::Model::AppResourceDir with values.



27
28
29
# File 'lib/specify/user_type.rb', line 27

def add_app_resource_dir(values)
  Model::AppResourceDir.create values
end

#saveObject

Returns self.

This is a dummy method to allow use as a Specify::ViewLoader#target alongside Specify::Model::Collection, Specify::Model::Discipline, and Specify::Model::User.



36
37
38
# File 'lib/specify/user_type.rb', line 36

def save
  self
end

#valid?Boolean

Returns true if #name is any of fullaccess, guest, limitedaccess, or manager; false otherwise.

Returns:

  • (Boolean)


42
43
44
# File 'lib/specify/user_type.rb', line 42

def valid?
  %w[fullaccess guest limitedaccess manager].include? @name
end

#view_set(collection) ⇒ Object

Returns the Specify::Model::ViewSetObject for this user type collection (a Specify::Model::Collection).



57
58
59
# File 'lib/specify/user_type.rb', line 57

def view_set(collection)
  view_set_dir(collection)&.view_set_object
end