Skip to content

Commit

Permalink
Merge pull request #4 from DmitryTsepelev/0.2.1
Browse files Browse the repository at this point in the history
0.2.1
  • Loading branch information
DmitryTsepelev committed Nov 9, 2018
2 parents da883c1 + 64931e5 commit 804a951
Show file tree
Hide file tree
Showing 27 changed files with 118 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ spec/dummy/yarn-error.log
spec/dummy/storage/
spec/dummy/tmp/
coverage/
Gemfile.lock
162 changes: 0 additions & 162 deletions Gemfile.lock

This file was deleted.

17 changes: 1 addition & 16 deletions lib/ar_lazy_preload.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
# frozen_string_literal: true

require "ar_lazy_preload/configuration"
require "ar_lazy_preload/ext/base"
require "ar_lazy_preload/ext/relation"
require "ar_lazy_preload/ext/association"
require "ar_lazy_preload/ext/merger"
require "ar_lazy_preload/ext/association_relation"
require "ar_lazy_preload/railtie"

module ArLazyPreload
class << self
def config
@config ||= Configuration.new
end
end

ActiveRecord::Base.include(ArLazyPreload::Base)

ActiveRecord::Relation.prepend(ArLazyPreload::Relation)
ActiveRecord::AssociationRelation.prepend(ArLazyPreload::AssociationRelation)
ActiveRecord::Relation::Merger.prepend(ArLazyPreload::Merger)

[
ActiveRecord::Associations::CollectionAssociation,
ActiveRecord::Associations::Association
].each { |klass| klass.prepend(ArLazyPreload::Association) }
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def lazy_preload(*args)
end

def lazy_preload!(*args)
args.reject!(&:blank?)
args.flatten!
self.lazy_preload_values += args
self
Expand Down
26 changes: 26 additions & 0 deletions lib/ar_lazy_preload/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "ar_lazy_preload/active_record/base"
require "ar_lazy_preload/active_record/relation"
require "ar_lazy_preload/active_record/association"
require "ar_lazy_preload/active_record/merger"
require "ar_lazy_preload/active_record/association_relation"

module ArLazyPreload
class Railtie < Rails::Railtie
config.to_prepare do |_app|
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.include(Base)

ActiveRecord::Relation.prepend(Relation)
ActiveRecord::AssociationRelation.prepend(AssociationRelation)
ActiveRecord::Relation::Merger.prepend(Merger)

[
ActiveRecord::Associations::CollectionAssociation,
ActiveRecord::Associations::Association
].each { |klass| klass.prepend(Association) }
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ar_lazy_preload/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ArLazyPreload
VERSION = "0.2.0"
VERSION = "0.2.1"
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added spec/dummy/config.ru
Empty file.
16 changes: 16 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require File.expand_path("boot", __dir__)

require "rails"
require "action_controller/railtie"
require "ar_lazy_preload/railtie"

Bundler.require(*Rails.groups)

module Dummy
class Application < Rails::Application
config.logger = Logger.new("/dev/null")
config.eager_load = false
end
end
7 changes: 7 additions & 0 deletions spec/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)

require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
25 changes: 25 additions & 0 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000

development:
<<: *default
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
database: db/production.sqlite3
7 changes: 7 additions & 0 deletions spec/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Load the Rails application.
require File.expand_path("application", __dir__)

# Initialize the Rails application.
Dummy::Application.initialize!
4 changes: 4 additions & 0 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

Dummy::Application.configure do
end
4 changes: 4 additions & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

Dummy::Application.routes.draw do
end
22 changes: 22 additions & 0 deletions spec/dummy/config/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
secret_key_base: a6a03acbab7b7658ca0b82967eabfc3f2954a81db06614bbbd7ecbf5a8ef27d2bbda85fc87d71b0475c5d711d6b096fa3f0d9dfbe44bb671841c4e1396b8a9e5

test:
secret_key_base: b6d9c9ed45db8aa6336d82dd12332915592299b519f8a4f34045352a9e908409fe057335ee8400df2298ad0ee4e304e7630f52d391bad8b89449bfad62010930

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# frozen_string_literal: true

ENV["RAILS_ENV"] = "test"

require "coveralls"
Coveralls.wear!

require_relative "dummy/config/environment"

require "active_record"
require "db_query_matchers"
require "database_cleaner"
Expand Down

0 comments on commit 804a951

Please sign in to comment.