Skip to content

Commit e1c2af2

Browse files
fix: add rubocop and codeclimate
1 parent 5d0f262 commit e1c2af2

15 files changed

+133
-55
lines changed

.codeclimate.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "2"
2+
plugins:
3+
rubocop:
4+
enabled: true
5+
channel: rubocop-0-60
6+
config:
7+
file: ".rubocop.yml"
8+
exclude_patterns:
9+
- "spec/"

.rubocop.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
AllCops:
2+
SuggestExtensions: false
3+
Exclude:
4+
- 'spec/**/*.rb'
5+
- 'bin/**/*'
6+
Style/Documentation:
7+
Enabled: false
8+
Style/HashEachMethods:
9+
Enabled: false
10+
Lint/MissingSuper:
11+
Enabled: false
12+
Lint/UriEscapeUnescape:
13+
Enabled: false

Gemfile

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

35
# Specify your gem's dependencies in postgrest.gemspec
46
gemspec
5-
6-
gem "rake", "~> 12.0"
7-
gem "rspec", "~> 3.0"

Gemfile.lock

+30-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9+
ast (2.4.2)
910
coderay (1.1.3)
1011
diff-lcs (1.4.4)
12+
docile (1.3.5)
1113
method_source (1.0.0)
14+
parallel (1.20.1)
15+
parser (3.0.1.0)
16+
ast (~> 2.4.1)
1217
pry (0.14.1)
1318
coderay (~> 1.1)
1419
method_source (~> 1.0)
15-
rake (12.3.3)
20+
rainbow (3.0.0)
21+
regexp_parser (2.1.1)
22+
rexml (3.2.5)
1623
rspec (3.10.0)
1724
rspec-core (~> 3.10.0)
1825
rspec-expectations (~> 3.10.0)
@@ -26,15 +33,35 @@ GEM
2633
diff-lcs (>= 1.2.0, < 2.0)
2734
rspec-support (~> 3.10.0)
2835
rspec-support (3.10.2)
36+
rubocop (1.13.0)
37+
parallel (~> 1.10)
38+
parser (>= 3.0.0.0)
39+
rainbow (>= 2.2.2, < 4.0)
40+
regexp_parser (>= 1.8, < 3.0)
41+
rexml
42+
rubocop-ast (>= 1.2.0, < 2.0)
43+
ruby-progressbar (~> 1.7)
44+
unicode-display_width (>= 1.4.0, < 3.0)
45+
rubocop-ast (1.4.1)
46+
parser (>= 2.7.1.5)
47+
ruby-progressbar (1.11.0)
48+
simplecov (0.21.2)
49+
docile (~> 1.1)
50+
simplecov-html (~> 0.11)
51+
simplecov_json_formatter (~> 0.1)
52+
simplecov-html (0.12.3)
53+
simplecov_json_formatter (0.1.2)
54+
unicode-display_width (2.0.0)
2955

3056
PLATFORMS
3157
ruby
3258

3359
DEPENDENCIES
3460
postgrest!
3561
pry
36-
rake (~> 12.0)
37-
rspec (~> 3.0)
62+
rspec (~> 3.5)
63+
rubocop (~> 1.13.0)
64+
simplecov (~> 0.21.2)
3865

3966
BUNDLED WITH
4067
2.1.4

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# PostgREST
22

