records_manipulator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 852f749ba32320ebffec020e8c19ace52f575e3c
4
+ data.tar.gz: 688a8adda340215f445593689f6923c4e8b5ad5d
5
+ SHA512:
6
+ metadata.gz: e8568b94e2379d296c58b731e371356215c0e8e45f53423c4008c9ce7afa2ab6a12c1c70c09cc9049fe86a214da6fd79193c3088bdb60e5de0dca11220cf5b0e
7
+ data.tar.gz: b5ccd8952e5b173cd0dee9627ab550a9a1dadf0da8c55c1b7328e2b9d436413a968188564cb5f65979d313f8b60cc5a1a4b5a9ab734dac40be7515244f362d0c
@@ -0,0 +1,15 @@
1
+ module RecordsManipulator
2
+ module BaseExtension
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def manipulate(&block)
10
+ relation.manipulate(&block)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module RecordsManipulator
2
+ class Railtie < Rails::Railtie #:nodoc:
3
+
4
+ initializer 'records_manipulator.initialize' do |app|
5
+ ActiveSupport.on_load(:active_record) do
6
+ require 'records_manipulator/relation_extension'
7
+ ::ActiveRecord::Relation.send :include, RecordsManipulator::RelationExtension
8
+
9
+ require 'records_manipulator/base_extension'
10
+ ::ActiveRecord::Base.send :include, RecordsManipulator::BaseExtension
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ module RecordsManipulator
2
+ module RelationExtension
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ alias_method :exec_queries_without_manipulator, :exec_queries
7
+ alias_method :exec_queries, :exec_queries_with_manipulator
8
+ private :exec_queries_with_manipulator
9
+ private :exec_queries_without_manipulator
10
+ end
11
+ end
12
+
13
+ def manipulate(&block)
14
+ @manipulators ||= []
15
+ @manipulators << block
16
+ self
17
+ end
18
+
19
+ def exec_queries_with_manipulator(&block)
20
+ @records = exec_queries_without_manipulator(&block)
21
+ if @manipulators
22
+ @manipulators.each do |m|
23
+ m.call(@records)
24
+ end
25
+ end
26
+ @records
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ require 'records_manipulator/railtie' if defined?(Rails)
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: records_manipulator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Add manipulations to an Active Record scope to change the records when
14
+ they are finally returned from the database
15
+ email:
16
+ - me@adamcooke.io
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/records_manipulator.rb
22
+ - lib/records_manipulator/base_extension.rb
23
+ - lib/records_manipulator/railtie.rb
24
+ - lib/records_manipulator/relation_extension.rb
25
+ homepage: https://github.com/adamcooke/records-manipulator
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.5.1
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Add manipulations to an Active Record scope to change the records when they
49
+ are finally returned from the database
50
+ test_files: []