Skip to content

Commit

Permalink
Merge e8e8247 into 53958f4
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel committed Oct 29, 2018
2 parents 53958f4 + e8e8247 commit dff2e48
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 73 deletions.
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inherit_gem:
salsify_rubocop: conf/rubocop.yml

AllCops:
TargetRubyVersion: 2.3

Style/FrozenStringLiteralComment:
Enabled: true
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ matrix:
gemfile: gemfiles/rails_5.2.gemfile
- rvm: jruby-9.1.16.0
gemfile: gemfiles/rails_5.2.gemfile
script:
- bundle exec rake
- bundle exec rubocop
2 changes: 2 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

appraise 'rails-4.2' do
gem 'activerecord', '4.2.10'
gem 'activesupport', '4.2.10'
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

### 3.0.0
- Drop support for Ruby <= 2.2
* Drop support for Ruby <= 2.2.
* Use frozen string literals.

### 2.1.2
* Fix [issue 61](https://github.com/salsify/goldiloader/issues/61) - don't eager load has_one associations with an order.
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/setup'
Bundler::GemHelper.install_tasks

Expand Down
13 changes: 7 additions & 6 deletions goldiloader.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'goldiloader/version'
Expand All @@ -15,11 +16,11 @@ Gem::Specification.new do |spec|
'homepage_uri' => 'https://github.com/salsify/goldiloader',
'changelog_uri' => 'https://github.com/salsify/goldiloader/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/salsify/goldiloader/',
'bug_tracker_uri' => 'https://github.com/salsify/goldiloader/issues',
'bug_tracker_uri' => 'https://github.com/salsify/goldiloader/issues'
}
spec.license = 'MIT'

spec.files = `git ls-files lib Readme.md LICENSE.txt`.split($/)
spec.files = `git ls-files lib Readme.md LICENSE.txt`.split($INPUT_RECORD_SEPARATOR)

spec.required_ruby_version = '>= 2.3'

Expand All @@ -29,16 +30,16 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'database_cleaner', '>= 1.2'
spec.add_development_dependency 'mime-types'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 3'
spec.add_development_dependency 'salsify_rubocop', '0.52.1.1'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'mime-types'

if RUBY_PLATFORM == 'java'
spec.add_development_dependency 'jdbc-sqlite3'
spec.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
spec.add_development_dependency 'jdbc-sqlite3'
else
spec.add_development_dependency 'sqlite3'
end
end

2 changes: 1 addition & 1 deletion lib/goldiloader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

require 'active_support/all'
require 'active_record'
Expand Down
2 changes: 1 addition & 1 deletion lib/goldiloader/active_record_patches.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
module BasePatch
Expand Down
4 changes: 2 additions & 2 deletions lib/goldiloader/association_info.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
class AssociationInfo
Expand All @@ -9,7 +9,7 @@ def initialize(association)

delegate :association_scope, :reflection, to: :@association

def has_one?
def has_one? # rubocop:disable Naming/PredicateName
reflection.has_one?
end

Expand Down
4 changes: 2 additions & 2 deletions lib/goldiloader/association_loader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
module AssociationLoader
Expand Down Expand Up @@ -35,7 +35,7 @@ def load?(model, association_name)
model.association(association_name).auto_include?
end

def has_association?(model, association_name)
def has_association?(model, association_name) # rubocop:disable Naming/PredicateName
model.class.reflect_on_association(association_name).present?
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/goldiloader/association_options.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
module AssociationOptions
Expand All @@ -24,8 +24,6 @@ def register
ActiveRecord::Associations::Builder::Association.valid_options.concat(OPTIONS)
end
end

private
end
end

Expand Down
16 changes: 11 additions & 5 deletions lib/goldiloader/auto_include_context.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
class AutoIncludeContext
Expand All @@ -13,10 +13,16 @@ def self.register_models(models, included_associations = nil)
auto_include_context.register_models(models)

Array.wrap(included_associations).each do |included_association|
associations = included_association.is_a?(Hash) ?
included_association.keys : Array.wrap(included_association)
nested_associations = included_association.is_a?(Hash) ?
included_association : Hash.new([])
associations = if included_association.is_a?(Hash)
included_association.keys
else
Array.wrap(included_association)
end
nested_associations = if included_association.is_a?(Hash)
included_association
else
Hash.new([])
end

associations.each do |association|
nested_models = models.flat_map do |model|
Expand Down
2 changes: 1 addition & 1 deletion lib/goldiloader/compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
module Compatibility
Expand Down
4 changes: 2 additions & 2 deletions lib/goldiloader/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
# frozen_string_literal: true

module Goldiloader
VERSION = '3.0.0'.freeze
VERSION = '3.0.0'
end
6 changes: 3 additions & 3 deletions spec/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: UTF-8
# frozen_string_literal: true

ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(version: 0) do

create_table(:blogs, force: true) do |t|
t.string :name
Expand Down Expand Up @@ -117,7 +117,7 @@ class Address < ActiveRecord::Base

class ScopedAddress < ActiveRecord::Base
self.table_name = 'addresses'
default_scope { where(city: ['Philadelphia'])}
default_scope { where(city: ['Philadelphia']) }
belongs_to :user
end

Expand Down
14 changes: 8 additions & 6 deletions spec/goldiloader/auto_include_context_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'ostruct'

Expand Down Expand Up @@ -117,16 +119,16 @@
context "when nested associations are nil" do
let!(:roots) do
[
create_mock_model(car: cars.first),
create_mock_model(car: nil),
create_mock_model(car: cars.last)
create_mock_model(car: cars.first),
create_mock_model(car: nil),
create_mock_model(car: cars.last)
]
end

let!(:cars) do
[
create_mock_model,
create_mock_model
create_mock_model,
create_mock_model
]
end

Expand All @@ -146,7 +148,7 @@
end

def create_mock_models(num)
num.times.map { create_mock_model }
Array.new(num) { create_mock_model }
end

def create_mock_model(associations = {})
Expand Down

0 comments on commit dff2e48

Please sign in to comment.