Class: BrowseEverything::Driver::Base
- Inherits:
-
Object
- Object
- BrowseEverything::Driver::Base
- Defined in:
- lib/browse_everything/driver/base.rb
Overview
Abstract class for provider classes
Direct Known Subclasses
Class Attribute Summary collapse
-
.sorter ⇒ Object
Returns the value of attribute sorter.
Instance Attribute Summary collapse
-
#code ⇒ Object
Provide accessor and mutator methods for @token and @code.
-
#token ⇒ Object
Provide accessor and mutator methods for @token and @code.
Class Method Summary collapse
-
.default_sorter ⇒ Proc
Provide a default sorting lambda.
-
.inherited(subclass) ⇒ Object
Set the sorter lambda (or proc) for all subclasses (see Class.inherited).
Instance Method Summary collapse
-
#auth_link(*_args) ⇒ Object
Abstract method.
-
#authorized? ⇒ Boolean
Abstract method.
-
#config ⇒ ActiveSupport::HashWithIndifferentAccess
Ensure that the configuration Hash has indifferent access.
-
#connect(*_args) ⇒ Object
Abstract method.
-
#contents(*_args) ⇒ Object
Abstract method.
-
#icon ⇒ String
Generate the icon markup for the driver.
-
#initialize(config_values) ⇒ Base
constructor
Constructor.
-
#key ⇒ String
Generate the key for the driver.
-
#link_for(path) ⇒ Array<String, Hash>
Generate the link for a resource at a given path.
-
#name ⇒ String
Generate the name for the driver.
-
#validate_config ⇒ Object
Abstract method.
Constructor Details
#initialize(config_values) ⇒ Base
Constructor
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
.sorter ⇒ Object
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
#code ⇒ Object
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 |
#token ⇒ Object
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_sorter ⇒ Proc
Provide a default sorting lambda
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)
33 34 35 36 |
# File 'lib/browse_everything/driver/base.rb', line 33 def inherited(subclass) subclass.sorter = sorter super end |
Instance Method Details
#auth_link(*_args) ⇒ Object
Abstract method
93 94 95 |
# File 'lib/browse_everything/driver/base.rb', line 93 def auth_link(*_args) [] end |
#authorized? ⇒ Boolean
Abstract method
88 89 90 |
# File 'lib/browse_everything/driver/base.rb', line 88 def false end |
#config ⇒ ActiveSupport::HashWithIndifferentAccess
Ensure that the configuration Hash has indifferent access
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 |
#icon ⇒ String
Generate the icon markup for the driver
65 66 67 |
# File 'lib/browse_everything/driver/base.rb', line 65 def icon 'unchecked' end |
#key ⇒ String
Generate the key for the driver
59 60 61 |
# File 'lib/browse_everything/driver/base.rb', line 59 def key self.class.name.split(/::/).last.underscore end |
#link_for(path) ⇒ Array<String, Hash>
Generate the link for a resource at a given path
83 84 85 |
# File 'lib/browse_everything/driver/base.rb', line 83 def link_for(path) [path, { file_name: File.basename(path) }] end |
#name ⇒ String
Generate the name for the driver
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_config ⇒ Object
Abstract method
55 |
# File 'lib/browse_everything/driver/base.rb', line 55 def validate_config; end |