Class: QuickTravel::Adapter
- Inherits:
-
Object
- Object
- QuickTravel::Adapter
show all
- Includes:
- InitFromHash
- Defined in:
- lib/quick_travel/mock.rb,
lib/quick_travel/adapter.rb
Direct Known Subclasses
Accommodation, AvailabilityDetails, Booking, Checkout, Client, ClientType, Country, Document, DocumentGroup, DropOffLocation, DropOffOption, Location, Package, Party, PassengerType, Payment, PaymentType, PricePerPaxType, PriceQuote, PricingDetails, Product, ProductType, Products::Base, Property, PropertyType, Region, Reservation, Resource, ResourceCategory, Route, Setting, Trip, Vehicle, VehicleType
Defined Under Namespace
Classes: Deserializer
Class Method Summary
collapse
Instance Method Summary
collapse
#define_readers, #initialize, #to_hash
Class Method Details
.all(opts = {}) ⇒ Object
29
30
31
|
# File 'lib/quick_travel/mock.rb', line 29
def self.all
[new, new]
end
|
.belongs_to(relation_name, options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/quick_travel/adapter.rb', line 43
def self.belongs_to(relation_name, options = {})
define_method relation_name do
instance_variable_get("@#{relation_name}") || instance_variable_set(
"@#{relation_name}",
begin
attrs = instance_variable_get("@#{relation_name}_attributes")
return nil unless attrs
klass = QuickTravel.const_get(options[:class_name] || relation_name.to_s.singularize.classify)
klass.new(attrs)
end
)
end
end
|
.create(options = {}) ⇒ Object
75
76
77
|
# File 'lib/quick_travel/adapter.rb', line 75
def self.create(options = {})
post_and_validate("#{api_base}.json", options)
end
|
.find(id, opts = {}) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/quick_travel/adapter.rb', line 57
def self.find(id, opts = {})
check_id!(id)
if lookup
all.detect { |o| o.id == id.to_i }
else
find_all!("#{api_base}/#{id}.json", opts).first
end
end
|
.has_many(relation_name, options = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/quick_travel/adapter.rb', line 29
def self.has_many(relation_name, options = {})
define_method relation_name do
instance_variable_get("@#{relation_name}") || instance_variable_set(
"@#{relation_name}",
begin
klass = QuickTravel.const_get(options[:class_name] || relation_name.to_s.singularize.classify)
Array(instance_variable_get("@#{relation_name}_attributes")).map { |attr|
klass.new(attr)
}
end
)
end
end
|
.update(id, options = {}) ⇒ Object
79
80
81
82
|
# File 'lib/quick_travel/adapter.rb', line 79
def self.update(id, options = {})
check_id!(id)
put_and_validate("#{api_base}/#{id}.json", options)
end
|
Instance Method Details
#to_s ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/quick_travel/adapter.rb', line 84
def to_s
if defined? @to_s
@to_s
else
super
end
end
|