erlang_config 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c1d8a480081ceebd90788f93f858aacc667db9c
4
+ data.tar.gz: 2c76272040f67ac0faaea00ca8e5a4330a3fdf42
5
+ SHA512:
6
+ metadata.gz: 5a2334d755fd7f58aff33969b4f41080bcb4f97d21ee885248c692ec4078a12d2933865d4c7ffec503ce884f846679d5fd901ac6ea2b22854a9a76b99e61d275
7
+ data.tar.gz: 1a266ea8a96f67b060098c19ce39935d4884ee784592aa6387ba42f4128cad7f60d348da8b6ad3591dbb533185ffb95e601fa6b49d724464a1940b8935bf12eb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in erlang_config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Roman Gaufman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Erlang::Config
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'erlang_config'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install erlang_config
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/erlang_config/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'erlang_config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "erlang_config"
8
+ spec.version = ErlangConfig::VERSION
9
+ spec.authors = ["Roman Gaufman"]
10
+ spec.email = ["roman@xanview.com"]
11
+ spec.summary = %q{Encode and Decode Erlang style configuration files.}
12
+ spec.description = %q{See summery}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 10.1"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ end
@@ -0,0 +1,26 @@
1
+ require "erlang_config/erlterm"
2
+ require "erlang_config/erlatom"
3
+ require "erlang_config/erlbinary"
4
+ require "erlang_config/erlnumeration"
5
+ require "erlang_config/erllist"
6
+ require "erlang_config/erlpid"
7
+ require "erlang_config/erlref"
8
+ require "erlang_config/erlstring"
9
+ require "erlang_config/erltuple"
10
+
11
+ ERL_CLOSE_STRS = {"["=>"]", "{"=>"}", '"'=>'"', "'"=>"'", '<<'=>'>>', "#Ref<"=>">", "<"=>">"}
12
+
13
+ module ErlangConfig
14
+
15
+ def self.decode(str)
16
+ str.gsub!(/[\n\r]/,"")
17
+ erl_obj = ErlTerm.decode(str)
18
+ erl_obj.parse if erl_obj.is_a?(ErlEnumeration)
19
+ erl_obj.to_ruby
20
+ end
21
+
22
+ def self.encode(hash)
23
+ puts "Sorry, this has not been written yet, pull requests are welcome :)"
24
+ end
25
+
26
+ end
@@ -0,0 +1,7 @@
1
+ module ErlangConfig
2
+ class ErlAtom < ErlTerm
3
+ def to_ruby
4
+ self.str.gsub(/'/,"")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module ErlangConfig
2
+ class ErlBinary < ErlTerm
3
+ def to_ruby
4
+ self.str.gsub!(/[<>]/,"")
5
+ bin_els = self.str.split(",")
6
+ els = bin_els.map { |el|
7
+ if el[/^[0-9]+$/]
8
+ el.to_i
9
+ elsif el[/^"/]
10
+ el.gsub(/"/,"")
11
+ end
12
+ }
13
+ els.length > 1 ? els : els[0]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module ErlangConfig
2
+ class ErlList < ErlEnumeration
3
+ def to_ruby
4
+ @elements.map {|el|
5
+ (el.is_a?(ErlTerm) || el.is_a?(ErlEnumeration))? el.to_ruby : el
6
+ }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,72 @@
1
+ module ErlangConfig
2
+ class ErlEnumeration
3
+ attr_accessor :str, :elements
4
+ def initialize(str)
5
+ @str = str
6
+ @elements = []
7
+ end
8
+
9
+ def parse
10
+ strs = get_element_strs
11
+ @elements = parse_element_strs(strs)
12
+ end
13
+
14
+ def pos_close_str(str, open_str)
15
+ close_str = ERL_CLOSE_STRS[open_str]
16
+ if open_str == close_str
17
+ return str.index(close_str,1)
18
+ else
19
+ open_count = 1
20
+ for i in ((str.index(open_str)+1)..(str.length))
21
+ opened = (str[i,open_str.length ] == open_str)
22
+ open_count += 1 if opened
23
+ closed = (str[i,close_str.length] == close_str)
24
+ open_count -= 1 if closed
25
+ return i if (closed && open_count==0)
26
+ end
27
+ raise "Parse error, not found matching close of #{open_str} in #{str}"
28
+ end
29
+ end
30
+
31
+ def parse_first_term(str_to_parse)
32
+ open_str = str_to_parse[/^(\[|\{|\"|\'|<<|#Ref|<)/,1]
33
+ if open_str
34
+ close_str = ERL_CLOSE_STRS[open_str]
35
+ pos_open_str = str_to_parse.index(open_str)
36
+ pos_close_str = pos_close_str(str_to_parse,open_str)
37
+ term_str = str_to_parse[pos_open_str..(pos_close_str+close_str.length-1)]
38
+ new_str_to_parse = str_to_parse[(pos_close_str+close_str.length), str.length]
39
+ else
40
+ pos_open_str = 0
41
+ pos_close_str = str_to_parse.index(",") || str_to_parse.length
42
+ term_str = str_to_parse[pos_open_str..(pos_close_str-1)]
43
+ new_str_to_parse = str_to_parse[pos_close_str+1, str.length]
44
+ end
45
+ new_str_to_parse = "" if new_str_to_parse.nil?
46
+ [term_str, new_str_to_parse.gsub(/^[,\s]+/,"")]
47
+ end
48
+
49
+ #parse @str to elements to the end of @str, and each elements must be separated by ","
50
+ def get_element_strs
51
+ element_strs=[]
52
+ str_to_parse = @str[1,@str.length-2].strip # between [ and ], or { and }
53
+ until str_to_parse == ""
54
+ term_str, new_str_to_parse = parse_first_term(str_to_parse)
55
+ element_strs << term_str
56
+ str_to_parse = new_str_to_parse
57
+ end
58
+ element_strs
59
+ end
60
+
61
+ def parse_element_strs(strs)
62
+ strs.map {|term_str|
63
+ term = ErlTerm.decode(term_str)
64
+ if term.is_a?(ErlTuple) or term.is_a?(ErlList)
65
+ term_strs = term.get_element_strs
66
+ term.elements = term.parse_element_strs(term_strs)
67
+ end
68
+ term
69
+ }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,8 @@
1
+ module ErlangConfig
2
+ class ErlPid < ErlTerm
3
+ def to_ruby
4
+ self.str.gsub!(/<>/,"")
5
+ bin_els = self.str.split(".")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module ErlangConfig
2
+ class ErlRef < ErlTerm
3
+ def to_ruby
4
+ self.str.gsub!(/#Ref<|>/,"")
5
+ bin_els = self.str.split(".")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module ErlangConfig
2
+ class ErlString < ErlTerm
3
+ def to_ruby
4
+ self.str.gsub(/"/,"")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module ErlangConfig
2
+ class ErlTerm
3
+ attr_accessor :str
4
+ def initialize(str)
5
+ @str = str
6
+ end
7
+
8
+ def self.decode(str)
9
+ str.strip!
10
+ term_open_str = str[/^(\[|\{|\"|\'|<<|#Ref|<)/,1]
11
+ if term_open_str.nil? # integer,float, or, atom
12
+ matches = /^(([-0-9\.]+)|([a-z][a-z0-9_]*))/.match(str)
13
+ term = case
14
+ when (matches[2] && str[/\./]) then str.to_f
15
+ when matches[2] then str.to_i
16
+ when matches[3] then str.to_sym
17
+ end
18
+ else
19
+ term_close_str = ERL_CLOSE_STRS[term_open_str]
20
+ re_ends_with_close_str = Regexp.new(Regexp.escape("#{term_close_str}")+"$")
21
+ raise "Parse error, Invalid erlang term #{str}" unless re_ends_with_close_str.match(str)
22
+ term = case term_open_str
23
+ when '[' then ErlList.new(str)
24
+ when '{' then ErlTuple.new(str)
25
+ when '"' then ErlString.new(str)
26
+ when "'" then ErlAtom.new(str)
27
+ when "<<" then ErlBinary.new(str)
28
+ when "#Ref" then ErlRef.new(str)
29
+ when "<" then ErlPid.new(str)
30
+ else raise "Parse error with #{term_open_str}"
31
+ end
32
+ end
33
+ term
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module ErlangConfig
2
+ class ErlTuple < ErlEnumeration
3
+ def to_ruby
4
+ arr = @elements.map {|el|
5
+ (el.is_a?(ErlTerm) || el.is_a?(ErlEnumeration))? el.to_ruby : el
6
+ }
7
+ key = arr.delete_at(0)
8
+ hash = {key => ( arr.length>1 ? arr: arr[0])}
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ErlangConfig
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ [{pid,53721},
2
+ {running_applications,
3
+ [{rabbitmq_management_visualiser,"RabbitMQ Visualiser","3.2.3"},
4
+ {rabbitmq_federation_management,"RabbitMQ Federation Management",
5
+ "3.2.3"},
6
+ {rabbitmq_management,"RabbitMQ Management Console","3.2.3"},
7
+ {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.2.3"},
8
+ {webmachine,"webmachine","1.10.3-rmq3.2.3-gite9359c7"},
9
+ {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.2.3-git680dba8"},
10
+ {rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.2.3"},
11
+ {rabbitmq_federation,"RabbitMQ Federation","3.2.3"},
12
+ {rabbitmq_stomp,"Embedded Rabbit Stomp Adapter","3.2.3"},
13
+ {rabbitmq_management_agent,"RabbitMQ Management Agent","3.2.3"},
14
+ {rabbitmq_amqp1_0,"AMQP 1.0 support for RabbitMQ","3.2.3"},
15
+ {rabbit,"RabbitMQ","3.2.3"},
16
+ {os_mon,"CPO CXC 138 46","2.2.13"},
17
+ {inets,"INETS CXC 138 49","5.9.6"},
18
+ {mnesia,"MNESIA CXC 138 12","4.10"},
19
+ {amqp_client,"RabbitMQ AMQP Client","3.2.3"},
20
+ {xmerl,"XML parser","1.3.4"},
21
+ {sasl,"SASL CXC 138 11","2.3.3"},
22
+ {stdlib,"ERTS CXC 138 10","1.19.3"},
23
+ {kernel,"ERTS CXC 138 10","2.16.3"}]},
24
+ {os,{unix,darwin}},
25
+ {erlang_version,
26
+ "Erlang R16B02 (erts-5.10.3) [source] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]\n"},
27
+ {memory,
28
+ [{total,26591584},
29
+ {connection_procs,2888},
30
+ {queue_procs,24800},
31
+ {plugins,193876},
32
+ {other_proc,8954688},
33
+ {mnesia,46916},
34
+ {mgmt_db,33156},
35
+ {msg_index,27588},
36
+ {other_ets,704724},
37
+ {binary,1619408},
38
+ {code,11103864},
39
+ {atom,568805},
40
+ {other_system,3310871}]},
41
+ {vm_memory_high_watermark,0.4},
42
+ {vm_memory_limit,858993459},
43
+ {disk_free_limit,50000000},
44
+ {disk_free,28775735296},
45
+ {file_descriptors,
46
+ [{total_limit,2460},
47
+ {total_used,5},
48
+ {sockets_limit,2212},
49
+ {sockets_used,3}]},
50
+ {processes,[{limit,1048576},{used,225}]},
51
+ {run_queue,0},
52
+ {uptime,11277}]
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe ErlangConfig do
4
+ context "when decoding an erlang config" do
5
+ it "should decode simple stuff correctly" do
6
+ erlang_string = '[{"x-max-hops",1},{"x-internal-purpose","federation"}]'
7
+ expect = [{"x-max-hops"=>1}, {"x-internal-purpose"=>"federation"}]
8
+ ErlangConfig.decode(erlang_string).should == expect
9
+ end
10
+
11
+ it "should decode rabbitmq status message without errors" do
12
+ erlang_string = File.read(File.expand_path('../data/rabbitmq_status.txt', __FILE__))
13
+ expect {
14
+ decoded = ErlangConfig.decode(erlang_string)
15
+ }.not_to raise_error
16
+ end
17
+ end
18
+
19
+ context "when encoding from a ruby hash" do
20
+ it "should encode correctly" do
21
+ ruby_hash = [{"x-max-hops"=>1}, {"x-internal-purpose"=>"federation"}]
22
+ expect = '[{"x-max-hops",1},{"x-internal-purpose","federation"}]'
23
+ # Erlang::Config.encode(ruby_hash).should == expect
24
+ pending "Encoding has not been implemented yet, pull requests welcome!"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require "erlang_config"
4
+
5
+ RSpec.configure do |config|
6
+ # some (optional) config here
7
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erlang_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Gaufman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ description: See summery
56
+ email:
57
+ - roman@xanview.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - erlang_config.gemspec
68
+ - lib/erlang_config.rb
69
+ - lib/erlang_config/erlatom.rb
70
+ - lib/erlang_config/erlbinary.rb
71
+ - lib/erlang_config/erllist.rb
72
+ - lib/erlang_config/erlnumeration.rb
73
+ - lib/erlang_config/erlpid.rb
74
+ - lib/erlang_config/erlref.rb
75
+ - lib/erlang_config/erlstring.rb
76
+ - lib/erlang_config/erlterm.rb
77
+ - lib/erlang_config/erltuple.rb
78
+ - lib/erlang_config/version.rb
79
+ - spec/data/rabbitmq_status.txt
80
+ - spec/erlang_config_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.2.0
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Encode and Decode Erlang style configuration files.
106
+ test_files:
107
+ - spec/data/rabbitmq_status.txt
108
+ - spec/erlang_config_spec.rb
109
+ - spec/spec_helper.rb
110
+ has_rdoc: