thrifty 0.0.3 → 0.0.4

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.
@@ -0,0 +1,4 @@
1
+ # This file exists so that loaded thrift files can successfully
2
+ # require thrift.
3
+ #
4
+ # I'd love a better solution than this.
@@ -5,6 +5,8 @@ require 'rubysh'
5
5
  class Thrifty::ThriftFile
6
6
  include Chalk::Log
7
7
 
8
+ DUMMY_DIRECTORY = File.expand_path('../dummy', __FILE__)
9
+
8
10
  attr_reader :relative_path, :options
9
11
 
10
12
  def initialize(manager, relative_path, options={})
@@ -28,21 +30,24 @@ class Thrifty::ThriftFile
28
30
 
29
31
  def require(generated_file)
30
32
  compile_once
31
- $:.unshift(build_directory)
33
+
34
+ # This is a bit dicey, as a generated thrift <file> will also
35
+ # include <file>_types and <file>_constants as well as
36
+ # 'thrift'. We need to make sure we can handle file names that may
37
+ # have already been required -- this path munging should
38
+ # successfully do so.
39
+
40
+ super('thrift')
41
+
42
+ orig_load_path = $:.dup
32
43
 
33
44
  begin
34
- log.info('Requiring', file: generated_file, idl: path)
45
+ $:[0..-1] = [build_directory, DUMMY_DIRECTORY]
46
+ log.info('Requiring', file: generated_file, idl: path, build_directory: build_directory)
35
47
  # Global require
36
48
  super(generated_file)
37
49
  ensure
38
- # Not sure what to do if someone changed $: in the
39
- # meanwhile. Could happen due a signal handler or something
40
- # crazy like that.
41
- if $:.first == build_directory
42
- $:.shift
43
- else
44
- log.error('Unexpected first element in load path; not removing', build_directory: build_directory, load_path: $:.inspect)
45
- end
50
+ $:[0..-1] = orig_load_path
46
51
  end
47
52
  end
48
53
 
@@ -53,7 +58,6 @@ class Thrifty::ThriftFile
53
58
  end
54
59
  end
55
60
 
56
-
57
61
  def version_file
58
62
  File.join(build_directory, 'VERSION')
59
63
  end
@@ -1,3 +1,3 @@
1
1
  module Thrifty
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,2 @@
1
+ /data
2
+ /thrifty
@@ -0,0 +1,10 @@
1
+ namespace rb ThriftyTest
2
+ struct UserProfile {
3
+ 1: i32 uid,
4
+ 2: string name,
5
+ 3: string blurb
6
+ }
7
+ service Collision {
8
+ void store(1: UserProfile user),
9
+ UserProfile retrieve(1: i32 uid)
10
+ }
@@ -6,6 +6,8 @@ require 'chalk-tools'
6
6
  # TODO: can we get by without quite so much rm -rf'ing?
7
7
 
8
8
  class Thrifty::DynamicTest < Critic::Functional::Test
9
+ DATA_DIR = File.expand_path('../_lib/thrift/data', __FILE__)
10
+
9
11
  def self.it_isolated(description, &blk)
10
12
  method = Chalk::Tools::ClassUtils.generate_method('test block', self, blk)
11
13
 
@@ -49,6 +51,18 @@ class Thrifty::DynamicTest < Critic::Functional::Test
49
51
 
50
52
  assert(File.exists?(expected_root))
51
53
  end
54
+
55
+ it_isolated 'allows thrift services with already-required names' do
56
+ FileUtils.mkdir_p(DATA_DIR)
57
+ File.write(File.join(DATA_DIR, 'collision.rb'), '# collision')
58
+ $:.unshift(DATA_DIR)
59
+ require 'collision'
60
+
61
+ Thrifty.register(File.expand_path('../_lib/thrift/collision.thrift', __FILE__))
62
+ required = Thrifty.require('collision')
63
+ assert(required)
64
+ ThriftyTest::Collision
65
+ end
52
66
  end
53
67
  end
54
68
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrifty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-11-29 00:00:00.000000000 Z
12
+ date: 2013-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -172,11 +172,14 @@ files:
172
172
  - examples/userdb/server.rb
173
173
  - examples/userdb/service.thrift
174
174
  - lib/thrifty.rb
175
+ - lib/thrifty/dummy/thrift.rb
175
176
  - lib/thrifty/manager.rb
176
177
  - lib/thrifty/thrift_file.rb
177
178
  - lib/thrifty/version.rb
178
179
  - test/_lib.rb
179
180
  - test/functional/_lib.rb
181
+ - test/functional/_lib/thrift/.gitignore
182
+ - test/functional/_lib/thrift/collision.thrift
180
183
  - test/functional/_lib/thrift/service.thrift
181
184
  - test/functional/thrifty.rb
182
185
  - test/integration/_lib.rb
@@ -197,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
200
  version: '0'
198
201
  segments:
199
202
  - 0
200
- hash: 1830425111965813571
203
+ hash: 287513174984063520
201
204
  required_rubygems_version: !ruby/object:Gem::Requirement
202
205
  none: false
203
206
  requirements:
@@ -206,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
209
  version: '0'
207
210
  segments:
208
211
  - 0
209
- hash: 1830425111965813571
212
+ hash: 287513174984063520
210
213
  requirements: []
211
214
  rubyforge_project:
212
215
  rubygems_version: 1.8.23
@@ -217,6 +220,8 @@ summary: Begone manual compilation of Thrift definitions! Thrifty makes it easy
217
220
  test_files:
218
221
  - test/_lib.rb
219
222
  - test/functional/_lib.rb
223
+ - test/functional/_lib/thrift/.gitignore
224
+ - test/functional/_lib/thrift/collision.thrift
220
225
  - test/functional/_lib/thrift/service.thrift
221
226
  - test/functional/thrifty.rb
222
227
  - test/integration/_lib.rb