Skip to content

Commit fb28bb4

Browse files
committed
Small code improvements
1 parent 873cea4 commit fb28bb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+461
-218
lines changed

.rubocop.yml

+98-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,105 @@
1+
require:
2+
- rubocop/cop/internal_affairs
3+
- rubocop-performance
4+
- rubocop-rspec
15
AllCops:
2-
Include:
3-
- '**/Rakefile'
6+
NewCops: enable
47
Exclude:
5-
- 'spec/**/*'
6-
Metrics/LineLength:
7-
Max: 99
8-
Naming/FileName:
8+
- "bin/*"
9+
- "vendor/**/*"
10+
- "Rakefile"
11+
- "tmp/**/*"
12+
- ".git/**/*"
13+
TargetRubyVersion: 2.5
14+
Style/Documentation:
15+
Enabled: false
16+
Layout/LineLength:
17+
Max: 1000
18+
Metrics/MethodLength:
19+
Max: 250
20+
Metrics/ClassLength:
21+
Max: 1000
22+
Metrics/AbcSize:
23+
Max: 250
24+
Metrics/BlockLength:
25+
Max: 1500
26+
Metrics/CyclomaticComplexity:
27+
Max: 50
28+
Metrics/PerceivedComplexity:
29+
Max: 50
30+
Style/ClassAndModuleChildren:
931
Enabled: false
1032
Style/ModuleFunction:
1133
Enabled: false
12-
Style/Encoding:
34+
Style/ParallelAssignment:
1335
Enabled: false
14-
Documentation:
36+
Style/SymbolProc:
37+
Enabled: false
38+
Layout/HashAlignment:
39+
Enabled: false
40+
Metrics/BlockNesting:
41+
Enabled: false
42+
Lint/NonLocalExitFromIterator:
43+
Enabled: false
44+
Style/HashEachMethods:
45+
Enabled: true
46+
Style/HashTransformKeys:
47+
Enabled: true
48+
Style/HashTransformValues:
49+
Enabled: true
50+
Style/AndOr:
51+
Enabled: false
52+
RSpec/ExampleLength:
53+
Enabled: false
54+
RSpec/MultipleExpectations:
55+
Enabled: false
56+
RSpec/DescribeClass:
57+
Enabled: false
58+
Style/IfInsideElse:
59+
Enabled: false
60+
Layout/EmptyLinesAroundAttributeAccessor:
61+
Enabled: true
62+
Layout/SpaceAroundMethodCallOperator:
63+
Enabled: true
64+
Lint/DeprecatedOpenSSLConstant:
65+
Enabled: true
66+
Lint/MixedRegexpCaptureTypes:
67+
Enabled: true
68+
Lint/RaiseException:
69+
Enabled: true
70+
Lint/StructNewOverride:
71+
Enabled: true
72+
Style/ExponentialNotation:
73+
Enabled: false
74+
Style/RedundantFetchBlock:
75+
Enabled: true
76+
Style/RedundantRegexpCharacterClass:
77+
Enabled: true
78+
Style/RedundantRegexpEscape:
79+
Enabled: true
80+
Style/SlicingWithRange:
81+
Enabled: true
82+
Style/AccessorGrouping:
83+
Enabled: true
84+
Style/BisectedAttrAccessor:
85+
Enabled: true
86+
Style/RedundantAssignment:
87+
Enabled: true
88+
Performance/AncestorsInclude:
89+
Enabled: true
90+
Performance/BigDecimalWithNumericArgument:
91+
Enabled: true
92+
Performance/RedundantSortBlock:
93+
Enabled: true
94+
Performance/RedundantStringChars:
95+
Enabled: true
96+
Performance/ReverseFirst:
97+
Enabled: true
98+
Performance/SortReverse:
99+
Enabled: true
100+
Performance/Squeeze:
101+
Enabled: true
102+
Performance/StringInclude:
103+
Enabled: true
104+
RSpec/ContextWording:
15105
Enabled: false
16-
Metrics/MethodLength:
17-
Max: 15

Gemfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
# Specify your gem's dependencies in pipedrive.gemspec
46
gemspec
57

68
group :test do
7-
gem 'simplecov', :require => false
8-
gem 'coveralls', :require => false
9+
gem 'coveralls', require: false
10+
gem 'simplecov', require: false
911
end
1012

1113
group :local_development do
12-
gem 'terminal-notifier-guard', require: false if RUBY_PLATFORM.downcase.include?('darwin')
13-
gem 'guard-rspec', '>= 4.3.1' ,require: false
14-
gem 'guard-bundler', require: false
15-
gem 'guard-rubocop', require: false
1614
gem 'pry'
1715
end

Guardfile

-24
This file was deleted.

lib/pipedrive.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'logger'
24
require 'active_support/core_ext/hash'
35
require 'active_support/concern'
@@ -33,7 +35,7 @@ def setup
3335
end
3436

3537
def logger
36-
@logger ||= Logger.new(STDOUT)
38+
@logger ||= Logger.new($stdout)
3739
end
3840

