Class: DaisybillApi::Ext::Links::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/daisybill_api/ext/links/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, klass, options = {}) ⇒ Link

Returns a new instance of Link.



8
9
10
11
12
# File 'lib/daisybill_api/ext/links/link.rb', line 8

def initialize(name, klass, options = {})
  @name = name
  @klass = klass
  @options = options
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



5
6
7
# File 'lib/daisybill_api/ext/links/link.rb', line 5

def href
  @href
end

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'lib/daisybill_api/ext/links/link.rb', line 6

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/daisybill_api/ext/links/link.rb', line 6

def name
  @name
end

Instance Method Details

#foreign_idObject



29
30
31
# File 'lib/daisybill_api/ext/links/link.rb', line 29

def foreign_id
  href.split("/").last
end

#foreign_keyObject



21
22
23
# File 'lib/daisybill_api/ext/links/link.rb', line 21

def foreign_key
  @foreign_key ||= @options.has_key?(:foreign_key) ? @options[:foreign_key] : "#{name}_id"
end

#foreign_key?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/daisybill_api/ext/links/link.rb', line 25

def foreign_key?
  !@options.has_key?(:foreign_key) || !!@options[:foreign_key]
end

#valueObject



14
15
16
17
18
19
# File 'lib/daisybill_api/ext/links/link.rb', line 14

def value
  return unless href
  default_path = DaisybillApi::Data::Url::DEFAULT_PATH
  c = DaisybillApi::Data::Client.build(:get, href.gsub(default_path, ""))
  klass.constantize.new(c.response) if c.success?
end