class_from_son 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53b0a1472f3977c2b06e85680263efdd69178894
4
- data.tar.gz: 70b7f897adb5ee1b4ead08b90517eb2d1d412dad
3
+ metadata.gz: 4f9be3e63d8f7a02b3730f9f1724db43195b4f3c
4
+ data.tar.gz: 42738af01994e7cf1255056957ccf347293927d3
5
5
  SHA512:
6
- metadata.gz: da824ddb560f2d64d476b3602d6e8c24c59f62ee62a367bf2b532813877d5151fdc45daae57ccc90aea77b3e9acf04054c1218e6fa5b60a4da284ba8ae9728f8
7
- data.tar.gz: 640658471d76f8fa525f8057d6dc7a7159a56c093f498f165d1f570f9da6c0dce11f1e9c32ac09d0b016a2dcc2fd5d6a9575c58a481a3aae17a0ac9145b2173e
6
+ metadata.gz: 3115ef3e94fa4c576fb50a3835cd4750d6559c11664037548a9cad3486e7c2ded94efe661acae3c3bdc2098c0a101ffd7de3ab285c26cb97fdc73198ab12d480
7
+ data.tar.gz: 0b7154dd5c75d416bcb2c9c872df1d4fa1955bf1938afdad0e6bebfeadf49e33d3b05067b95073ace0d092b68af748fded8d52e8bbe99a1be03dbba712c56ea1
@@ -9,17 +9,19 @@ Limitations :
9
9
  SON : will only process JSON
10
10
  Code : will only generate Ruby or Java
11
11
 
12
- Usage : require the gem, then invoke as follows :
12
+ Usage : require the gem, then invoke
13
+ ```
14
+ require 'class_from_son'
13
15
 
14
- ClassFromSON.generate_from_file :ruby, a_file.json
16
+ ClassFromSON.generate_from_file :ruby, "a_file.json"
15
17
 
16
18
  or
17
19
 
18
20
  ClassFromSON.generate :ruby, my_json_string, :json
19
-
21
+ ```
20
22
 
21
23
  Method parameter explanations :
22
-
24
+ ```
23
25
  # Will generate classes from a SON file
24
26
  # Regardless of whether or not files are written, this will return an array of hashes; each hash represents a file, with two keys : :name for filename (without extension), and :contents for file contents
25
27
  #
@@ -29,9 +31,9 @@ Method parameter explanations :
29
31
  # make_file flag defaults to true; set to false if you do not want files to be created by this method
30
32
  # force_file flag is false; set to true if you wish to overwrite matching destination files (use with caution!)
31
33
  def ClassFromSON.generate_from_file(dest_lang, file, source_lang, make_file = true, force_file = false)
34
+ ```
32
35
 
33
-
34
-
36
+ ```
35
37
  # Will generate classes from a SON string
36
38
  # Regardless of whether or not files are written, this will return an array of hashes; each hash represents a file, with two keys : :name for filename (without extension), and :contents for file contents
37
39
  #
@@ -41,3 +43,4 @@ def ClassFromSON.generate_from_file(dest_lang, file, source_lang, make_file = tr
41
43
  # make_file flag defaults to true; set to false if you do not want files to be created by this method
42
44
  # force_file flag is false; set to true if you wish to overwrite matching destination files (use with caution!)
43
45
  def ClassFromSON.generate(dest_lang, source, source_lang, make_file = true, force_file = false)
46
+ ```
@@ -372,10 +372,14 @@ class ClassFromSON
372
372
  error_and_exit "Cannot parse input language #{@mode}; can only parse #{@@input_modes.join(", ")}"
373
373
  end
374
374
 
375
+ # TODO other input languages, e.g. XML, YAML
375
376
  case @mode
376
377
  when :json
377
- hash = JSON.parse(source)
378
- # TODO other input languages, e.g. XML, YAML
378
+ begin
379
+ hash = JSON.parse(source)
380
+ rescue JSON::ParserError => e
381
+ error_and_exit "Could not parse supplied string as JSON. Error message : #{e.message}"
382
+ end
379
383
  else
380
384
  error_and_exit "Cannot parse mode #{@mode}"
381
385
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: class_from_son
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Morrisby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2019-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem will attempt to generate code of a class of an object representing
14
14
  the contents of a Serialised-Object-Notation (SON) string (or file). E.g. it will
@@ -16,21 +16,12 @@ description: This gem will attempt to generate code of a class of an object repr
16
16
  email: rmorrisby@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
- extra_rdoc_files: []
19
+ extra_rdoc_files:
20
+ - README.md
20
21
  files:
