json_serialisable 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. data/lib/json_serialisable.rb +34 -34
  2. metadata +5 -5
@@ -1,34 +1,34 @@
1
- # Mixin for the Class class
2
- class Class
3
- # A shorthand which automatically adds methods for serialising via JSON
4
- #
5
- # Example:
6
- # attr_serialise :a, :b, ...
7
- #
8
- # Arguments:
9
- # (:variable_label)+
10
- #
11
- # Remark:
12
- # There should be a matching contstructor with the same method signature as the labels used in the function call.
13
- # This way json_create will not error when it is called.
14
-
15
- def attr_serialise(*attrs)
16
-
17
- # Sanity checks
18
- abort "Please provide at least one argument" if attrs.length == 0
19
-
20
- #Build to the to_json method
21
- tojson = "def to_json(*a)\n{ 'json_class' => #{self.name}"
22
- attrs.each { |a| tojson << ",\n'#{a}' => @#{a}"}
23
- tojson << "\n}.to_json(*a)\nend"
24
-
25
- #build to json_create method
26
- jsoncreate = "def self.json_create(o)\nnew( *o['#{attrs.shift}']"
27
- attrs.each { |a| jsoncreate << ", *o['#{a}']" }
28
- jsoncreate << ")\nend"
29
-
30
- # Add methods
31
- class_eval(tojson)
32
- class_eval(jsoncreate)
33
- end
34
- end
1
+ # Mixin for the Class class
2
+ class Class
3
+ # A shorthand which automatically adds methods for serialising via JSON
4
+ #
5
+ # Example:
6
+ # attr_serialise :a, :b, ...
7
+ #
8
+ # Arguments:
9
+ # (:variable_label)+
10
+ #
11
+ # Remark:
12
+ # There should be a matching contstructor with the same method signature as the labels used in the function call.
13
+ # This way json_create will not error when it is called.
14
+
15
+ def attr_serialise(*attrs)
16
+
17
+ # Sanity checks
18
+ abort "Please provide at least one argument" if attrs.length == 0
19
+
20
+ #Build to the to_json method
21
+ tojson = "def to_json(*a)\n{ 'json_class' => #{self.name}"
22
+ attrs.each { |a| tojson << ",\n'#{a}' => @#{a}"}
23
+ tojson << "\n}.to_json(*a)\nend"
24
+
25
+ #build to json_create method
26
+ jsoncreate = "def self.json_create(o)\nnew( o['#{attrs.shift}']"
27
+ attrs.each { |a| jsoncreate << ", o['#{a}']" }
28
+ jsoncreate << ")\nend"
29
+
30
+ # Add methods
31
+ class_eval(tojson)
32
+ class_eval(jsoncreate)
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_serialisable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-02 00:00:00.000000000 Z
12
+ date: 2012-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &20584776 !ruby/object:Gem::Requirement
16
+ requirement: &7888880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 1.5.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20584776
24
+ version_requirements: *7888880
25
25
  description: Adds support for autogenerating json serialisation functions
26
26
  email: carlc75@gmail.com
27
27
  executables: []
@@ -29,7 +29,7 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
  files:
31
31
  - lib/json_serialisable.rb
32
- homepage: http://carlellis.co.uk
32
+ homepage: https://github.com/carl-ellis/json_serialisable
33
33
  licenses: []
34
34
  post_install_message:
35
35
  rdoc_options: []