class BrowseEverything::Driver::Base

Abstract class for provider classes

Attributes

sorter[RW]
code[RW]

Provide accessor and mutator methods for @token and @code

token[RW]

Provide accessor and mutator methods for @token and @code

Public Class Methods

default_sorter() click to toggle source

Provide a default sorting lambda @return [Proc]

# 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) click to toggle source

Set the sorter lambda (or proc) for all subclasses (see Class.inherited) @param subclass [Class] the class inheriting from BrowseEverything::Driver::Base

# File lib/browse_everything/driver/base.rb, line 33
def inherited(subclass)
  subclass.sorter = sorter
end
new(config_values) click to toggle source

Constructor @param config_values [Hash] configuration for the driver

# File lib/browse_everything/driver/base.rb, line 40
def initialize(config_values)
  @config = config_values
  @sorter = self.class.sorter || self.class.default_sorter
  validate_config
end

Public Instance Methods

authorized?() click to toggle source

Abstract method

# File lib/browse_everything/driver/base.rb, line 87
def authorized?
  false
end
config() click to toggle source

Ensure that the configuration Hash has indifferent access @return [ActiveSupport::HashWithIndifferentAccess]

# File lib/browse_everything/driver/base.rb, line 48
def config
  @config = ActiveSupport::HashWithIndifferentAccess.new(@config) if @config.is_a? Hash
  @config
end
connect(*_args) click to toggle source

Abstract method

# File lib/browse_everything/driver/base.rb, line 97
def connect(*_args)
  nil
end
contents(*_args) click to toggle source

Abstract method

# File lib/browse_everything/driver/base.rb, line 75
def contents(*_args)
  []
end
icon() click to toggle source

Generate the icon markup for the driver @return [String]

# File lib/browse_everything/driver/base.rb, line 64
def icon
  'unchecked'
end
key() click to toggle source

Generate the key for the driver @return [String]

# File lib/browse_everything/driver/base.rb, line 58
def key
  self.class.name.split(/::/).last.underscore
end
name() click to toggle source

Generate the name for the driver @return [String]

# File lib/browse_everything/driver/base.rb, line 70
def name
  @name ||= (@config[:name] || self.class.name.split(/::/).last.titleize)
end
validate_config() click to toggle source

Abstract method

# File lib/browse_everything/driver/base.rb, line 54
def validate_config; end

Private Instance Methods

callback() click to toggle source

Generate the URL for the API callback @return [String]

# File lib/browse_everything/driver/base.rb, line 115
def callback
  connector_response_url(callback_options)
end
callback_options() click to toggle source

Generate the options for the Rails URL generation for API callbacks remove the script_name parameter from the url_options since that is causing issues

with the route not containing the engine path in rails 4.2.0

@return [Hash]

# File lib/browse_everything/driver/base.rb, line 107
def callback_options
  options = config.to_hash
  options.deep_symbolize_keys!
  options[:url_options].reject { |k, _v| k == :script_name }
end