stark 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -120,7 +120,7 @@ namespace.
120
120
 
121
121
  ### Debugging
122
122
 
123
- Spark will output some valuable (albeit verbose) debugging information
123
+ Stark will output some valuable (albeit verbose) debugging information
124
124
  if you set the `STARK_DEBUG` environment variable.
125
125
 
126
126
  ```
data/Rakefile CHANGED
@@ -16,8 +16,8 @@ Hoe.spec 'stark' do
16
16
  readme_file = "README.md"
17
17
  end
18
18
 
19
+ desc 'Run kpeg to generate new parser'
19
20
  task :parser do
20
21
  sh "kpeg -o lib/stark/raw_parser.rb -s -f lib/stark/thrift.kpeg"
21
22
  end
22
-
23
23
  # vim: syntax=ruby
@@ -2,7 +2,7 @@ require 'thrift'
2
2
  require 'logger'
3
3
 
4
4
  module Stark
5
- VERSION = '0.8.0'
5
+ VERSION = '0.9.0'
6
6
 
7
7
  def self.logger
8
8
  @logger ||= ::Logger.new($stdout)
@@ -28,7 +28,7 @@ module Stark
28
28
  require 'stringio'
29
29
 
30
30
  begin
31
- contents = file.respond_to?(:read) ? file.read : File.read(file)
31
+ contents = Stark::Parser.read_file(file)
32
32
  ast = Stark::Parser.ast contents
33
33
  rescue => e
34
34
  raise e, e.message + " while processing #{file} -\n#{e.backtrace.join("\n")}"
@@ -1,6 +1,7 @@
1
1
  module Stark
2
2
  end
3
3
 
4
+ require 'set'
4
5
  require 'stark/raw_parser'
5
6
 
6
7
  class Stark::Parser
@@ -9,11 +10,11 @@ class Stark::Parser
9
10
 
10
11
  ast.each do |elem|
11
12
  case elem
12
- when AST::Include
13
- data = File.read elem.path
14
- out += expand(Stark::Parser.ast(data))
15
- else
16
- out << elem
13
+ when AST::Include
14
+ data = Stark::Parser.read_file(elem.path)
15
+ out += expand(Stark::Parser.ast(data))
16
+ else
17
+ out << elem
17
18
  end
18
19
  end
19
20
 
@@ -29,4 +30,16 @@ class Stark::Parser
29
30
  parser = Stark::Parser.new arg
30
31
  parser.ast
31
32
  end
33
+
34
+ def self.read_file(file)
35
+ @@include_path ||= Set.new([Dir.pwd])
36
+ if file.respond_to?(:read)
37
+ @@include_path << File.dirname(File.expand_path(file.path, Dir.pwd)) if file.respond_to?(:path)
38
+ return file.read
39
+ else
40
+ @@include_path << File.dirname(File.expand_path(file, Dir.pwd))
41
+ fn = (@@include_path.map { |path| File.expand_path(file, path) }.detect { |fn| File.exist?(fn) }) || file
42
+ File.read fn
43
+ end
44
+ end
32
45
  end
@@ -1669,7 +1669,7 @@ class Stark::Parser
1669
1669
  return _tmp
1670
1670
  end
1671
1671
 
1672
- # Element = (Comment | obsp Header bsp | Definition bsp)
1672
+ # Element = (Comment | obsp Header bsp | Definition obsp)
1673
1673
  def _Element
1674
1674
 
1675
1675
  _save = self.pos
@@ -1707,7 +1707,7 @@ class Stark::Parser
1707
1707
  self.pos = _save2
1708
1708
  break
1709
1709
  end
1710
- _tmp = apply(:_bsp)
1710
+ _tmp = apply(:_obsp)
1711
1711
  unless _tmp
1712
1712
  self.pos = _save2
1713
1713
  end
@@ -4049,7 +4049,7 @@ class Stark::Parser
4049
4049
  Rules[:_CaptureDocText] = rule_info("CaptureDocText", "{}")
4050
4050
  Rules[:_DestroyDocText] = rule_info("DestroyDocText", "{}")
4051
4051
  Rules[:_HeaderList] = rule_info("HeaderList", "(HeaderList Header | Header)")
4052
- Rules[:_Element] = rule_info("Element", "(Comment | obsp Header bsp | Definition bsp)")
4052
+ Rules[:_Element] = rule_info("Element", "(Comment | obsp Header bsp | Definition obsp)")
4053
4053
  Rules[:_Header] = rule_info("Header", "(Include | Namespace)")
4054
4054
  Rules[:_Namespace] = rule_info("Namespace", "(\"namespace\" - tok_identifier:l - tok_identifier:n {namespace(l,n)} | \"namespace\" - \"*\" - tok_identifier:n {namespace(nil,n)})")
4055
4055
  Rules[:_Include] = rule_info("Include", "\"include\" - tok_literal:f {include(f)}")
@@ -27,7 +27,14 @@ module Stark
27
27
  {}.tap do |hash|
28
28
  self.class.fields.each do |idx,name|
29
29
  v = send name
30
- hash[name] = v if v
30
+ case v
31
+ when Array
32
+ hash[name] = v.map(&:to_hash)
33
+ when Struct
34
+ hash[name] = v.to_hash
35
+ else
36
+ hash[name] = v if v
37
+ end
31
38
  end
32
39
  end
33
40
  end
@@ -187,7 +187,7 @@ HeaderList = HeaderList Header
187
187
 
188
188
  Element = Comment
189
189
  | obsp Header bsp
190
- | Definition bsp
190
+ | Definition obsp
191
191
 
192
192
  Header = Include | Namespace
193
193
 
@@ -12,4 +12,4 @@
12
12
  struct Foo {
13
13
  // one comment entry is allowed here, but not elsewhere inside the struct
14
14
  1: i32 id
15
- }
15
+ }
@@ -1 +1 @@
1
- include "test/blah.thrift"
1
+ include "blah.thrift"
@@ -138,6 +138,32 @@ EOM
138
138
  assert_equal({:str => "hi", :int => 20}, foo.to_hash)
139
139
  end
140
140
 
141
+ def test_to_struct_to_hash_nested
142
+ ruby = create_ruby <<-EOM, :only_ast => true
143
+ struct Bar {
144
+ 1: string blah
145
+ }
146
+ struct Quux {
147
+ 1: i32 int
148
+ }
149
+ struct Foo {
150
+ 1:string str
151
+ 2:list<Bar> bars
152
+ 3:i32 int
153
+ 4:Quux q
154
+ }
155
+ EOM
156
+
157
+ ns = Module.new
158
+ ns.module_eval ruby
159
+ assert ns::Foo
160
+
161
+ foo = ns::Foo.new :str => "hi", :int => 20
162
+ foo.bars = [ns::Bar.new(:blah => "baz")]
163
+ foo.q = ns::Quux.new(:int => 42)
164
+ assert_equal({:str => "hi", :int => 20, :bars => [{:blah => "baz"}], :q => {:int => 42}}, foo.to_hash)
165
+ end
166
+
141
167
  def test_to_struct_aref
142
168
  ruby = create_ruby <<-EOM, :only_ast => true
143
169
  struct Foo {
@@ -39,7 +39,7 @@ class TestStark < Test::Unit::TestCase
39
39
  assert @m.const_defined?(:FavoriteUsers)
40
40
  end
41
41
 
42
- def test_materialize_service_with_comments
42
+ def test_materialize_service_with_comments_and_no_ending_newline
43
43
  file_path = File.join(File.dirname(__FILE__), 'comments.thrift')
44
44
  assert_nothing_raised do
45
45
  Stark.materialize file_path, @m
@@ -64,4 +64,12 @@ class TestStark < Test::Unit::TestCase
64
64
  assert @m.const_defined?(:Types)
65
65
  end
66
66
 
67
+ def test_include_in_same_dir_not_working_dir
68
+ Dir.chdir(File.dirname(__FILE__) + '/../') do
69
+ file_path = File.join(File.dirname(__FILE__), 'include_blah.thrift')
70
+ assert_nothing_raised do
71
+ Stark.materialize file_path, @m
72
+ end
73
+ end
74
+ end
67
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-22 00:00:00.000000000 Z
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thrift
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '4.0'
37
+ version: '3.10'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '4.0'
45
+ version: '3.10'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: hoe
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '3.6'
53
+ version: '3.5'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '3.6'
61
+ version: '3.5'
62
62
  description: Optimized thrift bindings for ruby.
63
63
  email:
64
64
  - evan@phx.io
@@ -68,8 +68,6 @@ extensions: []
68
68
  extra_rdoc_files:
69
69
  - History.txt
70
70
  - Manifest.txt
71
- - README.md
72
- - examples/README.md
73
71
  files:
74
72
  - .autotest
75
73
  - .gemtest
@@ -142,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
140
  version: '0'
143
141
  requirements: []
144
142
  rubyforge_project: stark
145
- rubygems_version: 1.8.23
143
+ rubygems_version: 1.8.25
146
144
  signing_key:
147
145
  specification_version: 3
148
146
  summary: Optimized thrift bindings for ruby.