activerecord-postgres-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
+ SHA1:
3
+ metadata.gz: 2fa2ff434f05486be6458bac2bf2eb94f389acba
4
+ data.tar.gz: 27b6a6c6c5abd025e246973aa221ace946442e27
5
+ SHA512:
6
+ metadata.gz: 8427901febe5ad97f87b4b3ffc7320d8634242907f8c347a99fc7d2b357971bcf6f76c6b1ea41fe35d4253c1f4b56a1a1481c19e3368bdcd226cbca1825dbfd4
7
+ data.tar.gz: b8cd3670f4761e7d8bdef9fd70f654732fac829fb8046b85f941eb33e0148205043c738877d1f415ad83f0b8bc6fd281edf64136e6da59fa74ad3219c1759c00
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '>= 3.2', '< 4'
4
+ gem 'multi_json'
5
+ gem 'hashie'
6
+
7
+ group :development do
8
+ gem 'rspec'
9
+ gem 'rdoc'
10
+ gem 'bundler'
11
+ gem 'jeweler'
12
+ end
@@ -0,0 +1,81 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.18)
5
+ activesupport (= 3.2.18)
6
+ builder (~> 3.0.0)
7
+ activerecord (3.2.18)
8
+ activemodel (= 3.2.18)
9
+ activesupport (= 3.2.18)
10
+ arel (~> 3.0.2)
11
+ tzinfo (~> 0.3.29)
12
+ activesupport (3.2.18)
13
+ i18n (~> 0.6, >= 0.6.4)
14
+ multi_json (~> 1.0)
15
+ addressable (2.3.6)
16
+ arel (3.0.3)
17
+ builder (3.0.4)
18
+ descendants_tracker (0.0.4)
19
+ thread_safe (~> 0.3, >= 0.3.1)
20
+ diff-lcs (1.2.5)
21
+ faraday (0.9.0)
22
+ multipart-post (>= 1.2, < 3)
23
+ git (1.2.6)
24
+ github_api (0.11.3)
25
+ addressable (~> 2.3)
26
+ descendants_tracker (~> 0.0.1)
27
+ faraday (~> 0.8, < 0.10)
28
+ hashie (>= 1.2)
29
+ multi_json (>= 1.7.5, < 2.0)
30
+ nokogiri (~> 1.6.0)
31
+ oauth2
32
+ hashie (2.1.1)
33
+ highline (1.6.21)
34
+ i18n (0.6.9)
35
+ jeweler (2.0.1)
36
+ builder
37
+ bundler (>= 1.0)
38
+ git (>= 1.2.5)
39
+ github_api
40
+ highline (>= 1.6.15)
41
+ nokogiri (>= 1.5.10)
42
+ rake
43
+ rdoc
44
+ jwt (1.0.0)
45
+ mini_portile (0.6.0)
46
+ multi_json (1.10.1)
47
+ multi_xml (0.5.5)
48
+ multipart-post (2.0.0)
49
+ nokogiri (1.6.2.1)
50
+ mini_portile (= 0.6.0)
51
+ oauth2 (0.9.4)
52
+ faraday (>= 0.8, < 0.10)
53
+ jwt (~> 1.0)
54
+ multi_json (~> 1.3)
55
+ multi_xml (~> 0.5)
56
+ rack (~> 1.2)
57
+ rack (1.5.2)
58
+ rake (10.3.2)
59
+ rdoc (4.1.0)
60
+ rspec (2.14.1)
61
+ rspec-core (~> 2.14.0)
62
+ rspec-expectations (~> 2.14.0)
63
+ rspec-mocks (~> 2.14.0)
64
+ rspec-core (2.14.8)
65
+ rspec-expectations (2.14.5)
66
+ diff-lcs (>= 1.1.3, < 2.0)
67
+ rspec-mocks (2.14.6)
68
+ thread_safe (0.3.4)
69
+ tzinfo (0.3.39)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ activerecord (>= 3.2, < 4)
76
+ bundler
77
+ hashie
78
+ jeweler
79
+ multi_json
80
+ rdoc
81
+ rspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Roman Shterenzon
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,34 @@
1
+ # activerecord-postgres-json
2
+
3
+ A minimal JSON column type support for ActiveRecord 3.2.x
4
+ This gem adds the following support:
5
+
6
+ 1. Using json column type in migrations, e.g. `add_column :foo, :bar, :json`
7
+ 2. json field support in the schema definitions
8
+ 3. JSON coder for using with the `serialize` class method:
9
+
10
+ ```ruby
11
+ class User < ActiveRecord::Base
12
+ serialize :settings, ActiveRecord::Coders::JSON
13
+ end
14
+
15
+ User.first.settings.class # => Hashie::Mash
16
+ User.first.settings.show_popups # => true
17
+ ...
18
+ ```
19
+
20
+ ## Contributing to activerecord-postgres-json
21
+
22
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
23
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
24
+ * Fork the project.
25
+ * Start a feature/bugfix branch.
26
+ * Commit and push until you are happy with your contribution.
27
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
28
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
29
+
30
+ ## Copyright
31
+
32
+ Copyright (c) 2014 Roman Shterenzon. See LICENSE.txt for
33
+ further details.
34
+
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "activerecord-postgres-json"
18
+ gem.homepage = "http://github.com/romanbsd/activerecord-postgres-json"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Active Record support for PostgreSQL JSON type}
21
+ gem.description = gem.summary
22
+ gem.email = "romanbsd@yahoo.com"
23
+ gem.authors = ["Roman Shterenzon"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "activerecord-postgres-json #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: activerecord-postgres-json 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "activerecord-postgres-json"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Roman Shterenzon"]
14
+ s.date = "2014-06-02"
15
+ s.description = "Active Record support for PostgreSQL JSON type"
16
+ s.email = "romanbsd@yahoo.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "activerecord-postgres-json.gemspec",
31
+ "lib/activerecord-postgres-json.rb",
32
+ "lib/activerecord-postgres-json/activerecord.rb",
33
+ "lib/activerecord-postgres-json/coders.rb",
34
+ "spec/activerecord-postgres-json_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = "http://github.com/romanbsd/activerecord-postgres-json"
38
+ s.licenses = ["MIT"]
39
+ s.rubygems_version = "2.2.2"
40
+ s.summary = "Active Record support for PostgreSQL JSON type"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 4
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<activerecord>, ["< 4", ">= 3.2"])
47
+ s.add_runtime_dependency(%q<multi_json>, [">= 0"])
48
+ s.add_runtime_dependency(%q<hashie>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, [">= 0"])
50
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, [">= 0"])
52
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<activerecord>, ["< 4", ">= 3.2"])
55
+ s.add_dependency(%q<multi_json>, [">= 0"])
56
+ s.add_dependency(%q<hashie>, [">= 0"])
57
+ s.add_dependency(%q<rspec>, [">= 0"])
58
+ s.add_dependency(%q<rdoc>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, [">= 0"])
60
+ s.add_dependency(%q<jeweler>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<activerecord>, ["< 4", ">= 3.2"])
64
+ s.add_dependency(%q<multi_json>, [">= 0"])
65
+ s.add_dependency(%q<hashie>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, [">= 0"])
67
+ s.add_dependency(%q<rdoc>, [">= 0"])
68
+ s.add_dependency(%q<bundler>, [">= 0"])
69
+ s.add_dependency(%q<jeweler>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,2 @@
1
+ require 'activerecord-postgres-json/activerecord'
2
+ require 'activerecord-postgres-json/coders'
@@ -0,0 +1,50 @@
1
+ require 'active_record'
2
+ require 'active_record/connection_adapters/postgresql_adapter'
3
+
4
+ module ActiveRecord
5
+
6
+ module ConnectionAdapters
7
+ PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:json] = {name: 'json'}
8
+
9
+ class PostgreSQLColumn < Column
10
+ # Adds the json type for the column.
11
+ def simplified_type_with_json(field_type)
12
+ field_type == 'json' ? :json : simplified_type_without_json(field_type)
13
+ end
14
+
15
+ alias_method_chain :simplified_type, :json
16
+ end
17
+ end
18
+
19
+ class TableDefinition
20
+
21
+ # Adds json type for migrations. So you can add columns to a table like:
22
+ # create_table :people do |t|
23
+ # ...
24
+ # t.json :info
25
+ # ...
26
+ # end
27
+ def json(*args)
28
+ options = args.extract_options!
29
+ column_names = args
30
+ column_names.each { |name| column(name, 'json', options) }
31
+ end
32
+
33
+ end
34
+
35
+ class Table
36
+
37
+ # Adds json type for migrations. So you can add columns to a table like:
38
+ # change_table :people do |t|
39
+ # ...
40
+ # t.json :info
41
+ # ...
42
+ # end
43
+ def json(*args)
44
+ options = args.extract_options!
45
+ column_names = args
46
+ column_names.each { |name| column(name, 'json', options) }
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,38 @@
1
+ require 'multi_json'
2
+ require 'hashie'
3
+
4
+ module ActiveRecord
5
+ module Coders
6
+ class JSON
7
+ def self.load(json)
8
+ new.load(json)
9
+ end
10
+
11
+ def self.dump(json)
12
+ new.dump(json)
13
+ end
14
+
15
+ def initialize(default = Hashie::Mash.new)
16
+ @default = default
17
+ end
18
+
19
+ def dump(obj)
20
+ obj.nil? ? (@default.nil? ? nil : to_json(@default)) : to_json(obj)
21
+ end
22
+
23
+ def load(json)
24
+ json.nil? ? @default : from_json(json)
25
+ end
26
+
27
+ private
28
+ def to_json(obj)
29
+ MultiJson.dump(obj)
30
+ end
31
+
32
+ # FIXME: support arrays
33
+ def from_json(json)
34
+ Hashie::Mash.new MultiJson.load(json)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ActiverecordPostgresJson" do
4
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'activerecord-postgres-json'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-postgres-json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman Shterenzon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '3.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "<"
28
+ - !ruby/object:Gem::Version
29
+ version: '4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: multi_json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: hashie
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rdoc
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: bundler
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: jeweler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Active Record support for PostgreSQL JSON type
118
+ email: romanbsd@yahoo.com
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files:
122
+ - LICENSE.txt
123
+ - README.md
124
+ files:
125
+ - ".document"
126
+ - ".rspec"
127
+ - Gemfile
128
+ - Gemfile.lock
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - VERSION
133
+ - activerecord-postgres-json.gemspec
134
+ - lib/activerecord-postgres-json.rb
135
+ - lib/activerecord-postgres-json/activerecord.rb
136
+ - lib/activerecord-postgres-json/coders.rb
137
+ - spec/activerecord-postgres-json_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: http://github.com/romanbsd/activerecord-postgres-json
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Active Record support for PostgreSQL JSON type
163
+ test_files: []