Class: Toolchest::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/toolchest/configuration.rb

Constant Summary collapse

VALID_AUTH_STRATEGIES =
%i[none token oauth].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mount_key = :default) ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/toolchest/configuration.rb', line 13

def initialize(mount_key = :default)
  @mount_key = mount_key.to_sym
  @auth = :none
  @tool_naming = :underscored
  @filter_tools_by_scope = true
  @server_name = nil
  @server_version = Toolchest::VERSION
  @scopes = {}
  @login_path = "/login"
  @authenticate_block = nil
  @optional_scopes = false
  @required_scopes = []
  @allowed_scopes_for_block = nil
  @authorize_link_block = nil
  @additional_view_paths = []
  @access_token_expires_in = 7200
  @toolboxes = nil
  @toolbox_module = nil
end

Instance Attribute Details

#access_token_expires_inObject

Returns the value of attribute access_token_expires_in.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def access_token_expires_in
  @access_token_expires_in
end

#additional_view_pathsObject

Returns the value of attribute additional_view_paths.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def additional_view_paths
  @additional_view_paths
end

#authObject

Returns the value of attribute auth.



11
12
13
# File 'lib/toolchest/configuration.rb', line 11

def auth
  @auth
end

#filter_tools_by_scopeObject

Returns the value of attribute filter_tools_by_scope.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def filter_tools_by_scope
  @filter_tools_by_scope
end

#login_pathObject

Returns the value of attribute login_path.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def 
  @login_path
end

#mount_keyObject

Returns the value of attribute mount_key.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def mount_key
  @mount_key
end

#mount_pathObject

Returns the value of attribute mount_path.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def mount_path
  @mount_path
end

#optional_scopesObject

Returns the value of attribute optional_scopes.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def optional_scopes
  @optional_scopes
end

#required_scopesObject

Returns the value of attribute required_scopes.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def required_scopes
  @required_scopes
end

#scopesObject

Returns the value of attribute scopes.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def scopes
  @scopes
end

#server_descriptionObject

Returns the value of attribute server_description.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def server_description
  @server_description
end

#server_instructionsObject

Returns the value of attribute server_instructions.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def server_instructions
  @server_instructions
end

#server_nameObject

Returns the value of attribute server_name.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def server_name
  @server_name
end

#server_versionObject

Returns the value of attribute server_version.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def server_version
  @server_version
end

#tool_namingObject

Returns the value of attribute tool_naming.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def tool_naming
  @tool_naming
end

#toolbox_moduleObject

Returns the value of attribute toolbox_module.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def toolbox_module
  @toolbox_module
end

#toolboxesObject

Returns the value of attribute toolboxes.



5
6
7
# File 'lib/toolchest/configuration.rb', line 5

def toolboxes
  @toolboxes
end

Instance Method Details

#allowed_scopes_for(&block) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/toolchest/configuration.rb', line 69

def allowed_scopes_for(&block)
  if block
    @allowed_scopes_for_block = block
  else
    @allowed_scopes_for_block
  end
end

#authenticate(&block) ⇒ Object



49
# File 'lib/toolchest/configuration.rb', line 49

def authenticate(&block) = @authenticate_block = block

#authenticate_with(token) ⇒ Object



51
52
53
54
# File 'lib/toolchest/configuration.rb', line 51

def authenticate_with(token)
  return nil unless @authenticate_block
  @authenticate_block.call(token)
end


56
57
58
59
60
61
62
# File 'lib/toolchest/configuration.rb', line 56

def authorize_link(&block)
  if block
    @authorize_link_block = block
  else
    @authorize_link_block
  end
end

#authorize_link?(user) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/toolchest/configuration.rb', line 64

def authorize_link?(user)
  return true unless @authorize_link_block
  @authorize_link_block.call(user)
end

#current_user_for_oauth(&block) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/toolchest/configuration.rb', line 81

def current_user_for_oauth(&block)
  if block
    @current_user_for_oauth_block = block
  else
    @current_user_for_oauth_block
  end
end

#resolve_allowed_scopes(user, scopes) ⇒ Object



77
78
79
# File 'lib/toolchest/configuration.rb', line 77

def resolve_allowed_scopes(user, scopes)
  @allowed_scopes_for_block ? @allowed_scopes_for_block.call(user, scopes) : scopes
end

#resolve_current_user(request) ⇒ Object



89
90
91
92
# File 'lib/toolchest/configuration.rb', line 89

def resolve_current_user(request)
  return nil unless @current_user_for_oauth_block
  @current_user_for_oauth_block.call(request)
end

#resolved_server_nameObject



94
# File 'lib/toolchest/configuration.rb', line 94

def resolved_server_name = @server_name || (defined?(Rails) && Rails.application ? Rails.application.class.module_parent_name : "Toolchest")