Skip to content

Commit

Permalink
Merge pull request #154 from derekmorr/dropbox-refactor
Browse files Browse the repository at this point in the history
address rubocop issues for dropbox driver
  • Loading branch information
jeremyf committed Mar 15, 2017
2 parents d8a6767 + 584b6a3 commit 3f358a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 54 deletions.
37 changes: 5 additions & 32 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require: rubocop-rspec

# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-03-10 16:33:37 -0500 using RuboCop version 0.42.0.
# on 2017-03-13 19:45:39 -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 All @@ -13,7 +11,7 @@ Lint/Loop:
Exclude:
- 'lib/browse_everything/driver/google_drive.rb'

# Offense count: 11
# Offense count: 10
Metrics/AbcSize:
Max: 31

Expand All @@ -35,40 +33,17 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Max: 9

# 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:
- 'app/helpers/browse_everything_helper.rb'

# Offense count: 14
# Offense count: 12
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: strict, flexible
Rails/TimeZone:
Exclude:
- 'lib/browse_everything/driver/box.rb'
- 'lib/browse_everything/driver/dropbox.rb'
- 'lib/browse_everything/driver/google_drive.rb'
- 'lib/browse_everything/driver/sky_drive.rb'
- 'lib/browse_everything/retriever.rb'
Expand Down Expand Up @@ -97,12 +72,11 @@ Style/FileName:
Exclude:
- 'lib/browse-everything.rb'

# Offense count: 5
# Offense count: 4
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/browse_everything/driver/box.rb'
- 'lib/browse_everything/driver/dropbox.rb'
- 'lib/browse_everything/driver/file_system.rb'
- 'lib/browse_everything/driver/google_drive.rb'
- 'lib/browse_everything/driver/sky_drive.rb'
Expand Down Expand Up @@ -144,14 +118,13 @@ Style/PredicateName:
- 'spec/**/*'
- 'app/helpers/browse_everything_helper.rb'

# Offense count: 2
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'lib/browse_everything/driver/box.rb'
- 'lib/browse_everything/driver/dropbox.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand Down
50 changes: 28 additions & 22 deletions lib/browse_everything/driver/dropbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,45 @@
module BrowseEverything
module Driver
class Dropbox < Base
CONFIG_KEYS = [:app_key, :app_secret].freeze

def icon
'dropbox'
end

def validate_config
unless [:app_key, :app_secret].all? { |key| config[key].present? }
raise BrowseEverything::InitializationError, 'Dropbox driver requires :app_key and :app_secret'
end
return if CONFIG_KEYS.all? { |key| config[key].present? }
raise BrowseEverything::InitializationError, "Dropbox driver requires #{CONFIG_KEYS.inspect}"
end

# @return [Array<BrowseEverything::FileEntry>]
def contents(path = '')
path.sub!(/^[\/.]+/, '')
result = []
unless path.empty?
result << BrowseEverything::FileEntry.new(
Pathname(path).join('..'),
'', '..', 0, Time.now, true
)
end
result += client.metadata(path)['contents'].collect do |info|
path = info['path']
BrowseEverything::FileEntry.new(
path,
[key, path].join(':'),
File.basename(path),
info['bytes'],
Time.parse(info['modified']),
info['is_dir']
)
end
path.sub!(%r{ /^[\/.]+/}, '')
result = add_directory_entry(path)
result += client.metadata(path)['contents'].collect { |info| make_file_entry(info) }
result
end

def add_directory_entry(path)
return [] if path.empty?
[BrowseEverything::FileEntry.new(
Pathname(path).join('..'),
'', '..', 0, Time.zone.now, true
)]
end

def make_file_entry(info)
path = info['path']
BrowseEverything::FileEntry.new(
path,
[key, path].join(':'),
File.basename(path),
info['bytes'],
Time.zone.parse(info['modified']),
info['is_dir']
)
end

def link_for(path)
[client.media(path)['url'], { expires: 4.hours.from_now, file_name: File.basename(path), file_size: client.metadata(path)['bytes'].to_i }]
end
Expand Down

0 comments on commit 3f358a3

Please sign in to comment.