Class: Boar::Handlers::Downloads::Base

Inherits:
Generic
  • Object
show all
Defined in:
app/models/boar/handlers/downloads/base.rb

Direct Known Subclasses

BoxNet, Dropbox, GoogleDrive, Local, Remote, S3, SkyDrive

Instance Attribute Summary collapse

Attributes inherited from Generic

#configuration, #service

Instance Method Summary collapse

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, options)
  super(service)

  @options = ensure_hash(options)

  # Get the configuration for the provider
  @provider_options = ensure_hash(@options[:providers]).fetch(self.class_key, {}).deep_symbolize_keys
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'app/models/boar/handlers/downloads/base.rb', line 11

def options
  @options
end

#provider_optionsObject (readonly)

Returns the value of attribute provider_options.



11
12
13
# File 'app/models/boar/handlers/downloads/base.rb', line 11

def provider_options
  @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_keyObject



27
28
29
# File 'app/models/boar/handlers/downloads/base.rb', line 27

def class_key
  self.class.name.demodulize.underscore
end

#credentials_paramsObject



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_credentialsObject



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