Class: RubySMB::Server::Share::Provider::Base
- Inherits:
-
Object
- Object
- RubySMB::Server::Share::Provider::Base
- Defined in:
- lib/ruby_smb/server/share/provider.rb
Overview
The share provider defines the share and its attributes such as its type and name. It is shared across all client connections and sessions.
Defined Under Namespace
Classes: Hook
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#add_hook(request_class, callback: nil, location: :before, &block) ⇒ Object
Add a hook to be called when the specified request class is processed.
-
#initialize(name, hooks: nil) ⇒ Base
constructor
A new instance of Base.
-
#new_processor(server_client, session) ⇒ Object
Create a new, session-specific processor instance for this share.
-
#remove_hook(request_class, location: :before) ⇒ Object
Remove a hook for the specified request class.
-
#type ⇒ Object
The type of this share.
Constructor Details
#initialize(name, hooks: nil) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/ruby_smb/server/share/provider.rb', line 12 def initialize(name, hooks: nil) @name = name @hooks = hooks || [] end |
Instance Attribute Details
#hooks ⇒ Array
77 78 79 |
# File 'lib/ruby_smb/server/share/provider.rb', line 77 def hooks @hooks end |
#name ⇒ String
72 73 74 |
# File 'lib/ruby_smb/server/share/provider.rb', line 72 def name @name end |
Instance Method Details
#add_hook(request_class, callback: nil, location: :before, &block) ⇒ Object
Add a hook to be called when the specified request class is processed. Any hook that was previously installed for the request class and location will be removed. A hook installed with a location of :before will be called with the session and request as the only two arguments. The return value, if provided, will replace the request that is to be processed. A hook installed with a location of :after will be called with the session, request and response as the only three arguments. The return value, if provided, will replace the response that is to be sent to the client.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_smb/server/share/provider.rb', line 27 def add_hook(request_class, callback: nil, location: :before, &block) unless i[ before after ].include?(location) raise ArgumentError, 'the location argument must be :before or :after' end unless callback.nil? ^ block.nil? raise ArgumentError, 'either a callback or a block must be specified' end # Remove any hooks that were previously installed, this enforces that only one hook can be present at a time # for any particular request class and location combination. remove_hook(request_class, location: location) @hooks << Hook.new(request_class, location, callback || block) nil end |
#new_processor(server_client, session) ⇒ Object
Create a new, session-specific processor instance for this share.
60 61 62 |
# File 'lib/ruby_smb/server/share/provider.rb', line 60 def new_processor(server_client, session) self.class::Processor.new(self, server_client, session) end |
#remove_hook(request_class, location: :before) ⇒ Object
Remove a hook for the specified request class.
48 49 50 51 52 53 54 |
# File 'lib/ruby_smb/server/share/provider.rb', line 48 def remove_hook(request_class, location: :before) @hooks.filter! do |hook| hook.request_class == request_class && hook.location == location end nil end |
#type ⇒ Object
The type of this share.
65 66 67 |
# File 'lib/ruby_smb/server/share/provider.rb', line 65 def type self.class::TYPE end |