67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/clientele/resource.rb', line 67
def build(data, client: nil, response: nil)
new(
catch(:build) do
if data.kind_of? Hash
if many = results(data)
build many, client: client elsif one = result(data)
throw :build, one
else
throw :build, data
end
elsif data.respond_to? :map
data.map do |dataset|
build dataset, client: client end
end
end
).tap do |instance|
instance.instance_variable_set :@client, client if client
instance.instance_variable_set :@response, response if response
end
end
|