Class: NCC::Connection
- Inherits:
-
Object
- Object
- NCC::Connection
- Defined in:
- lib/ncc/connection.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#fog ⇒ Object
readonly
Returns the value of attribute fog.
Class Method Summary collapse
Instance Method Summary collapse
- #collection(type, key = nil) ⇒ Object
- #communication_error(message) ⇒ Object
- #connection_params ⇒ Object
- #console_log(instance_id) ⇒ Object
- #create_instance(instance_spec, wait_for_ip = 60) ⇒ Object
- #current? ⇒ Boolean
- #debug(msg = nil) ⇒ Object
- #delete(instance_id) ⇒ Object
- #do_connect ⇒ Object
- #do_fog ⇒ Object
- #fields(obj, *flist) ⇒ Object
- #generic_provider_request(instance) ⇒ Object
- #generic_translate(abstract_object_type, provider_object) ⇒ Object
- #get_provider_object(provider_object_spec) ⇒ Object
- #get_provider_objects(type) ⇒ Object
- #host_fqdn(host) ⇒ Object
- #id_field(abstract_object_type) ⇒ Object
- #id_map(type) ⇒ Object
-
#id_map_hash(h) ⇒ Object
Something like “images” => { “$abstract_id” => x } can have an x where it’s the provider id, or an x which is a hash.
- #id_of(abstract_object_type, obj) ⇒ Object
- #ids(a) ⇒ Object
- #images(image_id = nil) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(ncc, cloud, opt = {}) ⇒ Connection
constructor
A new instance of Connection.
- #instance_for(server) ⇒ Object
- #instance_host(server) ⇒ Object
- #instance_image(server) ⇒ Object
- #instance_ip_address(server) ⇒ Object
- #instance_name(server) ⇒ Object
- #instance_not_found(instance_id) ⇒ Object
- #instance_size(server) ⇒ Object
- #instance_status(server) ⇒ Object
- #instances(instance_id = nil) ⇒ Object
- #inventory_request(instance) ⇒ Object
- #keyintern(h) ⇒ Object
- #keyname_for(type) ⇒ Object
-
#map_from_raw_provider_id(type, raw_provider_id) ⇒ Object
raw meaning not using “our” notion of id_field.
- #map_to_id(type, provider_id) ⇒ Object
- #map_to_provider_id(type, abstract_id) ⇒ Object
- #map_to_provider_status(abstract_status) ⇒ Object
- #map_to_status(provider_status) ⇒ Object
- #maybe_invalidate(type) ⇒ Object
- #me ⇒ Object
- #merge_configured(abstract_object, data) ⇒ Object
- #modify_instance_request(instance) ⇒ Object
- #notice(msg) ⇒ Object
- #object_of(abstract_object_type, provider_object) ⇒ Object
- #provider ⇒ Object
- #provider_id_map(type) ⇒ Object
- #provider_request(instance) ⇒ Object
- #provider_request_of(instance) ⇒ Object
- #reboot(instance_id) ⇒ Object
- #sizes(size_id = nil) ⇒ Object
- #to_s ⇒ Object
- #translate(abstract_object_type, provider_object) ⇒ Object
- #translated_id_of(abstract_object_type, obj) ⇒ Object
-
#use_only_mapped(type) ⇒ Object
Warning.
- #warn(msg) ⇒ Object
Constructor Details
#initialize(ncc, cloud, opt = {}) ⇒ Connection
Returns a new instance of Connection.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ncc/connection.rb', line 43 def initialize(ncc, cloud, opt={}) @ncc = ncc @cache = { } @cfg = ncc.config @cfg_mtime = @cfg.mtime @cloud = cloud @logger = opt[:logger] if opt.has_key? :logger @cache_timeout = opt[:cache_timeout] || 600 @auth_retry_limit = opt[:auth_retry_limit] || 1 do_connect end |
Instance Attribute Details
#fog ⇒ Object (readonly)
Returns the value of attribute fog.
28 29 30 |
# File 'lib/ncc/connection.rb', line 28 def fog @fog end |
Class Method Details
.connect(ncc, cloud = :default, opt = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ncc/connection.rb', line 30 def self.connect(ncc, cloud=:default, opt={}) cfg = ncc.config provider = cfg[:clouds][cloud]['provider'] case provider when 'aws' require 'ncc/connection/aws' NCC::Connection::AWS.new(ncc, cloud, opt) when 'openstack' require 'ncc/connection/openstack' NCC::Connection::OpenStack.new(ncc, cloud, opt) end end |
Instance Method Details
#collection(type, key = nil) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/ncc/connection.rb', line 290 def collection(type, key=nil) maybe_invalidate type @cache[type] ||= { :timestamp => Time.now, :data => Hash[get_provider_objects(type).map { |o| [o.id, o] }] } if key.nil? @cache[type][:data].values else @cache[type][:data][key] end end |
#communication_error(message) ⇒ Object
552 553 554 555 556 |
# File 'lib/ncc/connection.rb', line 552 def communication_error() = "Error communicating with #{provider} cloud #{@cloud}: " + unless /Error .*communicating with/.match() raise NCC::Error::Cloud, end |
#connection_params ⇒ Object
100 101 102 |
# File 'lib/ncc/connection.rb', line 100 def connection_params [] end |
#console_log(instance_id) ⇒ Object
576 577 578 579 |
# File 'lib/ncc/connection.rb', line 576 def console_log(instance_id) raise NCC::Error::NotFound, "Cloud #{@cloud} provider " + "#{provider} does not support console logs" end |
#create_instance(instance_spec, wait_for_ip = 60) ⇒ Object
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/ncc/connection.rb', line 488 def create_instance(instance_spec, wait_for_ip=60) if ! instance_spec.kind_of? NCC::Instance instance_spec = NCC::Instance.new(@cfg, instance_spec) end req_id = ['ncc', @cloud, UUIDTools::UUID.random_create.to_s].join('-') begin info "#{@cloud} requesting name from inventory using #{req_id}" fqdn = @ncc.inventory.get_or_assign_system_name(req_id)['fqdn'] rescue StandardError => e raise NCC::Error::Cloud, "Error [#{e.class}] " + "communicating with inventory to " + "assign name using (ncc_req_id=#{req_id}): #{e.}" end instance_spec.name = fqdn begin req = provider_request(instance_spec) t0 = Time.now info "#{@cloud} sending request: #{req.inspect}" server = do_fog { |fog| fog.servers.create(req) } # The reason we wait for an IP is so we can add it to # inventory, which then calculates the datacenter if wait_for_ip > 0 and instance_ip_address(server).nil? info "#{@cloud} waiting for ip on #{server.id}" this = self server.wait_for(wait_for_ip) { this.instance_ip_address(server) } end rescue StandardError => err inv_update = { 'fqdn' => fqdn, 'status' => 'decommissioned' } if ! server.nil? and server.id inv_update['serial_number'] = server.id end @ncc.inventory.update('system', inv_update, fqdn) server_id = (server.nil? ? 'nil' : server.id) communication_error "[#{err.class}] (ncc_req_id=#{req_id} " + "instance_id=#{server_id}): #{err.}" end elapsed = Time.now - t0 info "Created instance instance_id=#{server.id} at #{provider} cloud #{@cloud} in #{elapsed}s" instance = instance_for server instance_spec.id = instance.id instance_spec.ip_address = instance.ip_address instance_spec.host = instance.host inv_req = inventory_request(instance_spec) inv_req['cloud'] = @cloud inv_req['status'] = 'building' begin info "#{@cloud} updating inventory #{fqdn}/#{req_id} -> #{inv_req.inspect}" @ncc.inventory.update('system', inv_req, fqdn) rescue StandardError => e raise NCC::Error::Cloud, "Error [#{e.class}] updating inventory " + "system #{fqdn} " + "(cloud=#{@cloud} ncc_req_id=#{req_id} " + "instance_id=#{server.id}): " + e. end instance end |
#current? ⇒ Boolean
55 56 57 58 |
# File 'lib/ncc/connection.rb', line 55 def current? provider == @cfg[:clouds][@cloud]['provider'] and @cfg_mtime == @cfg[:clouds][@cloud].mtime end |
#debug(msg = nil) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/ncc/connection.rb', line 81 def debug(msg=nil) msg ||= yield if block_given? if @logger and @logger.respond_to? :debug @logger.debug "#{self} #{msg}" end end |
#delete(instance_id) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/ncc/connection.rb', line 558 def delete(instance_id) server = do_fog { |fog| fog.servers.get(instance_id) } if server.nil? instance_not_found instance_id else begin instance = instance_for server server.destroy inv_update = { 'fqdn' => instance.name, 'status' => 'decommissioned' } @ncc.inventory.update('system', inv_update, instance.name) rescue StandardError => e communication_error "deleting fqdn=#{instance.name} " + "instance_id=#{server.id}: #{e.}" end end end |
#do_connect ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/ncc/connection.rb', line 104 def do_connect cloud_config = @cfg[:clouds][@cloud] pnames = connection_params + ['provider'] params = Hash[cloud_config.to_hash(*pnames).map do |k, v| [k.intern, v] end ] @fog = Fog::Compute.new(params) end |
#do_fog ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ncc/connection.rb', line 113 def do_fog do_connect unless @fog remaining_tries = @auth_retry_limit begin yield @fog rescue Excon::Errors::Unauthorized => err # might be an expired auth token, retry if remaining_tries > 0 do_connect remaining_tries -= 1 retry else @fog = nil raise NCC::Error::Cloud, "Error communicating with #{provider} " + "cloud #{@cloud} (#{e.class}): #{e.}" end rescue NCC::Error::Cloud => err @fog = nil raise err rescue NCC::Error => err raise err rescue StandardError => err @fog = nil raise NCC::Error::Cloud, "Error communicating with #{provider} " + "cloud #{@cloud} [#{err.class}]: #{err.}" end end |
#fields(obj, *flist) ⇒ Object
147 148 149 |
# File 'lib/ncc/connection.rb', line 147 def fields(obj, *flist) Hash[flist.map { |f| [f, obj.send(f)] }] end |
#generic_provider_request(instance) ⇒ Object
445 446 447 448 449 450 451 |
# File 'lib/ncc/connection.rb', line 445 def generic_provider_request(instance) { :name => instance.name, :flavor => map_to_provider_id(:size, instance.size), :size => map_to_provider_id(:image, instance.image), }.merge(instance.extra provider) end |
#generic_translate(abstract_object_type, provider_object) ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/ncc/connection.rb', line 371 def generic_translate(abstract_object_type, provider_object) abstract_object = { 'id' => id_of(abstract_object_type, provider_object), 'provider_id' => provider_object.id } [:name, :description].each do |field| abstract_object[field.to_s] = provider_object.send(field) if provider_object.respond_to? field end abstract_object end |
#get_provider_object(provider_object_spec) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/ncc/connection.rb', line 319 def get_provider_object(provider_object_spec) abstract_object_type, abstract_object_id = provider_object_spec.first if id_field(abstract_object_type) != :id collection(abstract_object_type).find do |provider_object| id_of(abstract_object_type, provider_object) == abstract_object_id end else provider_object_id = map_to_provider_id(abstract_object_type, abstract_object_id) collection(abstract_object_type, provider_object_id) end end |
#get_provider_objects(type) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/ncc/connection.rb', line 303 def get_provider_objects(type) enum = case type when :size :flavors when :image :images end if use_only_mapped(type) and id_field(type) == :id id_map(type).values.map do |id| do_fog { |fog| fog.send(enum).get(id) } end else do_fog { |fog| fog.send(enum) } end end |
#host_fqdn(host) ⇒ Object
476 477 478 479 480 481 482 |
# File 'lib/ncc/connection.rb', line 476 def host_fqdn(host) if @cfg[:clouds][@cloud].has_key? 'host_domain' host + '.' + @cfg[:clouds][@cloud]['host_domain'] else host end end |
#id_field(abstract_object_type) ⇒ Object
265 266 267 268 269 270 271 272 |
# File 'lib/ncc/connection.rb', line 265 def id_field(abstract_object_type) methodname = abstract_object_type.to_s + '_id_field' if self.respond_to? methodname self.send methodname else :id end end |
#id_map(type) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ncc/connection.rb', line 187 def id_map(type) debug "making id_map for #{type.inspect}" keyname = keyname_for(type) r = { } debug "keyname = #{keyname} (for #{type.inspect})" debug "provider map: #{@cfg[:providers][provider].to_hash.inspect}" r.update(id_map_hash(@cfg[:providers][provider][keyname].to_hash)) if @cfg[:providers][provider].has_key? keyname #debug "cloud map: #{@cfg[:clouds][@cloud][keyname].to_hash}" r.update(id_map_hash(@cfg[:clouds][@cloud][keyname].to_hash)) if @cfg[:clouds][@cloud].has_key? keyname debug " >> #{r.inspect}" r end |
#id_map_hash(h) ⇒ Object
Something like “images” => { “$abstract_id” => x } can have an x where it’s the provider id, or an x which is a hash. If the hash has an id key, than that is used as a mapped id, if it doesn’t, it’s ignored (for the purposes of id mapping) -jbrinkley/20130410
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/ncc/connection.rb', line 173 def id_map_hash(h) Hash[ h.map do |k, v| if v.respond_to? :has_key? if v.has_key? 'id' [k, v['id']] end else [k, v] end end.reject { |p| p.nil? } ] end |
#id_of(abstract_object_type, obj) ⇒ Object
274 275 276 277 |
# File 'lib/ncc/connection.rb', line 274 def id_of(abstract_object_type, obj) map_to_id(abstract_object_type, translated_id_of(abstract_object_type, obj)) end |
#ids(a) ⇒ Object
151 152 153 |
# File 'lib/ncc/connection.rb', line 151 def ids(a) Hash[a.map { |e| [e['id'], e] }] end |
#images(image_id = nil) ⇒ Object
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/ncc/connection.rb', line 254 def images(image_id=nil) if image_id.nil? collection(:image).find_all do |provider_image| @cfg[:images].has_key? id_of(:image, provider_image) end.map { |i| object_of(:image, i) } else object_of(:image, get_provider_object(:image => image_id)) end end |
#info(msg) ⇒ Object
94 95 96 97 98 |
# File 'lib/ncc/connection.rb', line 94 def info(msg) if @logger and @logger.respond_to? :info @logger.info "#{self} #{msg}" end end |
#instance_for(server) ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/ncc/connection.rb', line 383 def instance_for(server) instance = NCC::Instance.new(@cfg, :logger => @logger) instance.set_without_validation(:id => server.id) instance.set_without_validation(:name => instance_name(server)) instance.set_without_validation(:size => instance_size(server)) instance.set_without_validation(:image => instance_image(server)) instance.set_without_validation(:ip_address => instance_ip_address(server)) instance.set_without_validation(:host => instance_host(server)) instance.set_without_validation(:status => instance_status(server)) instance end |
#instance_host(server) ⇒ Object
412 413 414 |
# File 'lib/ncc/connection.rb', line 412 def instance_host(server) nil end |
#instance_image(server) ⇒ Object
404 405 406 |
# File 'lib/ncc/connection.rb', line 404 def instance_image(server) map_to_id(:image, server.image) end |
#instance_ip_address(server) ⇒ Object
416 417 418 |
# File 'lib/ncc/connection.rb', line 416 def instance_ip_address(server) server.ip_address end |
#instance_name(server) ⇒ Object
396 397 398 |
# File 'lib/ncc/connection.rb', line 396 def instance_name(server) server.name end |
#instance_not_found(instance_id) ⇒ Object
547 548 549 550 |
# File 'lib/ncc/connection.rb', line 547 def instance_not_found(instance_id) raise NCC::Error::NotFound, "Instance #{instance_id.inspect} not " + "found in #{provider} cloud #{@cloud}" end |
#instance_size(server) ⇒ Object
400 401 402 |
# File 'lib/ncc/connection.rb', line 400 def instance_size(server) map_to_id(:size, server.size) end |
#instance_status(server) ⇒ Object
408 409 410 |
# File 'lib/ncc/connection.rb', line 408 def instance_status(server) map_to_status(server.status) end |
#instances(instance_id = nil) ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/ncc/connection.rb', line 420 def instances(instance_id=nil) debug "instances(#{instance_id.inspect})" if instance_id.nil? do_fog { |fog| fog.servers }.map { |server| instance_for server } else server = do_fog { |fog| fog.servers.get instance_id } if server.nil? instance_not_found instance_id end instance_for server end end |
#inventory_request(instance) ⇒ Object
461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/ncc/connection.rb', line 461 def inventory_request(instance) i = instance.with_defaults(@cfg[:clouds][@cloud]['defaults'], @cfg[:providers][provider]['defaults']) { 'fqdn' => i.name, 'size' => i.size, 'image' => i.image, 'serial_number' => i.id, 'roles' => i.role.sort.join(','), 'ip_address' => i.ip_address, 'host_fqdn' => host_fqdn(i.host), 'environment_name' => i.environment }.merge(instance.extra 'inventory') end |
#keyintern(h) ⇒ Object
453 454 455 456 457 458 459 |
# File 'lib/ncc/connection.rb', line 453 def (h) Hash[h.map do |k, v| [k.to_sym, ((v.is_a? Hash and (k.to_sym != :tags)) ? (v) : v)] end] end |
#keyname_for(type) ⇒ Object
159 160 161 162 163 164 165 166 |
# File 'lib/ncc/connection.rb', line 159 def keyname_for(type) case type when :size 'sizes' when :image 'images' end end |
#map_from_raw_provider_id(type, raw_provider_id) ⇒ Object
raw meaning not using “our” notion of id_field
226 227 228 229 230 231 232 |
# File 'lib/ncc/connection.rb', line 226 def map_from_raw_provider_id(type, raw_provider_id) # Using collection here for cache provider_object = collection(type).find do |item| item.id == raw_provider_id end id_of(type, provider_object) end |
#map_to_id(type, provider_id) ⇒ Object
216 217 218 219 |
# File 'lib/ncc/connection.rb', line 216 def map_to_id(type, provider_id) debug "provider_id_map = #{provider_id_map(type).inspect}" provider_id_map(type)[provider_id] || provider_id end |
#map_to_provider_id(type, abstract_id) ⇒ Object
221 222 223 |
# File 'lib/ncc/connection.rb', line 221 def map_to_provider_id(type, abstract_id) id_map(type)[abstract_id] || abstract_id end |
#map_to_provider_status(abstract_status) ⇒ Object
238 239 240 |
# File 'lib/ncc/connection.rb', line 238 def map_to_provider_status(abstract_status) abstract_status end |
#map_to_status(provider_status) ⇒ Object
234 235 236 |
# File 'lib/ncc/connection.rb', line 234 def map_to_status(provider_status) provider_status end |
#maybe_invalidate(type) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ncc/connection.rb', line 60 def maybe_invalidate(type) if @cache.has_key? type @cache.delete(type) if (Time.now - @cache[type][:timestamp]) > @cache_timeout end end |
#me ⇒ Object
67 68 69 |
# File 'lib/ncc/connection.rb', line 67 def me [self.class, provider, @cloud].join(' ') end |
#merge_configured(abstract_object, data) ⇒ Object
343 344 345 346 347 348 349 |
# File 'lib/ncc/connection.rb', line 343 def merge_configured(abstract_object, data) if data.respond_to? :each_pair data.each_pair { |k, v| abstract_object[k] ||= v } else abstract_object['provider_id'] ||= data end end |
#modify_instance_request(instance) ⇒ Object
484 485 486 |
# File 'lib/ncc/connection.rb', line 484 def modify_instance_request(instance) instance end |
#notice(msg) ⇒ Object
88 89 90 91 92 |
# File 'lib/ncc/connection.rb', line 88 def notice(msg) if @logger and @logger.respond_to? :notice @logger.notice "#{self} #{msg}" end end |
#object_of(abstract_object_type, provider_object) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/ncc/connection.rb', line 351 def object_of(abstract_object_type, provider_object) debug "object_of(#{abstract_object_type.inspect}, #{provider_object})" abstract_object = translate(abstract_object_type, provider_object) keyname = keyname_for abstract_object_type id = abstract_object['id'] [@cfg[:clouds][@cloud], @cfg[:providers][provider]].each do |cfg| if cfg.has_key? keyname and cfg[keyname].has_key? id debug "merging cloud/provider data: cfg[#{keyname}][#{id}]" merge_configured(abstract_object, cfg[keyname][id]) end end if @cfg.has_key? keyname.intern and @cfg[keyname.intern].has_key? id debug "merging abstract data: " + "@cfg[#{keyname.intern.inspect}][#{id}]" merge_configured(abstract_object, @cfg[keyname.intern][id].to_hash) end debug "object_of returns: #{abstract_object.inspect}" abstract_object end |
#provider ⇒ Object
155 156 157 |
# File 'lib/ncc/connection.rb', line 155 def provider generic end |
#provider_id_map(type) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/ncc/connection.rb', line 202 def provider_id_map(type) debug "making provider_id_map for #{type.inspect}" keyname = keyname_for(type) r = { } r.update(id_map_hash(@cfg[:providers][provider][keyname]. to_hash).invert) if @cfg[:providers][provider].has_key? keyname r.update(id_map_hash(@cfg[:clouds][@cloud][keyname]. to_hash).invert) if @cfg[:clouds][@cloud].has_key? keyname debug " >>> #{r.inspect}" r end |
#provider_request(instance) ⇒ Object
433 434 435 436 437 438 439 |
# File 'lib/ncc/connection.rb', line 433 def provider_request(instance) ( provider_request_of(instance. with_defaults(@cfg[:clouds][@cloud]['defaults'], @cfg[:providers][provider]['defaults'])) ) end |
#provider_request_of(instance) ⇒ Object
441 442 443 |
# File 'lib/ncc/connection.rb', line 441 def provider_request_of(instance) generic_provider_request(instance) end |
#reboot(instance_id) ⇒ Object
581 582 583 584 585 586 587 588 |
# File 'lib/ncc/connection.rb', line 581 def reboot(instance_id) server = do_fog { |fog| fog.servers.get(instance_id) } if server.nil? instance_not_found instance_id else server.reboot end end |
#sizes(size_id = nil) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/ncc/connection.rb', line 242 def sizes(size_id=nil) debug "sizes(#{size_id.inspect})" if size_id.nil? collection(:size).find_all do |flavor| @cfg[:sizes].has_key? id_of(:size, flavor) end.map { |f| object_of(:size, f) } else object_of(:size, get_provider_object(:size => size_id)) end end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/ncc/connection.rb', line 71 def to_s '#<' + me + '>' end |
#translate(abstract_object_type, provider_object) ⇒ Object
333 334 335 336 337 338 339 340 341 |
# File 'lib/ncc/connection.rb', line 333 def translate(abstract_object_type, provider_object) debug "translate(#{abstract_object_type.inspect}, #{provider_object})" methodname = 'translate_' + abstract_object_type.to_s if self.respond_to? methodname self.send(methodname, provider_object) else generic_translate(abstract_object_type, provider_object) end end |
#translated_id_of(abstract_object_type, obj) ⇒ Object
279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ncc/connection.rb', line 279 def translated_id_of(abstract_object_type, obj) id_fielder = id_field abstract_object_type if id_fielder.kind_of? Proc id_fielder.call obj elsif obj.nil? nil else obj.send id_fielder end end |
#use_only_mapped(type) ⇒ Object
Warning. use_only_mapped is ignored for types with alternate id fields
143 144 145 |
# File 'lib/ncc/connection.rb', line 143 def use_only_mapped(type) false end |
#warn(msg) ⇒ Object
75 76 77 78 79 |
# File 'lib/ncc/connection.rb', line 75 def warn(msg) if @logger and @logger.respond_to? :warn @logger.warn "#{self} #{msg}" end end |