Skip to content

Commit

Permalink
Merge branch 'master' into feature/error-message
Browse files Browse the repository at this point in the history
* master: (42 commits)
  Rubocop: Silence Style/IfUnlessModifier
  Rubocop: Silence Lint/Loop
  Rubocop: Fix some remaining cops
  Rubocop: Fix Style/BracesAroundHashParameters
  Extract a common DNSimple Rubocop config
  Rubocop: Fix Style/DotPosition
  Rubocop: Decreate recommended Metrics/MethodLength to 10
  By default, run tests and linter.
  Rubocop: Add a couple of more cops
  Add Rubucop tasks
  Rubocop: Fix Style/BlockDelimiters
  Rubocop: Silence various metrics
  Rubocop: Silence Style/IfInsideElse
  Rubocop: Fix Style/HashSyntax
  Rubocop: Fix Style/EmptyLinesAroundBlockBody
  Rubocop: Fix Style/FormatString
  Rubocop: Fix Style/NumericLiterals
  Rubocop: Fix Style/MultilineMethodCallIndentation
  Rubocop: Fix Style/PercentLiteralDelimiters
  Rubocop: Silence Metrics/AbcSize
  ...
  • Loading branch information
jacegu committed Mar 29, 2016
2 parents b42e00f + 731c06f commit 455ef5f
Show file tree
Hide file tree
Showing 36 changed files with 558 additions and 345 deletions.
13 changes: 13 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,13 @@
inherit_from:
- .rubocop_todo.yml
- .rubocop_dnsimple.yml

# [codesmell]
# It's irrelevant here, but it could be a code smell.
# Hence keep it disabled, but don't include it in the DNSimple suite.
Lint/Loop:
Enabled: false

# It doesn't seem to work as expected.
Style/IfUnlessModifier:
Enabled: false
171 changes: 171 additions & 0 deletions .rubocop_dnsimple.yml
@@ -0,0 +1,171 @@
AllCops:
Exclude:
# Exclude .gemspec files because they are generally auto-generated
- '*.gemspec'

# Generally, the keyword style uses a lot of space. This is particularly true when
# you use case/if statements, in combination with a long-name variable.
#
# invoice_error_message = case error
# when 1 == 1
# do_something
# else
# do_else
# end
#
Lint/EndAlignment:
AlignWith: variable

# [codesmell]
Metrics/AbcSize:
Enabled: false
Exclude:
- 'spec/**/*_spec.rb'
- 'test/**/*_test.rb'

# [codesmell]
Metrics/ClassLength:
Enabled: false
Exclude:
- 'spec/**/*_spec.rb'
- 'test/**/*_test.rb'

# [codesmell]
Metrics/MethodLength:
Enabled: false
Exclude:
- 'spec/**/*_spec.rb'
- 'test/**/*_test.rb'
Max: 10

# [codesmell]
Metrics/LineLength:
Enabled: false
Exclude:
- 'spec/**/*_spec.rb'
- 'test/**/*_test.rb'
Max: 100

# [codesmell]
# I don't really get the point of this cop.
Performance/RedundantMerge:
Enabled: false

# Do not use "and" or "or" in conditionals, but for readability we can use it
# to chain executions. Just beware of operator order.
Style/AndOr:
EnforcedStyle: conditionals

# braces_for_chaining seems a good fit of what we've been doing so far.
Style/BlockDelimiters:
EnforcedStyle: braces_for_chaining
IgnoredMethods:
- expect

# I'd rather use context_dependent, even if I'm not even sure we should enforce a style.
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent

# I was a big fan of leading, but trailing seems to be more commonly adopted.
# At least at the time being.
Style/DotPosition:
EnforcedStyle: trailing

# Double empty lines are useful to separate conceptually different methods
# in the same class or module.
Style/EmptyLines:
Enabled: false

