Class: Rubeus::Extensions::Java::Sql::DriverManager::Loader
- Inherits:
-
Object
- Object
- Rubeus::Extensions::Java::Sql::DriverManager::Loader
- Defined in:
- lib/rubeus/extensions/java/sql/driver_manager.rb,
lib/rubeus/extensions/java/sql/driver_manager.rb
Overview
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
Class Method Summary collapse
- .entries ⇒ Object
- .entry(name, *args, &block) ⇒ Object
- .setup_for(url, setup_options = nil) ⇒ Object
Instance Method Summary collapse
- #driver_for(url, driver_type = nil) ⇒ Object
-
#initialize(name) ⇒ Loader
constructor
A new instance of Loader.
- #options ⇒ Object
- #options=(value) ⇒ Object
- #pattern(pattern, driver, driver_type = :unknown) ⇒ Object
- #setup_for(url, setup_options = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Loader
Returns a new instance of Loader.
58 59 60 61 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 58 def initialize(name) @name = name @patterns = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
56 57 58 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 56 def name @name end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
56 57 58 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 56 def patterns @patterns end |
Class Method Details
.entries ⇒ Object
28 29 30 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 28 def entries @entries ||= [] end |
.entry(name, *args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 32 def entry(name, *args, &block) result = self.new(name) if block_given? result.instance_eval(&block) else pattern, driver, driver_type, = *args result.instance_eval do |db| db.pattern(pattern, driver, driver_type || :unknown) db. = end end entries << result result end |
.setup_for(url, setup_options = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 47 def setup_for(url, = nil) entries.each do |entry| driver = entry.setup_for(url, ) return driver if driver end raise ArgumentError, "DriverManager catalog not found for #{url}" end |
Instance Method Details
#driver_for(url, driver_type = nil) ⇒ Object
75 76 77 78 79 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 75 def driver_for(url, driver_type = nil) patterns = driver_type ? @patterns.select{|pattern| pattern[:driver_type] == driver_type} : @patterns pattern = patterns.detect{|pattern| pattern[:pattern] =~ url} pattern ? pattern[:driver] : nil end |
#options ⇒ Object
67 68 69 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 67 def @options ||= {} end |
#options=(value) ⇒ Object
71 72 73 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 71 def (value) @options = value end |
#pattern(pattern, driver, driver_type = :unknown) ⇒ Object
63 64 65 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 63 def pattern(pattern, driver, driver_type = :unknown) @patterns << {:pattern => pattern, :driver => driver, :driver_type => driver_type} end |
#setup_for(url, setup_options = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rubeus/extensions/java/sql/driver_manager.rb', line 81 def setup_for(url, = nil) driver_name = driver_for(url) return nil unless driver_name begin return JavaUtilities.get_proxy_class(driver_name) rescue NameError => name_error requirements = [:gem_require] raise name_error unless requirements requirements = [requirements] unless requirements.is_a?(Array) = [] requirements.each do |requirement| begin require(requirement) rescue LoadError => load_error msg = "failure to load '#{requirement}' of '#{[:gem]}'." msg << " Try 'jruby -S gem install #{[:gem]}'" unless /\.jar$/ =~ requirement << msg next end begin return JavaUtilities.get_proxy_class(driver_name) rescue NameError => name_error_again msg = "#{driver_name} not found for #{url}" msg << ", but loaded '#{requirement}' of '#{[:gem]}' successfully." msg << " It might be a serious problem. Please let us know by email '#{Rubeus::EMAIL_GROUP}'. " raise NameError, msg end end raise LoadError, "#{driver_name} not found for #{url} because of " << .join(" AND ") end end |