Class: Specify::UserType

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

Overview

A class that represents a lvel for upload of views.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ UserType

-> UserType Creates a new instance.



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

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'



10
11
12
# File 'lib/specify/user_type.rb', line 10

def name
  @name
end

#view_set_dir(collection) ⇒ Object

-> Model::AppResourceDir

Returns the instance's Model

AppResourceDir for collection.

collection: a Model::Collection.



45
46
47
48
49
50
# File 'lib/specify/user_type.rb', line 45

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

-> Model::AppResourceDir Creates a new instance of Model::AppResourceDir with values. values: a Hash with attributes and values to create a

Model::AppResourceDir


24
25
26
# File 'lib/specify/user_type.rb', line 24

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

#saveObject

-> UserType Dummy method to allow duck typing use alongside Model::Collection, Model::Discipline, and Model::User.



31
32
33
# File 'lib/specify/user_type.rb', line 31

def save
  self
end

#valid?Boolean

-> true or false Returns true if the user type name is any of 'fullaccess', 'guest', 'limitedaccess', or 'manager'; false otherwise.

Returns:

  • (Boolean)


38
39
40
# File 'lib/specify/user_type.rb', line 38

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

#view_set(collection) ⇒ Object

-> Model::ViewSetObject Returns the instance's Model::ViewSetObject for collection. collection: a Model::Collection.



55
56
57
# File 'lib/specify/user_type.rb', line 55

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