Skip to content

Commit aa01cfd

Browse files
authored
rRubocop and configuration (#2)
* rubocop * change directory structure * string literals * configuration specs
1 parent 15fbaf3 commit aa01cfd

File tree

12 files changed

+215
-30
lines changed

12 files changed

+215
-30
lines changed

.rubocop.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
require:
2+
- rubocop-rspec
3+
# Explanations of all possible options:
4+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
5+
AllCops:
6+
DisplayCopNames: true
7+
DisplayStyleGuide: true
8+
Exclude:
9+
- 'pkg/**/*'
10+
- 'vendor/**/*'
11+
- 'spec/fixtures/**/*'
12+
13+
Metrics/MethodLength:
14+
Max: 25
15+
16+
Layout/LineLength:
17+
Max: 160
18+
19+
# Details:
20+
# http://c2.com/cgi/wiki?AbcMetric
21+
Metrics/AbcSize:
22+
# The ABC size is a calculated magnitude, so this number can be a Fixnum or
23+
# a Float.
24+
Max: 20
25+
26+
Style/StringLiterals:
27+
EnforcedStyle: single_quotes
28+
29+
Style/HashSyntax:
30+
EnforcedStyle: ruby19
31+
32+
Style/NumericLiterals:
33+
Enabled: false
34+
35+
Style/SignalException:
36+
EnforcedStyle: only_raise
37+
38+
Metrics/ClassLength:
39+
Max: 120
40+
41+
# TODO: enable this when Ruby 3.0 is out.
42+
Style/FrozenStringLiteralComment:
43+
Enabled: false
44+
45+
Layout/FirstArrayElementIndentation:
46+
EnforcedStyle: consistent
47+
48+
Style/NumericPredicate:
49+
Enabled: false
50+
51+
Naming/VariableNumber:
52+
Enabled: false
53+
54+
Style/SafeNavigation:
55+
Enabled: false
56+
57+
Metrics/BlockLength:
58+
CountComments: false
59+
Max: 25
60+
Exclude:
61+
- 'Rakefile'
62+
- '**/*.rake'
63+
- 'spec/**/*.rb'
64+
65+
Layout/HeredocIndentation:
66+
Enabled: false
67+
68+
Gemspec/OrderedDependencies:
69+
Enabled: false
70+
71+
Style/FormatStringToken:
72+
Enabled: false
73+
74+
Naming/MethodParameterName:
75+
Enabled: false
76+
77+
Gemspec/RequiredRubyVersion:
78+
Enabled: false
79+
80+
Style/TrailingCommaInArguments:
81+
EnforcedStyleForMultiline: comma
82+
83+
Style/TrailingCommaInArrayLiteral:
84+
EnforcedStyleForMultiline: comma
85+
86+
Style/TrailingCommaInHashLiteral:
87+
EnforcedStyleForMultiline: comma
88+
89+
Naming/RescuedExceptionsVariableName:
90+
Enabled: false
91+
92+
Lint/RaiseException:
93+
Enabled: true
94+
95+
Lint/StructNewOverride:
96+
Enabled: true
97+
98+
Style/HashEachMethods:
99+
Enabled: true
100+
101+
Style/HashTransformKeys:
102+
Enabled: true
103+
104+
Style/HashTransformValues:
105+
Enabled: true
106+
107+
RSpec/FilePath:
108+
Enabled: true
109+
IgnoreMethods: true
110+
111+
Style/Documentation:
112+
Enabled: false

Gemfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in cirro-ruby-client.gemspec
44
gemspec
55

6-
gem "rake", "~> 12.0"
7-
gem "rspec", "~> 3.0"
6+
gem 'rake', '~> 12.0'
7+
gem 'rspec', '~> 3.0'
8+
9+
group :development do
10+
gem 'rubocop', require: false
11+
gem 'rubocop-rspec'
12+
end

Gemfile.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9+
ast (2.4.1)
910
diff-lcs (1.4.4)
11+
parallel (1.19.2)
12+
parser (2.7.2.0)
13+
ast (~> 2.4.1)
14+
rainbow (3.0.0)
1015
rake (12.3.3)
16+
regexp_parser (1.8.1)
17+
rexml (3.2.4)
1118
rspec (3.9.0)
1219
rspec-core (~> 3.9.0)
1320
rspec-expectations (~> 3.9.0)
@@ -21,6 +28,21 @@ GEM
2128
diff-lcs (>= 1.2.0, < 2.0)
2229
rspec-support (~> 3.9.0)
2330
rspec-support (3.9.3)
31+
rubocop (0.92.0)
32+
parallel (~> 1.10)
33+
parser (>= 2.7.1.5)
34+
rainbow (>= 2.2.2, < 4.0)
35+
regexp_parser (>= 1.7)
36+
rexml
37+
rubocop-ast (>= 0.5.0)
38+
ruby-progressbar (~> 1.7)
39+
unicode-display_width (>= 1.4.0, < 2.0)
40+
rubocop-ast (0.7.1)
41+
parser (>= 2.7.1.5)
42+
rubocop-rspec (1.43.2)
43+
rubocop (~> 0.87)
44+
ruby-progressbar (1.10.1)
45+
unicode-display_width (1.7.0)
2446

2547
PLATFORMS
2648
ruby
@@ -29,6 +51,8 @@ DEPENDENCIES
2951
cirro-ruby-client!
3052
rake (~> 12.0)
3153
rspec (~> 3.0)
54+
rubocop
55+
rubocop-rspec
3256

3357
BUNDLED WITH
3458
2.1.4

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require "bundler/gem_tasks"
2-
require "rspec/core/rake_task"
1+
require 'bundler/gem_tasks'
2+
require 'rspec/core/rake_task'
33

44
RSpec::Core::RakeTask.new(:spec)
55

6-
task :default => :spec
6+
task default: :spec

bin/console

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

3-
require "bundler/setup"
4-
require "cirro_i_o/client"
3+
require 'bundler/setup'
4+
require 'cirro_io/client'
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cirro_i_o/client"
1010
# require "pry"
1111
# Pry.start
1212

13-
require "irb"
13+
require 'irb'
1414
IRB.start(__FILE__)

cirro-ruby-client.gemspec

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
require_relative 'lib/cirro_i_o/client/version'
1+
require_relative 'lib/cirro_io/client/version'
22

33
Gem::Specification.new do |spec|
4-
spec.name = "cirro-ruby-client"
4+
spec.name = 'cirro-ruby-client'
55
spec.version = CirroIO::Client::VERSION
6-
spec.authors = ["Cirro Dev Team"]
7-
spec.email = ["[email protected]"]
6+
spec.authors = ['Cirro Dev Team']
7+
spec.email = ['[email protected]']
88

9-
spec.summary = "Ruby client library for Cirro API"
10-
spec.description = "Simple wrapper for Cirro API"
11-
spec.homepage = "https://cirro.io/api-docs/v1#cirro-api-documentation"
12-
spec.license = "MIT"
13-
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
9+
spec.summary = 'Ruby client library for Cirro API'
10+
spec.description = 'Simple wrapper for Cirro API'
11+
spec.homepage = 'https://cirro.io/api-docs/v1#cirro-api-documentation'
12+
spec.license = 'MIT'
13+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
1414

15-
spec.metadata["homepage_uri"] = spec.homepage
16-
spec.metadata["source_code_uri"] = "https://github.com/test-IO/cirro-ruby-client"
17-
spec.metadata["changelog_uri"] = "https://github.com/test-IO/cirro-ruby-client/CHANGELOG.md"
15+
spec.metadata['homepage_uri'] = spec.homepage
16+
spec.metadata['source_code_uri'] = 'https://github.com/test-IO/cirro-ruby-client'
17+
spec.metadata['changelog_uri'] = 'https://github.com/test-IO/cirro-ruby-client/CHANGELOG.md'
1818

1919
# Specify which files should be added to the gem when it is released.
2020
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
2222
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
2323
end
24-
spec.bindir = "exe"
24+
spec.bindir = 'exe'
2525
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26-
spec.require_paths = ["lib"]
26+
spec.require_paths = ['lib']
2727
end

lib/cirro_i_o/client.rb renamed to lib/cirro_io/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "cirro_i_o/client/version"
1+
require 'cirro_io/client/version'
22

33
module CirroIO
44
module Client
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module CirroIO
2+
module Client
3+
class Configuration
4+
def app_id(value = nil)
5+
@app_id = value unless value.nil?
6+
raise 'app_id must be defined' unless defined?(@app_id)
7+
8+
@app_id
9+
end
10+
11+
def private_key_path(value = nil)
12+
@private_key_path = value unless value.nil?
13+
raise 'private_key_path must be defined' unless defined?(@private_key_path)
14+
15+
@private_key_path
16+
end
17+
end
18+
end
19+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module CirroIO
22
module Client
3-
VERSION = "0.1.0"
3+
VERSION = '0.1.0'.freeze
44
end
55
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'cirro_io/client/configuration'
2+
3+
RSpec.describe CirroIO::Client::Configuration do
4+
let(:configuration) { described_class.new }
5+
6+
it 'assigns app_id' do
7+
configuration.app_id '12345'
8+
9+
expect(configuration.app_id).to eq('12345')
10+
end
11+
12+
it 'raise exception if app_id is not set' do
13+
expect { configuration.app_id }.to raise_error('app_id must be defined')
14+
end
15+
16+
it 'assigns private_key_path' do
17+
configuration.private_key_path './storage/cirro.pem'
18+
19+
expect(configuration.private_key_path).to eq('./storage/cirro.pem')
20+
end
21+
22+
it 'raise exception if private_key_path is not set' do
23+
expect { configuration.private_key_path }.to raise_error('private_key_path must be defined')
24+
end
25+
end

0 commit comments

Comments
 (0)