json_to_ruby_class 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +33 -0
- data/lib/json_to_ruby_class/version.rb +1 -1
- data/lib/json_to_ruby_class.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d4b496618f50ce3db3c2289f2b45b0b061401f3
|
4
|
+
data.tar.gz: e42dbca984291f936ac947c5feee50ee9dcfb336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 472017c0bb8540751f2d9501d4b3fc99e2cad8170c9cb297c863cb3ac63a02cd5ff43d9fd099a1a61159c04325d2a1a115c9543bf07d18c13b4c11d68a9669a7
|
7
|
+
data.tar.gz: bcaf802d4be506ac8689fede841269badafab01c8540efde8ede556d92d945ce16b258573ec8dfd3fcbd7cb90b58b2cebec27e7c9ad859324c01712129886aba
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# JsonToRubyClass
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/arcanoid/json_to_ruby_class.svg?branch=master)](https://travis-ci.org/arcanoid/json_to_ruby_class)
|
4
|
+
|
3
5
|
JsonToRubyClass is a gem that converts a JSON to a list of Ruby classes and outputs it into a string.
|
4
6
|
|
5
7
|
## Installation
|
@@ -20,7 +22,38 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
25
|
+
```ruby
|
26
|
+
json = {
|
27
|
+
"students": [
|
28
|
+
{
|
29
|
+
"firstName": "John",
|
30
|
+
"lastName": "Doe",
|
31
|
+
"age": 15
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"firstName": "Anna",
|
35
|
+
"lastName": "Smith",
|
36
|
+
"age": 16
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
|
41
|
+
puts JsonToRubyClass.produce_models(json)
|
42
|
+
```
|
43
|
+
|
44
|
+
This produces the following:
|
23
45
|
|
46
|
+
```ruby
|
47
|
+
Class Student
|
48
|
+
attr_accessor :first_name,
|
49
|
+
:last_name,
|
50
|
+
:age
|
51
|
+
end
|
52
|
+
|
53
|
+
Class Example
|
54
|
+
attr_accessor :students
|
55
|
+
end
|
56
|
+
```
|
24
57
|
|
25
58
|
## Development
|
26
59
|
|
data/lib/json_to_ruby_class.rb
CHANGED
@@ -32,7 +32,7 @@ module JsonToRubyClass
|
|
32
32
|
accessors_to_be_used = accessors.map { |s| ":#{s.to_s.underscore}" }
|
33
33
|
|
34
34
|
if (hash = existing_models_array.find { |model| model[:name] == model_name_to_be_used })
|
35
|
-
hash[:accessors].push(accessors_to_be_used).uniq!
|
35
|
+
hash[:accessors].push(accessors_to_be_used).flatten!.uniq!
|
36
36
|
else
|
37
37
|
existing_models_array << {
|
38
38
|
:name => (model_name.nil? ? 'Example' : model_name.to_s.camelcase),
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_to_ruby_class
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasilis Kalligas
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- CODE_OF_CONDUCT.md
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE.txt
|