Skip to content

Commit

Permalink
Merge pull request #156 from projecthydra/indentation
Browse files Browse the repository at this point in the history
Use Rails indentation style; include rubocop-rspec
  • Loading branch information
jcoyne committed Mar 21, 2017
2 parents 6f96105 + ebc20cf commit 95f2039
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 139 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ RSpec/LeadingSubject:

Style/NumericLiterals:
MinDigits: 7

Style/IndentationConsistency:
EnforcedStyle: rails
26 changes: 25 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require: rubocop-rspec

# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-03-15 21:03:05 -0400 using RuboCop version 0.42.0.
# on 2017-03-21 15:33:13 -0400 using RuboCop version 0.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -29,6 +31,28 @@ Metrics/MethodLength:
Metrics/ParameterLists:
Max: 7

# Offense count: 1
RSpec/DescribeClass:
Exclude:
- 'spec/javascripts/jasmine_spec.rb'

# Offense count: 2
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/features/select_files_spec.rb'
- 'spec/javascripts/jasmine_spec.rb'

# Offense count: 2
RSpec/MultipleExpectations:
Max: 2

# Offense count: 1
# Configuration parameters: IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/views/browse_everything/_file.html.erb_spec.rb'

# Offense count: 1
Rails/OutputSafety:
Exclude:
Expand Down
58 changes: 29 additions & 29 deletions app/controllers/browse_everything_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,40 @@ def resolve

private

def auth_link
@auth_link ||= if provider.present?
link, data = provider.auth_link
session["#{provider_name}_data"] = data
link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
link
end # else nil, implicitly
end
def auth_link
@auth_link ||= if provider.present?
link, data = provider.auth_link
session["#{provider_name}_data"] = data
link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
link
end # else nil, implicitly
end

def browser
if @browser.nil?
@browser = BrowseEverything::Browser.new(url_options)
@browser.providers.values.each do |p|
p.token = session["#{p.key}_token"]
def browser
if @browser.nil?
@browser = BrowseEverything::Browser.new(url_options)
@browser.providers.values.each do |p|
p.token = session["#{p.key}_token"]
end
end
@browser
end
@browser
end

def browse_path
@path ||= params[:path] || ''
end
def browse_path
@path ||= params[:path] || ''
end

def provider
@provider ||= browser.providers[provider_name]
end
def provider
@provider ||= browser.providers[provider_name]
end

def provider_name
@provider_name ||= params[:provider] || params[:state].to_s.split(/\|/).last
end
def provider_name
@provider_name ||= params[:provider] || params[:state].to_s.split(/\|/).last
end

helper_method :auth_link
helper_method :browser
helper_method :browse_path
helper_method :provider
helper_method :provider_name
helper_method :auth_link
helper_method :browser
helper_method :browse_path
helper_method :provider
helper_method :provider_name
end
16 changes: 8 additions & 8 deletions lib/browse_everything/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def connect(_params, _data)

private

def callback
connector_response_url(callback_options)
end
def callback
connector_response_url(callback_options)
end

# 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
def callback_options
config[:url_options].reject { |k, _v| k == :script_name }
end
# 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
def callback_options
config[:url_options].reject { |k, _v| k == :script_name }
end
end
end
end
82 changes: 41 additions & 41 deletions lib/browse_everything/driver/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,50 @@ def connect(params, _data)

private

def oauth_client
RubyBox::Session.new(client_id: config[:client_id],
client_secret: config[:client_secret])
# TODO: error checking here
end
def oauth_client
RubyBox::Session.new(client_id: config[:client_id],
client_secret: config[:client_secret])
# TODO: error checking here
end

def token_expired?(token)
return false unless @token.present? && @token['token'].present?
new_session = RubyBox::Session.new(
client_id: config[:client_id],
client_secret: config[:client_secret],
access_token: token
)
result = new_session.get("#{RubyBox::API_URL}/users/me")
result['status'] != 200
rescue RubyBox::AuthError => e
Rails.logger.error("AuthError occured when checking token. Exception #{e.class.name} : #{e.message}. token as expired and need to refresh it")
return true
end
def token_expired?(token)
return false unless @token.present? && @token['token'].present?
new_session = RubyBox::Session.new(
client_id: config[:client_id],
client_secret: config[:client_secret],
access_token: token
)
result = new_session.get("#{RubyBox::API_URL}/users/me")
result['status'] != 200
rescue RubyBox::AuthError => e
Rails.logger.error("AuthError occured when checking token. Exception #{e.class.name} : #{e.message}. token as expired and need to refresh it")
return true
end

def refresh_token
refresh_token = @token['refresh_token']
token = @token['token']
session = RubyBox::Session.new(
client_id: config[:client_id],
client_secret: config[:client_secret],
access_token: token
)
access_token = session.refresh_token(refresh_token)
@token = { 'token' => access_token.token, 'refresh_token' => access_token.refresh_token }
end
def refresh_token
refresh_token = @token['refresh_token']
token = @token['token']
session = RubyBox::Session.new(
client_id: config[:client_id],
client_secret: config[:client_secret],
access_token: token
)
access_token = session.refresh_token(refresh_token)
@token = { 'token' => access_token.token, 'refresh_token' => access_token.refresh_token }
end

