Class: Ree::LinkImportBuilder
- Defined in:
- lib/ree/dsl/link_import_builder.rb
Instance Method Summary collapse
-
#build(klass, package_name, object_name, proc) ⇒ ArrayOf[String]
List of names of imported constants.
-
#build_for_const(klass, source_const, proc) ⇒ ArrayOf[String]
List of names of imported constants.
-
#initialize(packages_facade) ⇒ LinkImportBuilder
constructor
A new instance of LinkImportBuilder.
Constructor Details
#initialize(packages_facade) ⇒ LinkImportBuilder
Returns a new instance of LinkImportBuilder.
4 5 6 |
# File 'lib/ree/dsl/link_import_builder.rb', line 4 def initialize(packages_facade) @packages_facade = packages_facade end |
Instance Method Details
#build(klass, package_name, object_name, proc) ⇒ ArrayOf[String]
Returns List of names of imported constants.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ree/dsl/link_import_builder.rb', line 13 def build(klass, package_name, object_name, proc) const_list, removed_constants = Ree::ImportDsl.new.execute(klass, proc) @packages_facade.load_package_object(package_name, object_name) package = @packages_facade.get_package(package_name) object = package.get_object(object_name) const_list.each do |const_obj| if object.klass.const_defined?(const_obj.name) set_const(klass, object.klass.const_get(const_obj.name), const_obj) elsif package.module.const_defined?(const_obj.name) set_const(klass, package.module.const_get(const_obj.name), const_obj) else raise Ree::Error.new("'#{const_obj.name}' is not found in :#{object.name}") end end assign_removed_constants(klass, removed_constants) const_list.map(&:name) end |
#build_for_const(klass, source_const, proc) ⇒ ArrayOf[String]
Returns List of names of imported constants.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ree/dsl/link_import_builder.rb', line 40 def build_for_const(klass, source_const, proc) const_list, removed_constants = Ree::ImportDsl.new.execute(klass, proc) mod_const = Object.const_get(source_const.name.split("::").first) const_list.each do |const_obj| if source_const.const_defined?(const_obj.name) set_const(klass, source_const.const_get(const_obj.name), const_obj) elsif mod_const.const_defined?(const_obj.name) set_const(klass, mod_const.const_get(const_obj.name), const_obj) else raise Ree::Error.new("'#{const_obj.name}' is not found in '#{source_const}'") end end assign_removed_constants(klass, removed_constants) nil end |