rubyang 0.1.2.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: bc6990db46836bbcca07ed7e7b1bc4bb5a183e94cbeb7f7c671bcdb18e5bd454
4
- data.tar.gz: 931778007ac7f6070a356fb23f52f82eab0abd2989e55f156f6bc3ec02279ae5
2
+ SHA1:
3
+ metadata.gz: f1077d7b202071724495876ca2ac2a0d0c94291b
4
+ data.tar.gz: 8a5a8311e3ee8b649f1600450f8fbac074bb3780
5
5
  SHA512:
6
- metadata.gz: 222f20d73796fa606bd7eebe671acf4ce92ec5c5685cab59ea25d8dcb935bd6486cd2565a640e250c042dce92bb6902637bbf49cba5359e204a72ee976953891
7
- data.tar.gz: bfb45f1c46df476d7584c35811f2c2c0d8befac3fd07f1bd6c3029992291c5866f7839cfcd2032825bd799e759c3f7b79344b93bb861b791152ad0f98092871f
6
+ metadata.gz: be32311e6fa9a114418aba7fa9ed57e69502488ae433b22906bcfaf49e9e05809181792c636707bb82d243b28a16148c595c9023b48ff742ac216a15801b24c1
7
+ data.tar.gz: 21b3d0ef30a342af19317e540cb397ef8894075ae437c5838a92c0e78af35dcdb0c8971fb6803ccb9b04df87a034c965e9508fdeee0b9982cf398228be344167
data/.gitignore CHANGED
@@ -10,6 +10,9 @@
10
10
  /test/version_tmp/
11
11
  /tmp/
12
12
 
13
+ # rspec failure tracking
14
+ .rspec_status
15
+
13
16
  ## Specific to RubyMotion:
14
17
  .dat*
15
18
  .repl_history
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
data/.travis.yml CHANGED
@@ -4,7 +4,12 @@ env:
4
4
  sudo: false
5
5
  language: ruby
6
6
  rvm:
7
- - 2.5.0
7
+ - 2.0
8
+ - 2.1
9
+ - 2.2
10
+ - 2.3
11
+ - 2.4
12
+ - 2.5
8
13
  before_install: gem install bundler -v 1.16.1
9
14
  install: bundle install --path vendor/bundle
10
15
  before_script:
@@ -13,7 +18,5 @@ before_script:
13
18
  - ./cc-test-reporter before-build
14
19
  script:
15
20
  - bundle exec rake spec
16
- - bundle exec rake build
17
21
  after_script:
18
22
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
19
-
data/lib/rubyang.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
 
3
- require_relative 'rubyang/version'
4
-
5
- require_relative 'rubyang/logger'
6
- require_relative 'rubyang/model'
7
- require_relative 'rubyang/xpath'
8
- require_relative 'rubyang/database'
3
+ require 'rubyang/version'
4
+ require 'rubyang/compat'
5
+ require 'rubyang/model'
6
+ require 'rubyang/xpath'
7
+ require 'rubyang/database'
9
8
 
10
9
  module Rubyang
11
10
  end
data/lib/rubyang/cli.rb CHANGED
@@ -1,131 +1,131 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
4
  require 'drb/drb'
4
5
  require 'readline'
5
-
6
- require_relative '../rubyang'
7
- require_relative 'cli/parser'
6
+ require 'rubyang'
7
+ require 'rubyang/cli/parser'
8
8
 
9
9
  module Rubyang
10
- class Cli
11
- def initialize
12
- @sock_file = "/tmp/rubyang/server/Example.sock"
13
- @db = DRbObject.new_with_uri( "drbunix:#{@sock_file}" )
10
+ class Cli
11
+ def initialize
12
+ @sock_file = "/tmp/rubyang/server/Example.sock"
13
+ @db = DRbObject.new_with_uri( "drbunix:#{@sock_file}" )
14
14
 
15
- @config_tree = @db.configure
15
+ @config_tree = @db.configure
16
16
 
17
- @fo = File.open("#{File.dirname(__FILE__)}/cli/log.txt", 'w')
18
- @fo.sync = true
17
+ @fo = File.open("#{File.dirname(__FILE__)}/cli/log.txt", 'w')
18
+ @fo.sync = true
19
19
 
