Class: Scimitar::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- Scimitar::Engine
- Defined in:
- lib/scimitar/engine.rb
Class Method Summary collapse
-
.add_custom_resource(resource) ⇒ Object
Can be used to add a new resource type which is not provided by the gem.
-
.custom_resources ⇒ Object
Returns the list of custom resources, if any.
-
.default_resources ⇒ Object
Returns the default resources added in this gem - by default, these are:.
-
.reset_custom_resources ⇒ Object
Resets the resource list to default.
-
.reset_default_resources ⇒ Object
Resets the default resource list.
-
.resources ⇒ Object
Return an Array of all supported default and custom resource classes.
-
.schemas ⇒ Object
Returns a flat array of instances of all resource schema included in the resource classes returned by ::resources.
-
.set_default_resources(resource_array) ⇒ Object
Override the resources returned by ::default_resources.
Class Method Details
.add_custom_resource(resource) ⇒ Object
Can be used to add a new resource type which is not provided by the gem. For example:
module Scim
module Resources
class ShinyResource < Scimitar::Resources::Base
set_schema Scim::Schema::Shiny
def self.endpoint
"/Shinies"
end
end
end
end
Scimitar::Engine.add_custom_resource Scim::Resources::ShinyResource
55 56 57 |
# File 'lib/scimitar/engine.rb', line 55 def self.add_custom_resource(resource) self.custom_resources() << resource end |
.custom_resources ⇒ Object
Returns the list of custom resources, if any.
34 35 36 |
# File 'lib/scimitar/engine.rb', line 34 def self.custom_resources @custom_resources ||= [] end |
.default_resources ⇒ Object
Returns the default resources added in this gem - by default, these are:
-
Scimitar::Resources::User
-
Scimitar::Resources::Group
…but if an implementation does not e.g. support Group, it can be overridden via ::set_default_resources to help with service auto-discovery.
75 76 77 78 |
# File 'lib/scimitar/engine.rb', line 75 def self.default_resources @standard_default_resources = [ Resources::User, Resources::Group ] @default_resources ||= @standard_default_resources.dup() end |
.reset_custom_resources ⇒ Object
Resets the resource list to default. This is really only intended for use during testing, to avoid one test polluting another.
62 63 64 |
# File 'lib/scimitar/engine.rb', line 62 def self.reset_custom_resources @custom_resources = [] end |
.reset_default_resources ⇒ Object
Resets the default resource list. This is really only intended for use during testing, to avoid one test polluting another.
102 103 104 105 |
# File 'lib/scimitar/engine.rb', line 102 def self.reset_default_resources self.default_resources() @default_resources = @standard_default_resources end |
.resources ⇒ Object
Return an Array of all supported default and custom resource classes. See also :add_custom_resource and :set_default_resources.
21 22 23 |
# File 'lib/scimitar/engine.rb', line 21 def self.resources self.default_resources() + self.custom_resources() end |
.schemas ⇒ Object
Returns a flat array of instances of all resource schema included in the resource classes returned by ::resources.
28 29 30 |
# File 'lib/scimitar/engine.rb', line 28 def self.schemas self.resources().map(&:schemas).flatten.uniq.map(&:new) end |
.set_default_resources(resource_array) ⇒ Object
Override the resources returned by ::default_resources.
resource_array
-
An Array containing one or both of Scimitar::Resources::User and/or Scimitar::Resources::Group, and nothing else.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/scimitar/engine.rb', line 86 def self.set_default_resources(resource_array) self.default_resources() unrecognised_resources = resource_array - @standard_default_resources if unrecognised_resources.any? raise "Scimitar::Engine.set_default_resources: Only #{@standard_default_resources.map(&:name).join(', ')} are supported" elsif resource_array.empty? raise 'Scimitar::Engine.set_default_resources: At least one resource must be given' end @default_resources = resource_array end |