Class: Boar::Handlers::Downloads::Base
- Defined in:
- app/models/boar/handlers/downloads/base.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#provider_options ⇒ Object
readonly
Returns the value of attribute provider_options.
Attributes inherited from Generic
Instance Method Summary collapse
-
#call(_, _, _, _) ⇒ Object
TODO: Create something Elephas.use for the remote implementations.
- #class_key ⇒ Object
- #credentials_params ⇒ Object
- #finalize_path(path, match_data) ⇒ Object
-
#initialize(service, options) ⇒ Base
constructor
A new instance of Base.
- #load_credentials ⇒ Object
- #update_credentials(credentials, params = nil) ⇒ Object
Methods included from Utils::Basic
#ensure_hash, #get_option, #interpolate
Constructor Details
#initialize(service, options) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 20 |
# File 'app/models/boar/handlers/downloads/base.rb', line 13 def initialize(service, ) super(service) @options = ensure_hash() # Get the configuration for the provider @provider_options = ensure_hash(@options[:providers]).fetch(self.class_key, {}).deep_symbolize_keys end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'app/models/boar/handlers/downloads/base.rb', line 11 def @options end |
#provider_options ⇒ Object (readonly)
Returns the value of attribute provider_options.
11 12 13 |
# File 'app/models/boar/handlers/downloads/base.rb', line 11 def @provider_options end |
Instance Method Details
#call(_, _, _, _) ⇒ Object
TODO: Create something Elephas.use for the remote implementations
23 24 25 |
# File 'app/models/boar/handlers/downloads/base.rb', line 23 def call(_, _, _, _) raise Boar::Exceptions::UnImplemented.new end |
#class_key ⇒ Object
27 28 29 |
# File 'app/models/boar/handlers/downloads/base.rb', line 27 def class_key self.class.name.demodulize.underscore end |
#credentials_params ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/boar/handlers/downloads/base.rb', line 35 def credentials_params host = @service.handler_for(:hosts).call(@service.controller.request) path = self.interpolate(@configuration.credentials_file, {root: Rails.root, request: @service.controller.request, controller: @service.controller}) all = YAML.load_file(path) name = self.class_key {single: HashWithIndifferentAccess.new(all.fetch(host).fetch(name)), path: path, all: all, host: host, provider: self, name: name } end |
#finalize_path(path, match_data) ⇒ Object
50 51 52 |
# File 'app/models/boar/handlers/downloads/base.rb', line 50 def finalize_path(path, match_data) path.gsub(/\\(\d+)/) { |m| match_data[$1.to_i] } end |
#load_credentials ⇒ Object
31 32 33 |
# File 'app/models/boar/handlers/downloads/base.rb', line 31 def load_credentials self.credentials_params[:single] end |
#update_credentials(credentials, params = nil) ⇒ Object
44 45 46 47 48 |
# File 'app/models/boar/handlers/downloads/base.rb', line 44 def update_credentials(credentials, params = nil) params ||= self.credentials_params params[:all][params[:host]][params[:name]] = params[:single].merge(credentials).to_hash open(params[:path], "w") {|f| f.write(params[:all].to_yaml) } end |