json_on_rails 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 5db307bd4a873cd54147b848fc87b9387798d25e4fccf640b49918904b16df98
4
- data.tar.gz: 71fd629916b708395777a9c6c01d45dc31a4df3b0f48f27f802cbccd89dc12b2
3
+ metadata.gz: 6d5cd9da9b9e15cf64d420716d697b9fdc34763d1dc4b2c5fa350bf3afdf3d6e
4
+ data.tar.gz: 7d9e7647696a997b94f8ed3a916cd8817e070f4d4b13dc033a23757964db1b3c
5
5
  SHA512:
6
- metadata.gz: 75d24791daac826a553609b6780c7d10cf8b860b141e8e7dccabbbf226ea4ae7f9f614259037a554131c6451c876bbcab16888f2cb875b18cab2d30a46c5c75e
7
- data.tar.gz: a2f5415d988fa361bd10b41a2cd3e8d8d08979d955cce52324bf0feb118e52ecf9ad76238780e95b46f57b7d565631a70b73e542baaabdcfb758daddc8599990
6
+ metadata.gz: f6fdb0645ce6d729560a9ebd71f7b87c48d4e732b723effb291ce59a3cf3714d32c21334086ca847d54187938249769d87ad0321fe698e477816d8c063cc47da
7
+ data.tar.gz: 93ca5c57db905354fcb8bfd6ea4b7f3dcdc85653193f28a80144c0b1edaca936426dd23b61c350bb610d7c4b031b03850a03f9de2fb2149afee73971892b844f
data/README.md CHANGED
@@ -18,10 +18,10 @@ The inner working is simple, and uses the standard Rails (internal) APIs; this i
18
18
  Add the gem to the Gemfile of your rails project:
19
19
 
20
20
  ```ruby
21
- gem "json_on_rails", "~> 0.1.0"
21
+ gem "json_on_rails", "~> 0.1.2"
22
22
  ```
23
23
 
24
- and update the Gemfile.lock:
24
+ and update the environment:
25
25
 
26
26
  ```sh
27
27
  $ bundle install
@@ -35,10 +35,10 @@ Create a table:
35
35
 
36
36
  ```
37
37
  class CreateUsers < ActiveRecord::Migration
38
- def up
38
+ def change
39
39
  create_table "migration_models" do |t|
40
40
  t.string "login", null: false, limit: 24
41
- t.column "extras", :json
41
+ t.json "extras"
42
42
  end
43
43
  end
44
44
  end
@@ -48,7 +48,7 @@ or add the column to an existing one:
48
48
 
49
49
  ```
50
50
  class CreateUsers < ActiveRecord::Migration
51
- def up
51
+ def change
52
52
  add_column "users", "extras", :json
53
53
  end
54
54
  end
@@ -66,17 +66,14 @@ end
66
66
  then (ab)use the new attribute!:
67
67
 
68
68
  ```ruby
69
- user = User.create!(login: "saverio", extras: {"uses" => ["mysql", "json"]})
70
- user.extras.fetch("uses") # => ["mysql", "json"]
69
+ User.create!(login: "saverio", extras: {"uses" => ["mysql", "json"]})
70
+ # ...
71
+ User.last.extras.fetch("uses") # => ["mysql", "json"]
71
72
  ```
72
73
 
73
- Don't forget that JSON doesn't support symbols, therefore, they can be saved, but are accessed/loaded as strings.
74
+ Don't forget that JSON doesn't support symbols, therefore, they can be set, but are accessed/loaded as strings.
74
75
 
75
76
  Users are encouraged to have a look at the test suite ([here](spec/json_on_rails/json_attributes_spec.rb) and [here](spec/json_on_rails/arel_methods_spec.rb)) for an exhaustive view of the functionality.
76
77
 
77
- ## Limitations
78
-
79
- The column creation `t.json <column_name>` syntax is currently unsupported.
80
-
81
78
  [BS img]: https://travis-ci.org/saveriomiroddi/json_on_rails.svg?branch=master
82
79
  [CS img]: https://coveralls.io/repos/saveriomiroddi/json_on_rails/badge.png?branch=master
@@ -0,0 +1,24 @@
1
+ module ActiveRecord
2
+ # Unfortunately, the type shorthands are hardcoded, and the code itself is not encapsulated
3
+ # in a method, so there's not much design freedom.
4
+ # See the file `schema_definitions.rb`.
5
+ #
6
+ module ConnectionAdapters
7
+ class TableDefinition
8
+ def json(*args)
9
+ options = args.extract_options!
10
+ column_names = args
11
+ column_names.each { |name| column(name, :json, options) }
12
+ end
13
+ end
14
+
15
+ class Table
16
+ def json(*args)
17
+ options = args.extract_options!
18
+ args.each do |column_name|
19
+ @base.add_column(name, column_name, :json, options)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "active_record/type/json"
4
+ require_relative "active_record/connection_adapters/schema_definitions"
4
5
 
5
6
  module JsonOnRails; end
@@ -1,3 +1,3 @@
1
1
  module JsonOnRails
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi
@@ -102,6 +102,7 @@ extra_rdoc_files: []
102
102
  files:
103
103
  - LICENSE
104
104
  - README.md
105
+ - lib/active_record/connection_adapters/schema_definitions.rb
105
106
  - lib/active_record/type/json.rb
106
107
  - lib/json_on_rails.rb
107
108
  - lib/json_on_rails/version.rb