activerecord-attribute_converter 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a1107bf795acf0d0ddd42afc3cd1512760445c4
4
- data.tar.gz: f38eae4f2d62f732acddde5b5e096caf6228cda8
3
+ metadata.gz: f5ac88613a83588985a6f7b7729ba74958bd5a53
4
+ data.tar.gz: c9d1fb6f43d5c45aeec99088a0c6d6f6252fc057
5
5
  SHA512:
6
- metadata.gz: 44ae86c61702a4c4ca8204b56ccb07417943d1a645d1a3b263d7a3bc2cc48872a9b9e17d982d15a72785a7320d08e0dfadd591310df4abf5f6b58c822fd690a0
7
- data.tar.gz: 413bc326e4a9eca90aa7dbd66be9d447deb6f967be959d2db40d5151ba77e5f0078bb585cbc62b18fc36de366587009e33233eaf1e87a5d8a1534cd9af50b076
6
+ metadata.gz: 0302cc8783014305e5de3597c455ce5d72b44fe81cc760eff5ab649c18cd135ae8594f1780bfaef8bf46ac3a5c37bc2063c3f6ba1d174578e815d6e228d37e2c
7
+ data.tar.gz: 7aec1c0d8d9b5067dc709180360d9d9ef5dfbe5fc043f73c13c3a6743da3e7a23e52ea8b186f70c9d24e268e75f9707a17ecf70a52d7262dae82e57a011733d9
@@ -1,8 +1,22 @@
1
1
  require 'active_support/lazy_load_hooks'
2
+ require 'activerecord/attribute_converter/base'
3
+ require 'activerecord/attribute_converter/predicate_builder'
4
+ require 'activerecord/attribute_converter/relation'
2
5
  require 'activerecord/attribute_converter/version'
3
6
 
4
7
  ActiveSupport.on_load(:active_record) do
5
- require 'activerecord/attribute_converter/base'
6
- require 'activerecord/attribute_converter/relation'
7
- require 'activerecord/attribute_converter/predicate_builder'
8
+ ActiveRecord::Base.send(:include, ActiveRecord::AttributeConverter::Base)
9
+
10
+ ActiveRecord::PredicateBuilder.singleton_class.class_eval do
11
+ include ActiveRecord::AttributeConverter::PredicateBuilder
12
+ alias_method_chain :build_from_hash, :attribute_converter
13
+ end
14
+
15
+ ActiveRecord::Relation.class_eval do
16
+ # Use alias_method_chain instead of Module#prepend here.
17
+ # In Rails 4, activerecord-deprecated_finders monkey-patches update_all and
18
+ # the combination of alias_method_chain and prepend causes some trouble.
19
+ include ActiveRecord::AttributeConverter::Relation
20
+ alias_method_chain :update_all, :attribute_converter
21
+ end
8
22
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/concern'
2
+
1
3
  module ActiveRecord
2
4
  module AttributeConverter
3
5
  module Base
@@ -44,5 +46,3 @@ module ActiveRecord
44
46
  end
45
47
  end
46
48
  end
47
-
48
- ActiveRecord::Base.send(:include, ActiveRecord::AttributeConverter::Base)
@@ -1,6 +1,9 @@
1
1
  module ActiveRecord
2
2
  module AttributeConverter
3
3
  module PredicateBuilder
4
+ # Rails 3.2: build_from_hash(engine, attributes, default_table, allow_table_name = true)
5
+ # Rails 4.0: build_from_hash(klass, attributes, default_table)
6
+ # Rails 4.1: build_from_hash(klass, attributes, default_table)
4
7
  def build_from_hash_with_attribute_converter(*args)
5
8
  klass = args[0]
6
9
  unless klass.attribute_converters.empty?
@@ -19,8 +22,3 @@ module ActiveRecord
19
22
  end
20
23
  end
21
24
  end
22
-
23
- ActiveRecord::PredicateBuilder.singleton_class.class_eval do
24
- include ActiveRecord::AttributeConverter::PredicateBuilder
25
- alias_method_chain :build_from_hash, :attribute_converter
26
- end
@@ -1,12 +1,18 @@
1
1
  module ActiveRecord
2
2
  module AttributeConverter
3
3
  module Relation
4
+ # Rails 3.2: update_all(updates, conditions = nil, options = {})
5
+ # Rails 4.0: update_all(updates)
6
+ # Rails 4.1: update_all(updates)
4
7
  def update_all_with_attribute_converter(*args)
5
8
  updates = args[0]
6
9
  conditions = args[1]
7
10
  options = args[2] || {}
8
11
 
9
12
  if !conditions && !options.present? && !@klass.attribute_converters.empty? && updates.is_a?(Hash)
13
+ # Only `update_all(attr: value)` form is supported.
14
+ # `update_all(['attr = ?', value])` and `update_all("attr = #{value}")`
15
+ # form is NOT supported because we cannot convert values safely.
10
16
  updates = updates.stringify_keys
11
17
  @klass.attribute_converters.each do |attr, converter|
12
18
  if updates.has_key?(attr)
@@ -21,8 +27,3 @@ module ActiveRecord
21
27
  end
22
28
  end
23
29
  end
24
-
25
- ActiveRecord::Relation.class_eval do
26
- include ActiveRecord::AttributeConverter::Relation
27
- alias_method_chain :update_all, :attribute_converter
28
- end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module AttributeConverter
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ ActiveRecord::Base.configurations['test'] = {
5
5
  adapter: 'sqlite3',
6
6
  database: ':memory:',
7
7
  }
8
- ActiveRecord::Base.establish_connection('test')
8
+ ActiveRecord::Base.establish_connection(:test)
9
9
  require File.expand_path('../schema', __FILE__)
10
10
  require File.expand_path('../models', __FILE__)
11
11
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-attribute_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0.beta1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.0.0.beta1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: appraisal
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.0.0.beta1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.0.0.beta1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Transparent conversion for ActiveRecord
@@ -101,9 +101,9 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - ".gitignore"
105
- - ".rspec"
106
- - ".travis.yml"
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
107
  - Appraisals
108
108
  - CHANGELOG.md
109
109
  - Gemfile
@@ -133,17 +133,17 @@ require_paths:
133
133
  - lib
134
134
  required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - ">="
141
+ - - '>='
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.2.2
146
+ rubygems_version: 2.0.14
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Transparent conversion for ActiveRecord