Class: ShafClient::Form
Instance Attribute Summary
Attributes inherited from Resource
#headers, #http_status
Attributes inherited from BaseResource
#attributes, #curies, #embedded_resources, #links
Instance Method Summary
collapse
Methods inherited from Resource
build, content_type, #destroy!, #get_doc, #initialize, profile, #reload!
#actions, #attribute, #curie, #embedded, #initialize, #link, #rel?, #to_h, #to_s
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ShafClient::BaseResource
Instance Method Details
#[](key) ⇒ Object
17
18
19
|
# File 'lib/shaf_client/form.rb', line 17
def [](key)
values[key.to_sym]
end
|
#[]=(key, value) ⇒ Object
21
22
23
|
# File 'lib/shaf_client/form.rb', line 21
def []=(key, value)
values[key.to_sym] = value
end
|
#http_method ⇒ Object
29
30
31
|
# File 'lib/shaf_client/form.rb', line 29
def http_method
attribute(:method).downcase.to_sym
end
|
#submit ⇒ Object
33
34
35
|
# File 'lib/shaf_client/form.rb', line 33
def submit
client.send(http_method, target, payload: @values)
end
|
#target ⇒ Object
25
26
27
|
# File 'lib/shaf_client/form.rb', line 25
def target
attribute(:href)
end
|
#valid? ⇒ Boolean
37
38
39
40
41
|
# File 'lib/shaf_client/form.rb', line 37
def valid?
attribute(:fields).all? do |field|
valid_field? field
end
end
|
#values ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/shaf_client/form.rb', line 9
def values
return @values if defined? @values
@values = attribute(:fields).each_with_object({}) do |d, v|
v[d['name'].to_sym] = d['value']
end
end
|