Class: Thrifty::Manager
- Inherits:
-
Object
- Object
- Thrifty::Manager
- Defined in:
- lib/thrifty/manager.rb
Instance Attribute Summary collapse
-
#build_root ⇒ Object
Returns the value of attribute build_root.
Instance Method Summary collapse
- #compile_all ⇒ Object
- #include_path ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #register(path, options = {}) ⇒ Object
- #require(generated_file) ⇒ Object
- #require_path ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
4 5 6 7 |
# File 'lib/thrifty/manager.rb', line 4 def initialize @thrift_files = {} @build_root ||= File.join(Dir.tmpdir, 'build-thrifty') end |
Instance Attribute Details
#build_root ⇒ Object
Returns the value of attribute build_root.
2 3 4 |
# File 'lib/thrifty/manager.rb', line 2 def build_root @build_root end |
Instance Method Details
#compile_all ⇒ Object
36 37 38 39 40 41 |
# File 'lib/thrifty/manager.rb', line 36 def compile_all @thrift_files.map do |_, thrift_file| built = thrift_file.compile_once [thrift_file, built] end end |
#include_path ⇒ Object
43 44 45 |
# File 'lib/thrifty/manager.rb', line 43 def include_path @thrift_files.keys.map {|f| File.dirname(f)}.uniq end |
#register(path, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/thrifty/manager.rb', line 9 def register(path, ={}) thrift_file = Thrifty::ThriftFile.new(self, path, ) thrift_file.validate_existence if @thrift_files.include?(thrift_file.path) raise "File already registered: #{thrift_file.path}" end @thrift_files[thrift_file.path] = thrift_file thrift_file end |
#require(generated_file) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/thrifty/manager.rb', line 21 def require(generated_file) definers = @thrift_files.values.select do |thrift_file| thrift_file.defines?(generated_file) end if definers.length == 0 raise LoadError, "No registered thrift file defines #{generated_file.inspect}. Perhaps you forgot to run `Thrifty.register(thrift_file)`?" elsif definers.length == 1 definer = definers.first definer.require(generated_file) else raise LoadError, "Ambiguous generated file #{generated_file.inspect} defined in #{definers.map {|definer| definer.thrift_file.inspect}.join(', ')}" end end |
#require_path ⇒ Object
47 48 49 |
# File 'lib/thrifty/manager.rb', line 47 def require_path @thrift_files.values.map(&:build_directory).uniq end |