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 +4 -4
- data/README.md +9 -12
- data/lib/active_record/connection_adapters/schema_definitions.rb +24 -0
- data/lib/json_on_rails.rb +1 -0
- data/lib/json_on_rails/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5cd9da9b9e15cf64d420716d697b9fdc34763d1dc4b2c5fa350bf3afdf3d6e
|
4
|
+
data.tar.gz: 7d9e7647696a997b94f8ed3a916cd8817e070f4d4b13dc033a23757964db1b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
21
|
+
gem "json_on_rails", "~> 0.1.2"
|
22
22
|
```
|
23
23
|
|
24
|
-
and update the
|
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
|
38
|
+
def change
|
39
39
|
create_table "migration_models" do |t|
|
40
40
|
t.string "login", null: false, limit: 24
|
41
|
-
t.
|
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
|
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
|
-
|
70
|
-
|
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
|
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
|
data/lib/json_on_rails.rb
CHANGED
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.
|
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
|