Class: DaisybillApi::Ext::Links::Link
- Inherits:
-
Object
- Object
- DaisybillApi::Ext::Links::Link
- Defined in:
- lib/daisybill_api/ext/links/link.rb
Instance Attribute Summary collapse
-
#href ⇒ Object
Returns the value of attribute href.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #foreign_id ⇒ Object
- #foreign_key ⇒ Object
- #foreign_key? ⇒ Boolean
-
#initialize(name, klass, options = {}) ⇒ Link
constructor
A new instance of Link.
- #value ⇒ Object
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, = {}) @name = name @klass = klass @options = end |
Instance Attribute Details
#href ⇒ Object
Returns the value of attribute href.
5 6 7 |
# File 'lib/daisybill_api/ext/links/link.rb', line 5 def href @href end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/daisybill_api/ext/links/link.rb', line 6 def klass @klass end |
#name ⇒ Object (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_id ⇒ Object
29 30 31 |
# File 'lib/daisybill_api/ext/links/link.rb', line 29 def foreign_id href.split("/").last end |
#foreign_key ⇒ Object
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
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 |
#value ⇒ Object
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 |