3+
## Status
4+
5+
[![Build Status](https://api.travis-ci.org/marcelobarreto/postgrest.svg?branch=master)](https://travis-ci.org/marcelobarreto/postgrest)
6+
[![Code Climate](https://codeclimate.com/github/marcelobarreto/postgrest.svg)](https://codeclimate.com/github/marcelobareto/postgrest)
7+
[![Code Climate](https://codeclimate.com/github/marcelobarreto/postgrest/coverage.svg)](https://codeclimate.com/github/marcelobarreto/postgrest)
8+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
9+
[![RubyGems](http://img.shields.io/gem/dt/postgrest.svg?style=flat)](http://rubygems.org/gems/postgrest)
10+
311
Ruby client for [PostgREST](https://postgrest.org/)
412

513
This gem is under development, any help are welcome :muscle:

Rakefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
require "bundler/gem_tasks"
2-
require "rspec/core/rake_task"
1+
# frozen_string_literal: true
2+
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
35

46
RSpec::Core::RakeTask.new(:spec)
57

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

bin/console

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

3-
require "bundler/setup"
4-
require "postgrest"
4+
require 'bundler/setup'
5+
require 'postgrest'
56

67
# You can add fixtures and/or initialization code here to make experimenting
78
# with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "postgrest"
1011
# require "pry"
1112
# Pry.start
1213

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

lib/postgrest.rb

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
require "postgrest/version"
2-
require "postgrest/http"
3-
require "postgrest/client"
4-
require "postgrest/query_builder"
5-
require "postgrest/response"
1+
# frozen_string_literal: true
2+
3+
require 'postgrest/version'
4+
require 'postgrest/http'
5+
require 'postgrest/client'
6+
require 'postgrest/query_builder'
7+
require 'postgrest/response'
68

79
module Postgrest
810
class MissingTableError < StandardError; end
11+
912
class RequestError < StandardError; end
1013
end

lib/postgrest/client.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Postgrest
24
class Client
35
DEFAULT_SCHEMA = 'public'

lib/postgrest/http.rb

+15-15
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def get(uri:, query: {}, headers: {})
2727
data = response_is_successful?(res) ? JSON.parse(res.body) : []
2828

2929
Response.new({
30-
error: !response_is_successful?(res),
31-
data: data,
32-
count: data.count,
33-
status: res.code.to_i,
34-
status_text: res.message,
35-
body: query,
36-
})
30+
error: !response_is_successful?(res),
31+
data: data,
32+
count: data.count,
33+
status: res.code.to_i,
34+
status_text: res.message,
35+
body: query
36+
})
3737
end
3838

3939
def post(uri:, body: {}, headers: {})
@@ -46,13 +46,13 @@ def post(uri:, body: {}, headers: {})
4646
end
4747

4848
Response.new({
49-
error: !response_is_successful?(res),
50-
data: res.body,
51-
count: nil,
52-
status: res.code.to_i,
53-
status_text: res.message,
54-
body: body,
55-
})
49+
error: !response_is_successful?(res),
50+
data: res.body,
51+
count: nil,
52+
status: res.code.to_i,
53+
status_text: res.message,
54+
body: body
55+
})
5656
end
5757

5858
private
@@ -62,4 +62,4 @@ def response_is_successful?(response)
6262
end
6363
end
6464
end
65-
end
65+
end

lib/postgrest/query_builder.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Postgrest
24
class QueryBuilder
35
attr_accessor :uri, :headers, :schema

lib/postgrest/response.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
# frozen_string_literal: true
2+
13
module Postgrest
24
class Response
35
attr_reader :error, :data, :count, :status, :status_text, :body
46

5-
def initialize(data:, status:, status_text:, body:, error: nil, count: 0)
6-
@error = error
7-
@data = data
8-
@count = count
9-
@status = status
10-
@status_text = status_text
11-
@body = body
7+
def initialize(params = {})
8+
@error = params[:error]
9+
@data = params[:data]
10+
@count = params[:count]
11+
@status = params[:status]
12+
@status_text = params[:status_text]
13+
@body = params[:body]
1214
end
1315
end
1416
end

lib/postgrest/version.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Postgrest
2-
VERSION = "0.1.0"
4+
VERSION = '0.1.0'
35
end

postgrest.gemspec

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1+
# frozen_string_literal: true
2+
13
require_relative 'lib/postgrest/version'
24

35
Gem::Specification.new do |spec|
4-
spec.name = "postgrest"
6+
spec.name = 'postgrest'
57
spec.version = Postgrest::VERSION
6-
spec.authors = ["Marcelo Barreto"]
7-
spec.email = ["[email protected]"]
8+
spec.authors = ['Marcelo Barreto']
9+
spec.email = ['[email protected]']
810

9-
spec.summary = "Ruby client for PostgREST"
10-
spec.description = "Ruby client for PostgREST"
11-
spec.homepage = "https://github.com/marcelobarreto/postgrest-rb"
12-
spec.license = "MIT"
13-
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11+
spec.summary = 'Ruby client for PostgREST'
12+
spec.description = 'Ruby client for PostgREST'
13+
spec.homepage = 'https://github.com/marcelobarreto/postgrest-rb'
14+
spec.license = 'MIT'
15+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
1416

15-
spec.metadata["homepage_uri"] = spec.homepage
16-
spec.metadata["source_code_uri"] = "https://github.com/marcelobarreto/postgrest-rb"
17+
spec.metadata['homepage_uri'] = spec.homepage
18+
spec.metadata['source_code_uri'] = 'https://github.com/marcelobarreto/postgrest-rb'
1719

1820
# Specify which files should be added to the gem when it is released.
1921
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
2123
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
2224
end
23-
spec.bindir = "exe"
25+
spec.bindir = 'exe'
2426
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25-
spec.require_paths = ["lib"]
27+
spec.require_paths = ['lib']
2628

27-
spec.add_development_dependency "pry"
29+
spec.add_development_dependency 'pry'
30+
spec.add_development_dependency 'rspec', '~> 3.5'
31+
spec.add_development_dependency 'rubocop', '~> 1.13.0'
32+
spec.add_development_dependency 'simplecov', '~> 0.21.2'
2833
end

spec/spec_helper.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
require "bundler/setup"
22
require "postgrest"
33

4+
require 'simplecov'
5+
SimpleCov.start
6+
47
RSpec.configure do |config|
58
# Enable flags like --only-failures and --next-failure
69
config.example_status_persistence_file_path = ".rspec_status"

0 commit comments

Comments
 (0)