activerecord_accessible_json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c064223ceb5c41e1924db60c3981a5f22d6e676765b110544388d9c34f53f8b5
4
+ data.tar.gz: dc0a99793bb179a402bec46e1786b661aa5c0f9ddb338d996f2521b6be2e3a7f
5
+ SHA512:
6
+ metadata.gz: 1743a7db330a5f6f43c1ad4c1c363b8a9fe45c1b67e5f839d8bfc419ca5c575a13ee7afe5eda80617c0e37adbdd43f7f714404a7ef10239e4cc5ff7f762f4644
7
+ data.tar.gz: e3a4c64f2a072f72785ecceeeec0555d7496e241314b49200e7be0d58dcccdc1f5dd2a2e0e4a26186cf58c6eed7ff7d3a80156cca9d6ea5958c0a076bff566c7
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Yamaguchi Takuya
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # ActiveRecord Accessible Json
2
+
3
+ Using this gem, ActiveRecord JSON typed attribute is deserialized into HashWithIndifferentAccess if possible.
4
+
5
+ ## Example
6
+
7
+ ```ruby
8
+ # Both author and tags are JSON typed columns.
9
+ Post.create(author: { 'name': 'yamat47', 'age': 27 }, tags: %w[Rails TDD])
10
+
11
+ post = Post.last
12
+ post.author.class #=> ActiveSupport::HashWithIndifferentAccess
13
+ post.author['name'] #=> 'yamat47'
14
+ post.author['name'] == post.author[:name] #=> true
15
+
16
+ post.author = { name: 'Andy', age: 30 }
17
+ post.author.class #=> ActiveSupport::HashWithIndifferentAccess
18
+ post.author['name'] #=> 'Andy'
19
+ post.author['name'] == post.author[:name] #=> true
20
+
21
+ # If attribute's value is not changeable into HashWithIndifferentAccess,
22
+ # this gem does nothing.
23
+ post.tags.class #=> Array
24
+ ```
25
+
26
+ ## Installation
27
+
28
+ Add this line to your Rails application's Gemfile:
29
+
30
+ ```ruby
31
+ gem 'activerecord_accessible_json'
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ ```bash
37
+ $ bundle
38
+ ```
39
+
40
+ Or install it yourself as:
41
+
42
+ ```bash
43
+ $ gem install activerecord_accessible_json
44
+ ```
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "activerecord_accessible_json/version"
2
+ require "activerecord_accessible_json/railtie"
3
+
4
+ module ActiverecordAccessibleJson
5
+ end
@@ -0,0 +1,13 @@
1
+ module ActiverecordAccessibleJson
2
+ module JsonExtension
3
+ # This patch is strongly dependent with ActiveRecord::Type::Json implementation.
4
+ # https://github.com/rails/rails/blob/8b3fc5ce30629cb098e923396c3eb797365c88d2/activerecord/lib/active_record/type/json.rb#L12
5
+ def deserialize(value)
6
+ return value unless value.is_a?(::String)
7
+ decoded_value = ActiveSupport::JSON.decode(value)
8
+ decoded_value.respond_to?(:with_indifferent_access) ? decoded_value.with_indifferent_access : decoded_value
9
+ rescue
10
+ nil
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require "activerecord_accessible_json/json_extension"
2
+
3
+ module ActiverecordAccessibleJson
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'activerecord_accessible_json' do |app|
6
+ ActiveSupport.on_load(:active_record) do
7
+ ActiveRecord::Type::Json.prepend ActiverecordAccessibleJson::JsonExtension
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ActiverecordAccessibleJson
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :activerecord_accessible_json do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_accessible_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yamaguchi Takuya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Using this gem, ActiveRecord's JSON attribute is deserialized into not
56
+ Hash but HashWithIndifferentAccess.
57
+ email:
58
+ - yamat47.thirddown@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/activerecord_accessible_json.rb
67
+ - lib/activerecord_accessible_json/json_extension.rb
68
+ - lib/activerecord_accessible_json/railtie.rb
69
+ - lib/activerecord_accessible_json/version.rb
70
+ - lib/tasks/activerecord_accessible_json_tasks.rake
71
+ homepage: https://github.com/yamat47/activerecord_accessible_json
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://github.com/yamat47/activerecord_accessible_json
76
+ source_code_uri: https://github.com/yamat47/activerecord_accessible_json
77
+ changelog_uri: https://github.com/yamat47/activerecord_accessible_json/blob/main/CHANGELOG.md
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.2.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Make ActiveRecord's JSON attribute more accessible.
97
+ test_files: []