-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbrowse_everything.rb
83 lines (71 loc) · 2.7 KB
/
browse_everything.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true
require 'rails'
require 'browse_everything/version'
require 'browse_everything/engine'
require 'browse_everything/retriever'
module BrowseEverything
autoload :Browser, 'browse_everything/browser'
autoload :FileEntry, 'browse_everything/file_entry'
module Driver
autoload :Base, 'browse_everything/driver/base'
autoload :FileSystem, 'browse_everything/driver/file_system'
autoload :Dropbox, 'browse_everything/driver/dropbox'
autoload :Box, 'browse_everything/driver/box'
autoload :GoogleDrive, 'browse_everything/driver/google_drive'
autoload :S3, 'browse_everything/driver/s3'
# Access the sorter set for the base driver class
# @return [Proc]
def sorter
BrowseEverything::Driver::Base.sorter
end
# Provide a custom sorter for all driver classes
# @param [Proc] the sorting lambda (or proc)
def sorter=(sorting_proc)
BrowseEverything::Driver::Base.sorter = sorting_proc
end
module_function :sorter, :sorter=
end
module Auth
module Google
autoload :Credentials, 'browse_everything/auth/google/credentials'
autoload :RequestParameters, 'browse_everything/auth/google/request_parameters'
end
end
class InitializationError < RuntimeError; end
class ConfigurationError < StandardError; end
class NotImplementedError < StandardError; end
class NotAuthorizedError < StandardError; end
class << self
attr_writer :config
def configure(value)
return if value.nil?
if value.is_a?(Hash)
@config = ActiveSupport::HashWithIndifferentAccess.new value
elsif value.is_a?(String)
begin
config_file_content = File.read(value)
config_file_template = ERB.new(config_file_content)
config_values = YAML.safe_load(config_file_template.result, permitted_classes: [Symbol])
@config = ActiveSupport::HashWithIndifferentAccess.new config_values
@config.deep_symbolize_keys
rescue Errno::ENOENT
Rails.logger.warn 'Missing browse_everything_providers.yml configuration file'
@config = ActiveSupport::HashWithIndifferentAccess.new({})
end
else
raise InitializationError, "Unrecognized configuration: #{value.inspect}"
end
if @config.include? 'drop_box' # rubocop:disable Style/GuardClause
warn '[DEPRECATION] `drop_box` is deprecated. Please use `dropbox` instead.'
@config['dropbox'] = @config.delete('drop_box')
end
end
def config
if @config.nil?
config_path = Rails.root.join 'config', 'browse_everything_providers.yml'
configure config_path.to_s
end
@config
end
end
end