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
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/quick_travel/adapter.rb', line 42
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
74
75
76
|
# File 'lib/quick_travel/adapter.rb', line 74
def self.create(options = {})
post_and_validate("#{api_base}.json", options)
end
|
.find(id, opts = {}) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/quick_travel/adapter.rb', line 56
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
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/quick_travel/adapter.rb', line 28
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
78
79
80
81
|
# File 'lib/quick_travel/adapter.rb', line 78
def self.update(id, options = {})
check_id!(id)
put_and_validate("#{api_base}/#{id}.json", options)
end
|
Instance Method Details
#to_s ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/quick_travel/adapter.rb', line 83
def to_s
if defined? @to_s
@to_s
else
super
end
end
|