Style/EmptyLinesAroundBlockBody:
Exclude:
# RSpec is all made of blocks. Disable this config in RSpec
# to be consistent with EmptyLinesAroundClassBody and EmptyLinesAroundModuleBody
- 'spec/**/*_spec.rb'
- 'test/**/*_test.rb'

# In most cases, a space is nice. Sometimes, it's not.
# Just be consistent with the rest of the surrounding code.
Style/EmptyLinesAroundClassBody:
Enabled: false

# In most cases, a space is nice. Sometimes, it's not.
# Just be consistent with the rest of the surrounding code.
Style/EmptyLinesAroundModuleBody:
Enabled: false

# I personally don't care about the format style.
# In most cases I like to use %, but not at the point I want to enforce it
# as a convention in the entire code.
Style/FormatString:
Enabled: false

# Prefer the latest Hash syntax
Style/HashSyntax:
Exclude:
# But Rakefiles generally have some definition like
# :default => :test
# that looks nicer with the old rocket syntax.
- 'Rakefile'

# Array indentation should be considered like MultilineMethodCallIndentation indentation
# and use 4 spaces instead of 2.
Style/IndentArray:
IndentationWidth: 4

# Hash indentation should be considered like MultilineMethodCallIndentation indentation
# and use 4 spaces instead of 2.
Style/IndentHash:
IndentationWidth: 4

# [codesmell]
# It's not always that bad.
Style/IfInsideElse:
Enabled: false

# Multi-line differs from standard indentation, they are indented twice.
Style/MultilineMethodCallIndentation:
EnforcedStyle: indented
IndentationWidth: 4

# unless is not always cool.
Style/NegatedIf:
Enabled: false

# Magic numbers are not welcomed
Style/NumericLiterals:
Exclude:
# however tests can use numeric literals for method calls,
# without the need to define a variable just for that.
- 'spec/**/*_spec.rb'
- 'test/**/*_test.rb'

# There are cases were the inline rescue is ok. We can either downgrade the severity,
# or rely on the developer judgement on a case-by-case basis.
Style/RescueModifier:
Enabled: false

# We don't have a preference.
Style/SpecialGlobalVars:
Enabled: false
EnforcedStyle: use_perl_names

# We generally use double quotes, sometimes single quotes.
# Should we enforce it at code level?
Style/StringLiterals:
Enabled: false
EnforcedStyle: double_quotes

# It's nice to be consistent. The trailing comma also allows easy reordering,
# and doesn't cause a diff in Git when you add a line to the bottom.
Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrivialAccessors:
# IgnoreClassMethods because I want to be able to define class-level accessors
# that sets an instance variable on the metaclass, such as:
#
# def self.default=(value)
# @default = value
# end
#
IgnoreClassMethods: true
14 changes: 14 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,14 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-27 01:01:12 +0100 using RuboCop version 0.38.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
# versions of RuboCop, may require this file to be generated again.

Style/Documentation:
# Silence this check for now until we fix it.
Enabled: false
Exclude:
- 'spec/**/*'
- 'test/**/*'
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -4,3 +4,4 @@ gemspec

gem 'rake', '< 11'
gem 'coveralls', require: false
gem 'rubocop', require: false
11 changes: 8 additions & 3 deletions Rakefile
@@ -1,16 +1,21 @@
require 'bundler/gem_tasks'

# Run test by default.
task :default => :spec
# By default, run tests and linter.
task default: [:spec, :rubocop]


require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new do |t|
t.verbose = !!ENV["VERBOSE"]
t.verbose = !ENV["VERBOSE"].nil?
end


require 'rubocop/rake_task'

RuboCop::RakeTask.new


require 'yard'

YARD::Rake::YardocTask.new(:yardoc) do |y|
Expand Down
20 changes: 10 additions & 10 deletions lib/dnsimple/client.rb
Expand Up @@ -11,13 +11,13 @@ module Dnsimple
# @see https://developer.dnsimple.com/
class Client

HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
HEADER_AUTHORIZATION = "Authorization"
WILDCARD_ACCOUNT = "_"
HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token".freeze
HEADER_AUTHORIZATION = "Authorization".freeze
WILDCARD_ACCOUNT = "_".freeze


# @return [String] The current API version.
API_VERSION = "v2"
API_VERSION = "v2".freeze


# Prepends the correct API version to +path+.
Expand Down Expand Up @@ -83,7 +83,7 @@ def get(path, options = {})
# @param [Hash] data The body for the request
# @param [Hash] options The query and header params for the request
# @return [HTTParty::Response]
def post(path, data = nil, options= {})
def post(path, data = nil, options = {})
execute :post, path, data, options
end

Expand Down Expand Up @@ -134,11 +134,11 @@ def execute(method, path, data = nil, options = {})
when 200..299
response
when 401
raise AuthenticationFailed.new(response["message"])
raise AuthenticationFailed, response["message"]
when 404
raise NotFoundError.new(response)
raise NotFoundError, response
else
raise RequestError.new(response)
raise RequestError, response
end
end

Expand Down Expand Up @@ -173,8 +173,8 @@ def base_options
options = {
format: :json,
headers: {
'Accept' => 'application/json',
'User-Agent' => user_agent
'Accept' => 'application/json',
'User-Agent' => user_agent,
},
}

Expand Down
9 changes: 8 additions & 1 deletion lib/dnsimple/client/clients.rb
Expand Up @@ -43,7 +43,14 @@ def webhooks


# @!class Struct
class ClientService < ::Struct.new(:client)
class ClientService

# @return [Dnsimple::Client]
attr_reader :client

def initialize(client)
@client = client
end

# Internal helper that loops over a paginated response and returns all the records in the collection.
#
Expand Down
12 changes: 6 additions & 6 deletions lib/dnsimple/client/contacts.rb
Expand Up @@ -23,8 +23,8 @@ def contacts(account_id, options = {})

Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Contact.new(r) })
end
alias :list :contacts
alias :list_contacts :contacts
alias list contacts
alias list_contacts contacts

# Lists ALL the contacts in the account.
#
Expand All @@ -45,7 +45,7 @@ def contacts(account_id, options = {})
def all_contacts(account_id, options = {})
paginate(:contacts, account_id, options)
end
alias :all :all_contacts
alias all all_contacts

# Creates a contact in the account.
#
Expand All @@ -63,7 +63,7 @@ def create_contact(account_id, attributes, options = {})

Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
end
alias :create :create_contact
alias create create_contact

# Gets a contact from the account.
#
Expand Down Expand Up @@ -98,7 +98,7 @@ def update_contact(account_id, contact_id, attributes, options = {})

Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
end
alias :update :update_contact
alias update update_contact

# Deletes a contact from the account.
#
Expand All @@ -118,7 +118,7 @@ def delete_contact(account_id, contact_id, options = {})

Dnsimple::Response.new(response, nil)
end
alias :delete :delete_contact
alias delete delete_contact

end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/dnsimple/client/domains.rb
Expand Up @@ -23,8 +23,8 @@ def domains(account_id, options = {})

Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Domain.new(r) })
end
alias :list :domains
alias :list_domains :domains
alias list domains
alias list_domains domains

# Lists ALL the domains in the account.
#
Expand All @@ -45,7 +45,7 @@ def domains(account_id, options = {})
def all_domains(account_id, options = {})
paginate(:domains, account_id, options)
end
alias :all :all_domains
alias all all_domains

# Creates a domain in the account.
#
Expand All @@ -64,7 +64,7 @@ def create_domain(account_id, attributes, options = {})

Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
end
alias :create :create_domain
alias create create_domain

# Gets a domain from the account.
#
Expand Down Expand Up @@ -101,7 +101,7 @@ def delete_domain(account_id, domain_id, options = {})

Dnsimple::Response.new(response, nil)
end
alias :delete :delete_domain
alias delete delete_domain

# Resets the domain token.
#
Expand Down

0 comments on commit 455ef5f

Please sign in to comment.