20
- #Readline.basic_word_break_characters = ""
21
- #Readline.completer_word_break_characters = ""
22
- Readline.completion_append_character = " "
23
- Readline.completion_proc = proc { |buf|
24
- @fo.puts "line_buffer: #{Readline.line_buffer}"
25
- begin
26
- tokens = Rubyang::Cli::Parser.parse( Readline.line_buffer )
27
- rescue
28
- next
29
- end
30
- command_type = tokens.shift
31
- case command_type
32
- when /^set$/
33
- if tokens.size == 0
34
- all_candidates = ['set']
35
- candidates = all_candidates
36
- else
37
- value = tokens.last.to_s
38
- all_candidates = get_candidates( @config_tree, tokens )
39
- candidates = all_candidates.grep(/^#{Regexp.escape(value.to_s)}/)
40
- end
41
- when /^show$/
42
- format = tokens[0].to_s
43
- all_candidates = ['xml', 'json']
44
- candidates = all_candidates.grep(/^#{Regexp.escape(format.to_s)}/)
45
- candidates
46
- else
47
- all_candidates = ['set', 'show']
48
- candidates = all_candidates.grep(/^#{Regexp.escape(command_type.to_s)}/)
49
- candidates
50
- end
51
- @fo.puts "tokens = #{tokens.inspect}"
52
- @fo.puts "all_candidates = #{all_candidates.inspect}"
53
- @fo.puts "candidates = #{candidates.inspect}"
54
- @fo.puts
55
- @fo.puts
56
- candidates
57
- }
58
- end
20
+ #Readline.basic_word_break_characters = ""
21
+ #Readline.completer_word_break_characters = ""
22
+ Readline.completion_append_character = " "
23
+ Readline.completion_proc = proc { |buf|
24
+ @fo.puts "line_buffer: #{Readline.line_buffer}"
25
+ begin
26
+ tokens = Rubyang::Cli::Parser.parse( Readline.line_buffer )
27
+ rescue
28
+ next
29
+ end
30
+ command_type = tokens.shift
31
+ case command_type
32
+ when /^set$/
33
+ if tokens.size == 0
34
+ all_candidates = ['set']
35
+ candidates = all_candidates
36
+ else
37
+ value = tokens.last.to_s
38
+ all_candidates = get_candidates( @config_tree, tokens )
39
+ candidates = all_candidates.grep(/^#{Regexp.escape(value.to_s)}/)
40
+ end
41
+ when /^show$/
42
+ format = tokens[0].to_s
43
+ all_candidates = ['xml', 'json']
44
+ candidates = all_candidates.grep(/^#{Regexp.escape(format.to_s)}/)
45
+ candidates
46
+ else
47
+ all_candidates = ['set', 'show']
48
+ candidates = all_candidates.grep(/^#{Regexp.escape(command_type.to_s)}/)
49
+ candidates
50
+ end
51
+ @fo.puts "tokens = #{tokens.inspect}"
52
+ @fo.puts "all_candidates = #{all_candidates.inspect}"
53
+ @fo.puts "candidates = #{candidates.inspect}"
54
+ @fo.puts
55
+ @fo.puts
56
+ candidates
57
+ }
58
+ end
59
59
 
60
- def set config_tree, tokens
61
- set_recursive config_tree, tokens
62
- end
60
+ def set config_tree, tokens
61
+ set_recursive config_tree, tokens
62
+ end
63
63
 
64
- def set_recursive config_tree, tokens
65
- return config_tree if tokens.size == 0
66
- token = tokens[0]
67
- case tokens[1..-1].size
68
- when 0
69
- config_tree.set token
70
- else
71
- child_tree = config_tree.edit token
72
- set_recursive child_tree, tokens[1..-1]
73
- end
74
- end
64
+ def set_recursive config_tree, tokens
65
+ return config_tree if tokens.size == 0
66
+ token = tokens[0]
67
+ case tokens[1..-1].size
68
+ when 0
69
+ config_tree.set token
70
+ else
71
+ child_tree = config_tree.edit token
72
+ set_recursive child_tree, tokens[1..-1]
73
+ end
74
+ end
75
75
 
76
- def get_candidates config_tree, tokens
77
- @fo.puts config_tree.class
78
- @fo.puts tokens.inspect
79
- token = tokens[0].to_s
80
- case config_tree
81
- when Rubyang::Database::DataTree::Leaf
82
- if tokens.size == 1
83
- [config_tree.value]
84
- else
85
- []
86
- end
87
- else
88
- if tokens.size > 1 and config_tree.schema.children.map{ |c| c.arg }.include? token
89
- child_tree = config_tree.edit token
90
- get_candidates child_tree, tokens[1..-1]
91
- else
92
- config_tree.schema.children.map{ |c| c.arg }
93
- end
94
- end
95
- end
76
+ def get_candidates config_tree, tokens
77
+ @fo.puts config_tree.class
78
+ @fo.puts tokens.inspect
79
+ token = tokens[0].to_s
80
+ case config_tree
81
+ when Rubyang::Database::DataTree::Leaf
82
+ if tokens.size == 1
83
+ [config_tree.value]
84
+ else
85
+ []
86
+ end
87
+ else
88
+ if tokens.size > 1 and config_tree.schema.children.map{ |c| c.arg }.include? token
89
+ child_tree = config_tree.edit token
90
+ get_candidates child_tree, tokens[1..-1]
91
+ else
92
+ config_tree.schema.children.map{ |c| c.arg }
93
+ end
94
+ end
95
+ end
96
96
 
97
- def run
98
- while buf = Readline.readline("> ", true)
99
- tokens = Rubyang::Cli::Parser.parse( buf )
100
- command_type = tokens.shift
101
- case command_type
102
- when /^set$/
103
- begin
104
- set @config_tree, tokens
105
- rescue => e
106
- puts "Error: #{e}"
107
- end
108
- when /^show$/
109
- show_type = tokens.shift
110
- case show_type
111
- when /^xml$/
112
- puts @config_tree.to_xml( pretty: true )
113
- when /^json$/
114
- puts @config_tree.to_json( pretty: true )
115
- end
116
- when /^commit$/
117
- begin
118
- @config_tree.commit
119
- rescue => e
120
- puts "Error: #{e}"
121
- end
122
- end
123
- end
124
- end
125
- end
97
+ def run
98
+ while buf = Readline.readline("> ", true)
99
+ tokens = Rubyang::Cli::Parser.parse( buf )
100
+ command_type = tokens.shift
101
+ case command_type
102
+ when /^set$/
103
+ begin
104
+ set @config_tree, tokens
105
+ rescue => e
106
+ puts "Error: #{e}"
107
+ end
108
+ when /^show$/
109
+ show_type = tokens.shift
110
+ case show_type
111
+ when /^xml$/
112
+ puts @config_tree.to_xml( pretty: true )
113
+ when /^json$/
114
+ puts @config_tree.to_json( pretty: true )
115
+ end
116
+ when /^commit$/
117
+ begin
118
+ @config_tree.commit
119
+ rescue => e
120
+ puts "Error: #{e}"
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
126
  end
127
127
 
128
128
  if __FILE__ == $0
129
- cli = Rubyang::Cli.new
130
- cli.run
129
+ cli = Rubyang::Cli.new
130
+ cli.run
131
131
  end
@@ -1,74 +1,74 @@
1
1
  # coding: utf-8
2
+ # vim: et ts=2 sw=2
2
3
 
3
4
  require 'strscan'
4
-
5
- #require_relative 'parser/parser.tab.rb'
5
+ #require 'rubyang/cli/parser/parser.tab.rb'
6
6
 
7
7
  module Rubyang
8
- class Cli
9
- class Parser
10
- def self.parse( str )
11
- parser = self.new
12
- parser.parse( str )
13
- end
8
+ class Cli
9
+ class Parser
10
+ def self.parse( str )
11
+ parser = self.new
12
+ parser.parse( str )
13
+ end
14
14
 
15
- def initialize
16
- end
15
+ def initialize
16
+ end
17
17
 
18
- def parse( str )
19
- @tokens = Array.new
18
+ def parse( str )
19
+ @tokens = Array.new
20
20
 
21
- s = StringScanner.new( str )
21
+ s = StringScanner.new( str )
22
22
 
23
- keywords = {
24
- }
23
+ keywords = {
24
+ }
25
25
 
26
- scanre_list = [
27
- ["dqstr", /^"(?:[^"]|\\.)*"/],
28
- ["sqstr", /^'(?:[^']|\\.)*'/],
29
- ["nqstr", /^[a-zA-Z0-9:\/\|\.=_-]+/],
30
- ["wsp", /^[ \t]+/],
31
- ]
32
- scanres = scanre_list.to_h
26
+ scanre_list = [
27
+ ["dqstr", /^"(?:[^"]|\\.)*"/],
28
+ ["sqstr", /^'(?:[^']|\\.)*'/],
29
+ ["nqstr", /^[a-zA-Z0-9:\/\|\.=_-]+/],
30
+ ["wsp", /^[ \t]+/],
31
+ ]
32
+ scanres = scanre_list.to_h
33
33
 
34
- scanre = Regexp.union( scanre_list.map{ |scanre| scanre[1] } )
34
+ scanre = Regexp.union( scanre_list.map{ |scanre| scanre[1] } )
35
35
 
36
- last = ''
37
- until s.eos?
38
- token = s.scan( scanre )
39
- case token
40
- when scanres["dqstr"] then
41
- token_ = token.gsub(/^"/,'').gsub(/"$/,'').gsub(/\\n/,"\n").gsub(/\\t/,"\t").gsub(/\\"/,"\"").gsub(/\\\\/,"\\")
42
- @tokens.push token_
43
- last = "dqstr"
44
- when scanres["sqstr"] then
45
- token_ = token.gsub(/^'/,'').gsub(/'$/,'')
46
- @tokens.push token_
47
- last = "sqstr"
48
- when scanres["nqstr"] then
49
- @tokens.push token
50
- last = "nqstr"
51
- when scanres["wsp"] then
52
- last = "wsp"
53
- else raise "token not match to any scanres: #{token.inspect}"
54
- end
55
- end
56
- if last == "wsp"
57
- @tokens.push ''
58
- end
36
+ last = ''
37
+ until s.eos?
38
+ token = s.scan( scanre )
39
+ case token
40
+ when scanres["dqstr"] then
41
+ token_ = token.gsub(/^"/,'').gsub(/"$/,'').gsub(/\\n/,"\n").gsub(/\\t/,"\t").gsub(/\\"/,"\"").gsub(/\\\\/,"\\")
42
+ @tokens.push token_
43
+ last = "dqstr"
44
+ when scanres["sqstr"] then
45
+ token_ = token.gsub(/^'/,'').gsub(/'$/,'')
46
+ @tokens.push token_
47
+ last = "sqstr"
48
+ when scanres["nqstr"] then
49
+ @tokens.push token
50
+ last = "nqstr"
51
+ when scanres["wsp"] then
52
+ last = "wsp"
53
+ else raise "token not match to any scanres: #{token.inspect}"
54
+ end
55
+ end
56
+ if last == "wsp"
57
+ @tokens.push ''
58
+ end
59
59
 
60
- #result = self.do_parse
61
- return @tokens
62
- end
60
+ #result = self.do_parse
61
+ return @tokens
62
+ end
63
63
 
64
- def next_token
65
- #p @tokens.first
66
- @tokens.shift
67
- end
68
- end
69
- end
64
+ def next_token
65
+ #p @tokens.first
66
+ @tokens.shift
67
+ end
68
+ end
69
+ end
70
70
  end
71
71
 
72
72
  if __FILE__ == $0
73
- p Rubyang::Cli::Parser.parse "set aaa "
73
+ p Rubyang::Cli::Parser.parse "set aaa "
74
74
  end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ if RUBY_VERSION < "2.1"
5
+ class Array
6
+ def to_h
7
+ h = Hash.new
8
+ self.each do |k, v|
9
+ h[k] = v
10
+ end
11
+ h
12
+ end
13
+ end
14
+ end