def box_client
refresh_token if token_expired?(@token['token'])
token = @token['token']
refresh_token = @token['refresh_token']
session = RubyBox::Session.new(
client_id: config[:client_id],
client_secret: config[:client_secret],
access_token: token,
refresh_token: refresh_token
)
RubyBox::Client.new(session)
end
def box_client
refresh_token if token_expired?(@token['token'])
token = @token['token']
refresh_token = @token['refresh_token']
session = RubyBox::Session.new(
client_id: config[:client_id],
client_secret: config[:client_secret],
access_token: token,
refresh_token: refresh_token
)
RubyBox::Client.new(session)
end
end
end
end
14 changes: 7 additions & 7 deletions lib/browse_everything/driver/dropbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def authorized?

private

def auth_flow
@csrf ||= {}
DropboxOAuth2Flow.new(config[:app_key], config[:app_secret], callback.to_s, @csrf, 'token')
end
def auth_flow
@csrf ||= {}
DropboxOAuth2Flow.new(config[:app_key], config[:app_secret], callback.to_s, @csrf, 'token')
end

def client
DropboxClient.new(token)
end
def client
DropboxClient.new(token)
end
end
end
end
42 changes: 21 additions & 21 deletions lib/browse_everything/driver/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,33 @@ def details(path, display = File.basename(path))

private

def make_directory_entry(relative_path, real_path)
entries = []
if relative_path.present?
entries << details(File.expand_path('..', real_path), '..')
def make_directory_entry(relative_path, real_path)
entries = []
if relative_path.present?
entries << details(File.expand_path('..', real_path), '..')
end
entries + Dir[File.join(real_path, '*')].collect { |f| details(f) }
end
entries + Dir[File.join(real_path, '*')].collect { |f| details(f) }
end

def sort_entries(entries)
entries.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
def sort_entries(entries)
entries.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
end

def make_pathname(path)
Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(config[:home]))
end
def make_pathname(path)
Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(config[:home]))
end

def file_size(path)
File.size(path).to_i
rescue
0
end
def file_size(path)
File.size(path).to_i
rescue
0
end
end
end
end
30 changes: 15 additions & 15 deletions lib/browse_everything/driver/google_drive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ def drive

private

def authorization
return @auth_client unless @auth_client.nil?
return nil unless token.present?
auth_client.update_token!(token)
self.token = auth_client.fetch_access_token! if auth_client.expired?
auth_client
end
def authorization
return @auth_client unless @auth_client.nil?
return nil unless token.present?
auth_client.update_token!(token)
self.token = auth_client.fetch_access_token! if auth_client.expired?
auth_client
end

def auth_client
@auth_client ||= Signet::OAuth2::Client.new token_credential_uri: 'https://www.googleapis.com/oauth2/v3/token',
authorization_uri: 'https://accounts.google.com/o/oauth2/auth',
scope: 'https://www.googleapis.com/auth/drive',
client_id: config[:client_id],
client_secret: config[:client_secret],
redirect_uri: callback
end
def auth_client
@auth_client ||= Signet::OAuth2::Client.new token_credential_uri: 'https://www.googleapis.com/oauth2/v3/token',
authorization_uri: 'https://accounts.google.com/o/oauth2/auth',
scope: 'https://www.googleapis.com/auth/drive',
client_id: config[:client_id],
client_secret: config[:client_secret],
redirect_uri: callback
end
end
end
end
34 changes: 17 additions & 17 deletions lib/browse_everything/driver/sky_drive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,26 @@ def connect(params, _data)

private

def oauth_client
Skydrive::Oauth::Client.new(config[:client_id], config[:client_secret], callback.to_s, 'wl.skydrive')
# TODO: error checking here
end
def oauth_client
Skydrive::Oauth::Client.new(config[:client_id], config[:client_secret], callback.to_s, 'wl.skydrive')
# TODO: error checking here
end

def rehydrate_token
return @rehydrate_token if @rehydrate_token
token_str = @token[:token]
token_expires = @token[:expires_at]
Rails.logger.warn "\n\n Rehydrating: #{@token} #{token_str} #{token_expires}"
@rehydrate_token = oauth_client.get_access_token_from_hash(token_str, expires_at: token_expires)
end
def rehydrate_token
return @rehydrate_token if @rehydrate_token
token_str = @token[:token]
token_expires = @token[:expires_at]
Rails.logger.warn "\n\n Rehydrating: #{@token} #{token_str} #{token_expires}"
@rehydrate_token = oauth_client.get_access_token_from_hash(token_str, expires_at: token_expires)
end

def safe_id(id)
id.tr('.', '-')
end
def safe_id(id)
id.tr('.', '-')
end

def real_id(id)
id.tr('-', '.')
end
def real_id(id)
id.tr('-', '.')
end
end
end
end

0 comments on commit 95f2039

Please sign in to comment.