Skip to content

Commit

Permalink
Minor improvements, fixes to Mutable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 13, 2024
1 parent 7317a8b commit 9ea5f0a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
28 changes: 12 additions & 16 deletions lib/async/rest/representation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,29 @@ def value

# Provides a way to mutate the value of the representation.
module Mutable
def value= value
@value = self.assign(value)
def post(value)
self.class.post(@resource, value) do |resource, response|
@value = response.read

self
end
end

def call(value)
def delete
self.class.delete(@resource)
end

def assign(value)
if value
self.post(value)
else
self.delete
end
end

def assign(value)
response = self.call(value)

response.read

return @value
end

def update
@value = assign(@value)
end
end

def inspect
"\#<#{self.class} #{@resource.inspect} value=#{@value.inspect}>"
"\#<#{self.class} #{@resource.path.inspect} value=#{@value.inspect}>"
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/async/rest/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def with(**options)
self.class.with(self, **options)
end

def path
@reference.path
end

def inspect
"\#<#{self.class} #{@reference.inspect} #{@headers.inspect}>"
end
Expand Down
5 changes: 3 additions & 2 deletions lib/async/rest/wrapper/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ module Async
module REST
module Wrapper
class Generic
def call(resource, verb = "GET", payload = nil, &block)
request = ::Protocol::HTTP::Request[verb, nil]
def call(resource, method = "GET", payload = nil, &block)
request = ::Protocol::HTTP::Request[method, nil]

self.prepare_request(request, payload)

response = resource.call(request)
Expand Down

0 comments on commit 9ea5f0a

Please sign in to comment.