Skip to content

Commit

Permalink
Add rubocop to project
Browse files Browse the repository at this point in the history
  • Loading branch information
hasghari committed Feb 9, 2020
1 parent 61024e8 commit c012f6f
Show file tree
Hide file tree
Showing 20 changed files with 288 additions and 172 deletions.
38 changes: 38 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
inherit_mode:
merge:
- Exclude

AllCops:
TargetRubyVersion: 2.6
Exclude:
- gemfiles/**

Layout/LineLength:
Max: 120

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented_relative_to_receiver

Naming/PredicateName:
AllowedMethods:
- has_many

Style/Documentation:
Enabled: false

Style/EmptyMethod:
EnforcedStyle: expanded

Style/FormatStringToken:
EnforcedStyle: template

Style/FrozenStringLiteralComment:
Enabled: false

Style/PercentLiteralDelimiters:
PreferredDelimiters:
default: ()
'%w': '()'
'%W': '()'
'%i': '()'
'%I': '()'
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ require 'rspec/core/rake_task'

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

task :default => :spec
task default: :spec
18 changes: 18 additions & 0 deletions gemfiles/activerecord_5.1.5.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GEM
rake
thor (>= 0.14.0)
arel (8.0.0)
ast (2.4.0)
builder (3.2.3)
coderay (1.1.2)
combustion (1.1.1)
Expand All @@ -50,6 +51,7 @@ GEM
erubi (1.7.1)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
json (2.1.0)
loofah (2.2.2)
crass (~> 1.0.2)
Expand All @@ -59,6 +61,9 @@ GEM
minitest (5.11.3)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
pg (1.2.2)
pry (0.11.3)
coderay (~> 1.1.0)
Expand All @@ -77,6 +82,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (10.5.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
Expand All @@ -95,6 +101,16 @@ GEM
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-rspec (1.37.1)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -104,6 +120,7 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.6.1)

PLATFORMS
ruby
Expand All @@ -119,6 +136,7 @@ DEPENDENCIES
pry (~> 0.10)
rake (~> 10.0)
rspec-rails (~> 3.7)
rubocop-rspec (~> 1.37)
simplecov (~> 0.16)

BUNDLED WITH
Expand Down
18 changes: 18 additions & 0 deletions gemfiles/activerecord_5.2.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GEM
rake
thor (>= 0.14.0)
arel (9.0.0)
ast (2.4.0)
builder (3.2.3)
coderay (1.1.2)
combustion (1.1.1)
Expand All @@ -50,6 +51,7 @@ GEM
erubi (1.7.1)
i18n (1.0.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
json (2.1.0)
loofah (2.2.2)
crass (~> 1.0.2)
Expand All @@ -59,6 +61,9 @@ GEM
minitest (5.11.3)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
pg (1.2.2)
pry (0.11.3)
coderay (~> 1.1.0)
Expand All @@ -77,6 +82,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (10.5.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
Expand All @@ -95,6 +101,16 @@ GEM
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-rspec (1.37.1)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -104,6 +120,7 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.6.1)

PLATFORMS
ruby
Expand All @@ -119,6 +136,7 @@ DEPENDENCIES
pry (~> 0.10)
rake (~> 10.0)
rspec-rails (~> 3.7)
rubocop-rspec (~> 1.37)
simplecov (~> 0.16)

BUNDLED WITH
Expand Down
18 changes: 18 additions & 0 deletions gemfiles/activerecord_6.0.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ GEM
bundler
rake
thor (>= 0.14.0)
ast (2.4.0)
builder (3.2.3)
coderay (1.1.2)
combustion (1.1.1)
Expand All @@ -49,6 +50,7 @@ GEM
erubi (1.8.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
json (2.2.0)
loofah (2.2.3)
crass (~> 1.0.2)
Expand All @@ -58,6 +60,9 @@ GEM
minitest (5.11.3)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
pg (1.2.2)
pry (0.12.2)
coderay (~> 1.1.0)
Expand All @@ -76,6 +81,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (10.5.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
Expand All @@ -94,6 +100,16 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-rspec (1.37.1)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
simplecov (0.17.0)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -103,6 +119,7 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.6.1)
zeitwerk (2.1.9)

PLATFORMS
Expand All @@ -119,6 +136,7 @@ DEPENDENCIES
pry (~> 0.10)
rake (~> 10.0)
rspec-rails (~> 3.7)
rubocop-rspec (~> 1.37)
simplecov (~> 0.16)

BUNDLED WITH
Expand Down
6 changes: 3 additions & 3 deletions lib/parentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Parentry
autoload :Navigation, 'parentry/navigation'
autoload :ClassMethods, 'parentry/class_methods'

# rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/BlockLength
def self.included(base)
base.class_eval do
mattr_accessor :parentry_strategy, :parentry_column, :depth_offset, :cache_depth, :touch_ancestors
Expand All @@ -14,9 +15,7 @@ def self.included(base)
has_many :children, class_name: base_class.name, foreign_key: :parent_id, dependent: :destroy

validate do
unless parent.blank? || parent.persisted?
errors.add(:parent, 'must be persisted')
end
errors.add(:parent, 'must be persisted') unless parent.blank? || parent.persisted?
end

validate :prevent_circular_parentry
Expand Down Expand Up @@ -52,4 +51,5 @@ def self.included(base)
base.send :include, InstanceMethods
base.extend ClassMethods
end
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength,Metrics/BlockLength
end
6 changes: 4 additions & 2 deletions lib/parentry/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ def parentry(options = {})
include Strategy::Array if parentry_strategy == 'array'
end

# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
def arrange(options = {})
scope =
if (order = options.delete(:order))
self.base_class.order_by_parentry.order(order)
base_class.order_by_parentry.order(order)
else
self.base_class.order_by_parentry
base_class.order_by_parentry
end

scope.where(options).each_with_object(Hash.new { |h, k| h[k] = {} }) do |node, memo|
Expand All @@ -27,5 +28,6 @@ def arrange(options = {})
insert_node[node] = {}
end
end
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
end
end
1 change: 1 addition & 0 deletions lib/parentry/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def touch_callbacks_disabled?

def ancestor_ids_was
return [] unless saved_changes[parentry_column]

parse_parentry(saved_changes[parentry_column][0]).tap(&:pop)
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/parentry/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def ancestors(scopes = {})
end

def leaf?
children.size == 0
children.size.zero?
end
alias_method :childless?, :leaf?
alias childless? leaf?

def children?
!leaf?
Expand All @@ -50,7 +50,7 @@ def siblings
end

def siblings?
siblings.size > 0
siblings.size.positive?
end

def only_child?
Expand Down Expand Up @@ -80,6 +80,7 @@ def descendants(scopes = {})
def depth
return depth_offset if root?
return parent.depth + 1 if changes[:parent_id].present?

path_ids.size - 1 + depth_offset
end

Expand Down
1 change: 1 addition & 0 deletions lib/parentry/strategy/array/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def parse_parentry(input = parentry)

def compute_parentry
return [] unless persisted?

parent.present? ? parent.parentry + [id] : [id]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/parentry/strategy/ltree/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def parse_parentry(input = parentry)
end

def compute_parentry
parent.present? ? "#{parent.parentry}.#{id}" : "#{id}"
parent.present? ? "#{parent.parentry}.#{id}" : id.to_s
end

def cascade_parentry
Expand Down
2 changes: 1 addition & 1 deletion lib/parentry/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Parentry
VERSION = '1.3.0'
VERSION = '1.3.0'.freeze
end
12 changes: 6 additions & 6 deletions parentry.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'parentry/version'

Expand All @@ -9,7 +8,7 @@ Gem::Specification.new do |spec|
spec.authors = ['Hamed Asghari']
spec.email = ['[email protected]']

spec.summary = %q{ActiveRecord adapter for the Postgres ltree module}
spec.summary = 'ActiveRecord adapter for the Postgres ltree module'
spec.homepage = 'https://github.com/hasghari/parentry'
spec.license = 'MIT'

Expand All @@ -19,11 +18,12 @@ Gem::Specification.new do |spec|
spec.add_dependency 'activerecord', '>= 5.1', '< 6.1'

spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec-rails', '~> 3.7'
spec.add_development_dependency 'pg', '~> 1.2'
spec.add_development_dependency 'combustion', '~> 1.1'
spec.add_development_dependency 'database_cleaner', '~> 1.6'
spec.add_development_dependency 'pg', '~> 1.2'
spec.add_development_dependency 'pry', '~> 0.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec-rails', '~> 3.7'
spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
spec.add_development_dependency 'simplecov', '~> 0.16'
end
13 changes: 13 additions & 0 deletions spec/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require: rubocop-rspec

inherit_from:
- ../.rubocop.yml

Metrics/BlockLength:
Enabled: false

RSpec/LetSetup:
Enabled: false

RSpec/NestedGroups:
Max: 5
Loading

0 comments on commit c012f6f

Please sign in to comment.