rson 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/serializer/rson.rb +9 -0
- data/lib/serializer/rson/class.rb +40 -0
- data/lib/serializer/rson/instance.rb +2 -0
- data/lib/serializer/rson/instance/private.rb +102 -0
- data/lib/serializer/rson/instance/public.rb +47 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2025620b7c89155f91b351f085377db68c4d3b83
|
4
|
+
data.tar.gz: 9d57ca7751798359765342ba4db1ced605a5270d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ff3ef15e137ae276b2bdb42f160ff69344dc340c748020e54a6cb5e469f5c0b545f82de0cf375be2577393235c201afa9b00386be26807b5b38edcc917a8a61
|
7
|
+
data.tar.gz: f132bd66727b0e2fb3afe49c3710202432efe0f9e9b3b33c26b31067c7f53f256ee02597e903b9eef67de3b48785e2350b50d763351aeb524bd2b43f0c916c84
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'classy_hash'
|
2
|
+
#############################################################################
|
3
|
+
#
|
4
|
+
#
|
5
|
+
#
|
6
|
+
#############################################################################
|
7
|
+
module Serializer
|
8
|
+
###########################################################################
|
9
|
+
#
|
10
|
+
#
|
11
|
+
#
|
12
|
+
###########################################################################
|
13
|
+
class RSON
|
14
|
+
#########################################################################
|
15
|
+
#
|
16
|
+
#
|
17
|
+
#
|
18
|
+
#########################################################################
|
19
|
+
module Class
|
20
|
+
def load(params={})
|
21
|
+
buffer = params.fetch(:buffer,nil)
|
22
|
+
if buffer.nil?
|
23
|
+
file_path = params.fetch(:file_path)
|
24
|
+
file_name = params.fetch(:file_name)
|
25
|
+
file_path = File.join(
|
26
|
+
File.expand_path(file_path),
|
27
|
+
file_name
|
28
|
+
)
|
29
|
+
buffer = IO.read(file_path)
|
30
|
+
end
|
31
|
+
instance = new(buffer)
|
32
|
+
instance.hydrate
|
33
|
+
rescue Parser::SyntaxError => e
|
34
|
+
puts 'in RSON file /etc/config.rson'
|
35
|
+
puts file_path if buffer.nil?
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
#############################################################################
|
6
|
+
module Serializer
|
7
|
+
###########################################################################
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
###########################################################################
|
12
|
+
class RSON
|
13
|
+
#########################################################################
|
14
|
+
#
|
15
|
+
#
|
16
|
+
#
|
17
|
+
#########################################################################
|
18
|
+
module Instance
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
#######################################################################
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#
|
26
|
+
#######################################################################
|
27
|
+
def hydrate_abstract_syntax_tree(abstract_syntax_tree)
|
28
|
+
rb_object = case abstract_syntax_tree.type
|
29
|
+
when :hash
|
30
|
+
hydrate_hash(abstract_syntax_tree)
|
31
|
+
when :array
|
32
|
+
hydrate_array(abstract_syntax_tree)
|
33
|
+
when :sym, :str, :int, :float
|
34
|
+
hydrate_leaf(abstract_syntax_tree)
|
35
|
+
when :dstr
|
36
|
+
hydrate_dstr(abstract_syntax_tree)
|
37
|
+
when :true
|
38
|
+
true
|
39
|
+
when :false
|
40
|
+
false
|
41
|
+
when :nil
|
42
|
+
nil
|
43
|
+
else
|
44
|
+
raise Exception, abstract_syntax_tree
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#######################################################################
|
49
|
+
#
|
50
|
+
# hydrate_hash()
|
51
|
+
# => Hash
|
52
|
+
#
|
53
|
+
#######################################################################
|
54
|
+
def hydrate_hash(abstract_syntax_tree)
|
55
|
+
rb_hash = Hash.new
|
56
|
+
abstract_syntax_tree.children.each do |child|
|
57
|
+
node_key, node_value = *child.to_a
|
58
|
+
rb_hash.store(
|
59
|
+
hydrate_abstract_syntax_tree(node_key),
|
60
|
+
hydrate_abstract_syntax_tree(node_value)
|
61
|
+
)
|
62
|
+
end
|
63
|
+
rb_hash
|
64
|
+
end
|
65
|
+
|
66
|
+
#######################################################################
|
67
|
+
#
|
68
|
+
#
|
69
|
+
# => Array
|
70
|
+
#
|
71
|
+
#######################################################################
|
72
|
+
def hydrate_array(abstract_syntax_tree)
|
73
|
+
rb_array = Array.new
|
74
|
+
abstract_syntax_tree.children.each do |child|
|
75
|
+
rb_array.push(
|
76
|
+
hydrate_abstract_syntax_tree(child)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
rb_array
|
80
|
+
end
|
81
|
+
|
82
|
+
#######################################################################
|
83
|
+
#
|
84
|
+
#
|
85
|
+
#
|
86
|
+
#######################################################################
|
87
|
+
def hydrate_leaf(abstract_syntax_tree)
|
88
|
+
abstract_syntax_tree.to_a.first
|
89
|
+
end
|
90
|
+
|
91
|
+
#######################################################################
|
92
|
+
#
|
93
|
+
#
|
94
|
+
#
|
95
|
+
#######################################################################
|
96
|
+
def hydrate_dstr(abstract_syntax_tree)
|
97
|
+
abstract_syntax_tree.children.map {|child| hydrate_leaf(child) }.join
|
98
|
+
end
|
99
|
+
|
100
|
+
end # module Instance
|
101
|
+
end # class RSON
|
102
|
+
end # module Serializer
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'parser/ruby23'
|
2
|
+
|
3
|
+
#############################################################################
|
4
|
+
#
|
5
|
+
#
|
6
|
+
#
|
7
|
+
#############################################################################
|
8
|
+
module Serializer
|
9
|
+
###########################################################################
|
10
|
+
#
|
11
|
+
#
|
12
|
+
#
|
13
|
+
###########################################################################
|
14
|
+
class RSON
|
15
|
+
#########################################################################
|
16
|
+
#
|
17
|
+
#
|
18
|
+
#
|
19
|
+
#########################################################################
|
20
|
+
module Instance
|
21
|
+
#######################################################################
|
22
|
+
#
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#######################################################################
|
26
|
+
def initialize(buffer)
|
27
|
+
@buffer = buffer
|
28
|
+
@abstract_syntax_tree = Parser::Ruby23.parse(@buffer)
|
29
|
+
end
|
30
|
+
|
31
|
+
#######################################################################
|
32
|
+
#
|
33
|
+
#
|
34
|
+
#
|
35
|
+
#######################################################################
|
36
|
+
def hydrate
|
37
|
+
raise ArgumentError, {
|
38
|
+
ast_class:@abstract_syntax_tree.class,
|
39
|
+
ast:@abstract_syntax_tree
|
40
|
+
} unless @abstract_syntax_tree.kind_of? Parser::AST::Node
|
41
|
+
hydrate_abstract_syntax_tree(@abstract_syntax_tree)
|
42
|
+
rescue Exception => e
|
43
|
+
raise e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rson
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David DELAVENNAT
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_print
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: classy_hash
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.1'
|
69
|
+
description: JSON like serialization with simple Ruby objects support
|
70
|
+
email: ''
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/serializer/rson.rb
|
76
|
+
- lib/serializer/rson/class.rb
|
77
|
+
- lib/serializer/rson/instance.rb
|
78
|
+
- lib/serializer/rson/instance/private.rb
|
79
|
+
- lib/serializer/rson/instance/public.rb
|
80
|
+
homepage: https://github.com/tannevaled/rson
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Ruby Simple Object's Notation
|
103
|
+
test_files: []
|