activerecord-serialize_coders 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e42d022642d25045964eb0e98745017ec842a30
4
+ data.tar.gz: 694bbc473a2217791e82f93646ca67b7a5616654
5
+ SHA512:
6
+ metadata.gz: 8bcaba55de89b2cc3a1fe3b415efa11a0de35cf802c2d47e4ecbeb2d890143344ee1ab165eb94fcd9775b77f91a92d8ab8956f8b9f45137d7cb7e0dca0d24248
7
+ data.tar.gz: 8f4ff38452e2a8aba86695d91aa2921819f96851c0a1c0a9a4fdd268654cdabef9278a970ed7f1d66f0194a01ef5eda89b6a9cb52330b813df1fe93b40dad42c
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .versions.conf
@@ -0,0 +1,4 @@
1
+ ruby=ruby-2.0.0-p0
2
+ ruby-gemset=activerecord-serialize_coders
3
+ #ruby-gem-install=bundler rake
4
+ #ruby-bundle-install=true
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # source 'https://rubygems.org'
2
+ source 'http://ruby.taobao.org'
3
+
4
+ # Specify your gem's dependencies in activerecord-serialize_coders.gemspec
5
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 vkill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Activerecord::SerializeCoders
2
+
3
+ ActiveRecord serialize coders
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activerecord-serialize_coders'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activerecord-serialize_coders
18
+
19
+ ## Usage
20
+
21
+ your `app/models/user.rb`
22
+
23
+ serialize :module_ids, ::ActiveRecord::Coders::StringIdsColumn.new
24
+ # or
25
+ serialize :module_ids, ::ActiveRecord::Coders::StringIdsColumn.new(require_update: true)
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_record/serialize_coders/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord-serialize_coders"
8
+ spec.version = ActiveRecord::SerializeCoders::VERSION
9
+ spec.authors = ["vkill"]
10
+ spec.email = ["vkill.net@gmail.com"]
11
+ spec.description = %q{ActiveRecord serialize coders}
12
+ spec.summary = %q{ActiveRecord serialize coders}
13
+ spec.homepage = "https://github.com/vkill/activerecord-serialize_coders"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "activerecord", "> 3.1"
25
+ spec.add_dependency "activesupport"
26
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveRecord
2
+ module Coders
3
+ class JsonHashColumn
4
+
5
+ attr_accessor :require_update
6
+
7
+ def initialize(options = {})
8
+ @require_update = options.delete(:require_update){ false }
9
+ end
10
+
11
+ def dump(hash)
12
+ ::JSON.dump(hash || {})
13
+ end
14
+
15
+ def load(hash)
16
+ ::HashWithIndifferentAccess.new ::JSON.load(hash || "{}")
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveRecord
2
+ module Coders
3
+ class StringIdsColumn
4
+
5
+ attr_accessor :require_update
6
+
7
+ def initialize(options = {})
8
+ @require_update = options.delete(:require_update){ false }
9
+ end
10
+
11
+ def dump(ids)
12
+ Array(ids).delete_if{|x| x == ''}.join(',')
13
+ end
14
+
15
+ def load(ids)
16
+ ids.to_s.split(',').map(&:to_i)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ require "active_record/serialize_coders/version"
2
+
3
+ require "active_record/serialize_coders/railtie" if defined?(::Rails)
4
+
5
+ module ActiveRecord
6
+ module SerializeCoders
7
+ end
8
+ end
@@ -0,0 +1,50 @@
1
+ module ActiveRecord
2
+ module SerializeCoders
3
+ module DirtyExtension
4
+
5
+ extend ::ActiveSupport::Concern
6
+
7
+ included do
8
+ if ::Rails.version > '4'
9
+ include Rail4InstanceMethods
10
+ alias_method_chain :keys_for_partial_write, :specify_serialize
11
+ else
12
+ include Rail3InstanceMethods
13
+ end
14
+ end
15
+
16
+ module Rail4InstanceMethods
17
+
18
+ private
19
+
20
+ def keys_for_partial_write_with_specify_serialize
21
+ _keys_for_partial_write
22
+ end
23
+ end
24
+
25
+ module Rail3InstanceMethods
26
+
27
+ private
28
+
29
+ def update(*)
30
+ if partial_updates?
31
+ super(_keys_for_partial_write)
32
+ else
33
+ super
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def _keys_for_partial_write
41
+ require_update_serialized_attributes = self.class.serialized_attributes.select do |key, coder|
42
+ coder.respond_to?(:require_update) and coder.require_update
43
+ end
44
+
45
+ changed | (attributes.keys & require_update_serialized_attributes.keys)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require "active_record/serialize_coders/dirty_extension"
2
+
3
+ module ActiveRecord
4
+ module SerializeCoders
5
+ class Railtie < ::Rails::Railtie
6
+
7
+ initializer 'active_record-serialize_coders' do |app|
8
+ ActiveSupport.on_load :active_record do
9
+ include ::ActiveRecord::SerializeCoders::DirtyExtension
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module SerializeCoders
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_record'
2
+ require 'active_support/hash_with_indifferent_access'
3
+ require 'active_support/concern'
4
+
5
+ require 'json'
6
+
7
+ require "active_record/serialize_coders"
8
+
9
+ require "active_record/coders/json_hash_column"
10
+ require "active_record/coders/string_ids_column"
11
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-serialize_coders
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - vkill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>'
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>'
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ActiveRecord serialize coders
70
+ email:
71
+ - vkill.net@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .versions.conf.sample
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - activerecord-serialize_coders.gemspec
83
+ - lib/active_record/coders/json_hash_column.rb
84
+ - lib/active_record/coders/string_ids_column.rb
85
+ - lib/active_record/serialize_coders.rb
86
+ - lib/active_record/serialize_coders/dirty_extension.rb
87
+ - lib/active_record/serialize_coders/railtie.rb
88
+ - lib/active_record/serialize_coders/version.rb
89
+ - lib/activerecord-serialize_coders.rb
90
+ homepage: https://github.com/vkill/activerecord-serialize_coders
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: ActiveRecord serialize coders
114
+ test_files: []