21
- - LICENCE.txt
22
- - README.txt
23
- - build.rb
24
- - class_from_son.gemspec
25
- - lib/class_from_SON.rb
26
- - test/Address.java
27
- - test/GeneratedFromJson.java
28
- - test/PhoneNumbers.java
29
- - test/address.rb
30
- - test/generated_from_json.rb
31
- - test/phonenumbers.rb
22
+ - README.md
23
+ - lib/class_from_son.rb
32
24
  - test/test_class_from_son.rb
33
- - test/testjson.json
34
25
  homepage: https://rubygems.org/gems/class_from_son
35
26
  licenses:
36
27
  - MIT
@@ -54,6 +45,6 @@ rubyforge_project:
54
45
  rubygems_version: 2.6.7
55
46
  signing_key:
56
47
  specification_version: 4
57
- summary: Generates classes from SON (e.g. JSON)
48
+ summary: Generates classes from Serialised-Object-Notation (e.g. JSON)
58
49
  test_files:
59
50
  - test/test_class_from_son.rb
data/LICENCE.txt DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2016 Richard Morrisby
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
data/build.rb DELETED
@@ -1,51 +0,0 @@
1
- # Simple build script
2
- # Deletes the existing gem file (if present)
3
- # Uninstalls the gem
4
- # Builds the gem
5
- # Installs the new gem
6
-
7
- # Note : when calling system (or backticks, etc.) th enew process starts at the system default, not the current working directory.
8
- # Therefore we need to use a syntax of : system "cd #{gem_dir} && #{i_cmd}"
9
-
10
- # Run from this directory!
11
-
12
- gem_dir = Dir.getwd
13
-
14
- # Delete existing .gem files in the dir
15
-
16
- gemfiles = Dir.entries(gem_dir).collect {|q| q if q =~ /.gem$/}.compact
17
-
18
- gemfiles.each do |q|
19
- File.delete q
20
- puts "Deleted #{q}"
21
- end
22
-
23
- gemfiles = Dir.entries(gem_dir).collect {|q| q if q =~ /.gem$/}.compact
24
- raise "Gem has not been deleted" unless gemfiles.size == 0
25
-
26
- # Uninstall, build, install
27
- gemspecs = Dir.entries(gem_dir).collect {|q| q if q =~ /.gemspec$/}.compact
28
-
29
- raise "Did not find a .gemspec in #{gem_dir}" if gemspecs.size < 1
30
- raise "Found more than one .gemspec in #{gem_dir}" if gemspecs.size > 1
31
-
32
- gemspec = gemspecs[0]
33
-
34
- gemname = File.basename(gemspec, File.extname(gemspec))
35
-
36
- u_cmd = "gem uninstall #{gemname}"
37
- system u_cmd
38
-
39
- b_cmd = "gem build #{gemspec}"
40
- system "cd #{gem_dir} && #{b_cmd}"
41
-
42
- gemfiles = Dir.entries(gem_dir).collect {|q| q if q =~ /.gem$/}.compact
43
- raise "Gem was not built" unless gemfiles.size == 1
44
-
45
- gemfile = gemfiles[0]
46
- raise "Gem file is not for the expected gem, expected a #{gemname} gem but found #{gemfile}" unless gemfile =~ /^#{gemname}/
47
-
48
- i_cmd = "gem install #{gemfile}"
49
- system "cd #{gem_dir} && #{i_cmd}"
50
-
51
- puts "Gem #{gemname} built & installed"
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'class_from_son'
3
- s.version = '0.1.0'
4
- s.licenses = ['MIT']
5
- s.summary = "Generates classes from SON (e.g. JSON)"
6
- s.description = "This gem will attempt to generate code of a class of an object representing the contents of a Serialised-Object-Notation (SON) string (or file). E.g. it will generate code of a object's class from some JSON."
7
- s.authors = ["Richard Morrisby"]
8
- s.email = 'rmorrisby@gmail.com'
9
- s.files = ["lib/class_from_SON.rb"]
10
- s.homepage = 'https://rubygems.org/gems/class_from_son'
11
- s.required_ruby_version = '>=1.9'
12
- s.files = Dir['**/**']
13
- s.test_files = Dir["test/test*.rb"]
14
- s.has_rdoc = true
15
- end
data/test/Address.java DELETED
@@ -1,38 +0,0 @@
1
- public class Address {
2
- public String streetAddress;
3
- public String city;
4
- public String state;
5
- public String postalCode;
6
-
7
- public String getStreetAddress() {
8
- return streetAddress;
9
- }
10
-
11
- public void setStreetAddress(String streetAddress) {
12
- this.streetAddress = streetAddress;
13
- }
14
-
15
- public String getCity() {
16
- return city;
17
- }
18
-
19
- public void setCity(String city) {
20
- this.city = city;
21
- }
22
-
23
- public String getState() {
24
- return state;
25
- }
26
-
27
- public void setState(String state) {
28
- this.state = state;
29
- }
30
-
31
- public String getPostalCode() {
32
- return postalCode;
33
- }
34
-
35
- public void setPostalCode(String postalCode) {
36
- this.postalCode = postalCode;
37
- }
38
- }
@@ -1,74 +0,0 @@
1
- public class GeneratedFromJson {
2
- public String firstName;
3
- public String lastName;
4
- public boolean isAlive;
5
- public int age;
6
- public Address address;
7
- public List<PhoneNumbers> phoneNumbers;
8
- public List<String> children;
9
- public String spouse;
10
-
11
- public String getFirstName() {
12
- return firstName;
13
- }
14
-
15
- public void setFirstName(String firstName) {
16
- this.firstName = firstName;
17
- }
18
-
19
- public String getLastName() {
20
- return lastName;
21
- }
22
-
23
- public void setLastName(String lastName) {
24
- this.lastName = lastName;
25
- }
26
-
27
- public boolean getIsAlive() {
28
- return isAlive;
29
- }
30
-
31
- public void setIsAlive(boolean isAlive) {
32
- this.isAlive = isAlive;
33
- }
34
-
35
- public int getAge() {
36
- return age;
37
- }
38
-
39
- public void setAge(int age) {
40
- this.age = age;
41
- }
42
-
43
- public Address getAddress() {
44
- return address;
45
- }
46
-
47
- public void setAddress(Address address) {
48
- this.address = address;
49
- }
50
-
51
- public List<PhoneNumbers> getPhoneNumbers() {
52
- return phoneNumbers;
53
- }
54
-
55
- public void setPhoneNumbers(List<PhoneNumbers> phoneNumbers) {
56
- this.phoneNumbers = phoneNumbers;
57
- }
58
-
59
- public List<String> getChildren() {
60
- return children;
61
- }
62
-
63
- public void setChildren(List<String> children) {
64
- this.children = children;
65
- }
66
-
67
- public String getSpouse() {
68
- return spouse;
69
- }
70
-
71
- public void setSpouse(String spouse) {
72
- this.spouse = spouse;
73
- }
74
- }
@@ -1,20 +0,0 @@
1
- public class PhoneNumbers {
2
- public String type;
3
- public String number;
4
-
5
- public String getType() {
6
- return type;
7
- }
8
-
9
- public void setType(String type) {
10
- this.type = type;
11
- }
12
-
13
- public String getNumber() {
14
- return number;
15
- }
16
-
17
- public void setNumber(String number) {
18
- this.number = number;
19
- }
20
- }
data/test/address.rb DELETED
@@ -1,13 +0,0 @@
1
- class Address
2
- attr_accessor :streetAddress
3
- attr_accessor :city
4
- attr_accessor :state
5
- attr_accessor :postalCode
6
-
7
- def initialize(streetAddress, city, state, postalCode)
8
- @streetAddress = streetAddress
9
- @city = city
10
- @state = state
11
- @postalCode = postalCode
12
- end
13
- end
@@ -1,21 +0,0 @@
1
- class Generated_from_json
2
- attr_accessor :firstName
3
- attr_accessor :lastName
4
- attr_accessor :isAlive
5
- attr_accessor :age
6
- attr_accessor :address
7
- attr_accessor :phoneNumbers
8
- attr_accessor :children
9
- attr_accessor :spouse
10
-
11
- def initialize(firstName, lastName, isAlive, age, address, phoneNumbers, children, spouse)
12
- @firstName = firstName
13
- @lastName = lastName
14
- @isAlive = isAlive
15
- @age = age
16
- @address = address
17
- @phoneNumbers = phoneNumbers
18
- @children = children
19
- @spouse = spouse
20
- end
21
- end
data/test/phonenumbers.rb DELETED
@@ -1,9 +0,0 @@
1
- class PhoneNumbers
2
- attr_accessor :type
3
- attr_accessor :number
4
-
5
- def initialize(type, number)
6
- @type = type
7
- @number = number
8
- end
9
- end
data/test/testjson.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "firstName": "John",
3
- "lastName": "Smith",
4
- "isAlive": true,
5
- "age": 25,
6
- "address": {
7
- "streetAddress": "21 2nd Street",
8
- "city": "New York",
9
- "state": "NY",
10
- "postalCode": "10021-3100"
11
- },
12
- "phoneNumbers": [
13
- {
14
- "type": "home",
15
- "number": "212 555-1234"
16
- },
17
- {
18
- "type": "office",
19
- "number": "646 555-4567"
20
- },
21
- {
22
- "type": "mobile",
23
- "number": "123 456-7890"
24
- }
25
- ],
26
- "children": [],
27
- "spouse": null
28
- }