Class: BrowseEverything::Driver::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/browse_everything/driver/base.rb

Overview

Abstract class for provider classes

Direct Known Subclasses

Box, Dropbox, FileSystem, GoogleDrive, S3

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_values) ⇒ Base

Constructor

Parameters:

  • config_values (Hash)

    configuration for the driver



41
42
43
44
45
# File 'lib/browse_everything/driver/base.rb', line 41

def initialize(config_values)
  @config = config_values
  @sorter = self.class.sorter || self.class.default_sorter
  validate_config
end

Class Attribute Details

.sorterObject

Returns the value of attribute sorter.



14
15
16
# File 'lib/browse_everything/driver/base.rb', line 14

def sorter
  @sorter
end

Instance Attribute Details

#codeObject

Provide accessor and mutator methods for @token and @code



10
11
12
# File 'lib/browse_everything/driver/base.rb', line 10

def code
  @code
end

#tokenObject

Provide accessor and mutator methods for @token and @code



10
11
12
# File 'lib/browse_everything/driver/base.rb', line 10

def token
  @token
end

Class Method Details

.default_sorterProc

Provide a default sorting lambda

Returns:

  • (Proc)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/browse_everything/driver/base.rb', line 18

def default_sorter
  lambda { |files|
    files.sort do |a, b|
      if b.container?
        a.container? ? a.name.downcase <=> b.name.downcase : 1
      else
        a.container? ? -1 : a.name.downcase <=> b.name.downcase
      end
    end
  }
end

.inherited(subclass) ⇒ Object

Set the sorter lambda (or proc) for all subclasses (see Class.inherited)

Parameters:

  • subclass (Class)

    the class inheriting from BrowseEverything::Driver::Base



33
34
35
36
# File 'lib/browse_everything/driver/base.rb', line 33

def inherited(subclass)
  subclass.sorter = sorter
  super
end

Instance Method Details

Abstract method



93
94
95
# File 'lib/browse_everything/driver/base.rb', line 93

def auth_link(*_args)
  []
end

#authorized?Boolean

Abstract method

Returns:

  • (Boolean)


88
89
90
# File 'lib/browse_everything/driver/base.rb', line 88

def authorized?
  false
end

#configActiveSupport::HashWithIndifferentAccess

Ensure that the configuration Hash has indifferent access

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)


49
50
51
52
# File 'lib/browse_everything/driver/base.rb', line 49

def config
  @config = ActiveSupport::HashWithIndifferentAccess.new(@config) if @config.is_a? Hash
  @config
end

#connect(*_args) ⇒ Object

Abstract method



98
99
100
# File 'lib/browse_everything/driver/base.rb', line 98

def connect(*_args)
  nil
end

#contents(*_args) ⇒ Object

Abstract method



76
77
78
# File 'lib/browse_everything/driver/base.rb', line 76

def contents(*_args)
  []
end

#iconString

Generate the icon markup for the driver

Returns:

  • (String)


65
66
67
# File 'lib/browse_everything/driver/base.rb', line 65

def icon
  'unchecked'
end

#keyString

Generate the key for the driver

Returns:

  • (String)


59
60
61
# File 'lib/browse_everything/driver/base.rb', line 59

def key
  self.class.name.split(/::/).last.underscore
end

Generate the link for a resource at a given path

Parameters:

  • path (String)

    the path to the resource

Returns:

  • (Array<String, Hash>)


83
84
85
# File 'lib/browse_everything/driver/base.rb', line 83

def link_for(path)
  [path, { file_name: File.basename(path) }]
end

#nameString

Generate the name for the driver

Returns:

  • (String)


71
72
73
# File 'lib/browse_everything/driver/base.rb', line 71

def name
  @name ||= @config[:name] || self.class.name.split(/::/).last.titleize
end

#validate_configObject

Abstract method



55
# File 'lib/browse_everything/driver/base.rb', line 55

def validate_config; end