3941
reset!

lib/pipedrive/activity.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Activity < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/activity_type.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class ActivityType < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/base.rb

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Base
35
def initialize(api_token = ::Pipedrive.api_token)
4-
fail 'api_token should be set' unless api_token.present?
6+
raise 'api_token should be set' unless api_token.present?
7+
58
@api_token = api_token
69
end
710

@@ -12,7 +15,8 @@ def connection
1215
def make_api_call(*args)
1316
params = args.extract_options!
1417
method = args[0]
15-
fail 'method param missing' unless method.present?
18+
raise 'method param missing' unless method.present?
19+
1620
url = build_url(args, params.delete(:fields_to_select))
1721
begin
1822
res = connection.__send__(method.to_sym, url, params)
@@ -26,11 +30,9 @@ def make_api_call(*args)
2630
end
2731

2832
def build_url(args, fields_to_select = nil)
29-
url = "/v1/#{entity_name}"
33+
url = +"/v1/#{entity_name}"
3034
url << "/#{args[1]}" if args[1]
31-
if fields_to_select.is_a?(::Array) && fields_to_select.size > 0
32-
url << ":(#{fields_to_select.join(',')})"
33-
end
35+
url << ":(#{fields_to_select.join(',')})" if fields_to_select.is_a?(::Array) && fields_to_select.size.positive?
3436
url << "?api_token=#{@api_token}"
3537
url
3638
end
@@ -52,16 +54,16 @@ def failed_response(res)
5254
failed: false)
5355
case res.status
5456
when 401
55-
failed_res.merge! not_authorized: true
57+
failed_res[:not_authorized] = true
5658
when 420
57-
failed_res.merge! failed: true
59+
failed_res[:failed] = true
5860
end
5961
failed_res
6062
end
6163

6264
def entity_name
63-
class_name = self.class.name.split("::")[-1].downcase.pluralize
64-
class_names = { "people" => "persons" }
65+
class_name = self.class.name.split('::')[-1].downcase.pluralize
66+
class_names = { 'people' => 'persons' }
6567
class_names[class_name] || class_name
6668
end
6769

@@ -77,7 +79,8 @@ def faraday_options
7779
end
7880

7981
# This method smells of :reek:TooManyStatements
80-
def connection # :nodoc
82+
# :nodoc
83+
def connection
8184
@connection ||= Faraday.new(faraday_options) do |conn|
8285
conn.request :url_encoded
8386
conn.response :mashify

lib/pipedrive/deal.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Deal < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/deal_field.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class DealField < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/file.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class File < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/filter.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Filter < Base
35
include ::Pipedrive::Operations::Read

lib/pipedrive/goal.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Goal < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/note.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Note < Base
35
include ::Pipedrive::Operations::Create

lib/pipedrive/operations/create.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
module Operations
35
module Create

lib/pipedrive/operations/delete.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
module Operations
35
module Delete

lib/pipedrive/operations/read.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
module Operations
35
module Read
46
extend ActiveSupport::Concern
57
include ::Enumerable
68
include ::Pipedrive::Utils
79

8-
# This method smells of :reek:TooManyStatements but ignores them
9-
def each(params = {})
10+
def each(params = {}, &block)
1011
return to_enum(:each, params) unless block_given?
11-
follow_pagination(:chunk, [], params) { |item| yield item }
12+
13+
follow_pagination(:chunk, [], params, &block)
1214
end
1315

1416
def all(params = {})
@@ -18,6 +20,7 @@ def all(params = {})
1820
def chunk(params = {})
1921
res = make_api_call(:get, params)
2022
return [] unless res.success?
23+
2124
res
2225
end
2326

lib/pipedrive/operations/update.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
module Operations
35
module Update
@@ -7,7 +9,8 @@ def update(*args)
79
params = args.extract_options!
810
params.symbolize_keys!
911
id = params.delete(:id) || args[0]
10-
fail 'id must be provided' unless id
12+
raise 'id must be provided' unless id
13+
1114
make_api_call(:put, id, params)
1215
end
1316
end

lib/pipedrive/organization.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class Organization < Base
35
include ::Pipedrive::Operations::Read
@@ -6,12 +8,13 @@ class Organization < Base
68
include ::Pipedrive::Operations::Delete
79
include ::Pipedrive::Utils
810

9-
def find_by_name(*args)
11+
def find_by_name(*args, &block)
1012
params = args.extract_options!
1113
params[:term] ||= args[0]
12-
fail 'term is missing' unless params[:term]
14+
raise 'term is missing' unless params[:term]
1315
return to_enum(:find_by_name, params) unless block_given?
14-
follow_pagination(:make_api_call, [:get, 'find'], params) { |item| yield item }
16+
17+
follow_pagination(:make_api_call, [:get, 'find'], params, &block)
1518
end
1619
end
1720
end

lib/pipedrive/organization_field.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Pipedrive
24
class OrganizationField < Base
35
include ::Pipedrive::Operations::Read

0 commit comments

Comments
 (0)