Class: ShafClient::Form
Constant Summary
Constants included
from MimeTypes
MimeTypes::DEFAULT_ADAPTER, MimeTypes::MIME_TYPE_HAL, MimeTypes::MIME_TYPE_JSON
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, #get_doc, #get_hal_form, #initialize, #inspect, profile, #reload!
#actions, #attribute, #curie, #embedded, #initialize, #inspect, #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
19
20
21
|
# File 'lib/shaf_client/form.rb', line 19
def [](key)
values.fetch(key.to_sym)
end
|
#[]=(key, value) ⇒ Object
23
24
25
26
|
# File 'lib/shaf_client/form.rb', line 23
def []=(key, value)
values.fetch(key.to_sym) values[key.to_sym] = value
end
|
#content_type ⇒ Object
40
41
42
|
# File 'lib/shaf_client/form.rb', line 40
def content_type
raise NotImplementedError
end
|
#fields ⇒ Object
44
45
46
|
# File 'lib/shaf_client/form.rb', line 44
def fields
raise NotImplementedError
end
|
#http_method ⇒ Object
36
37
38
|
# File 'lib/shaf_client/form.rb', line 36
def http_method
raise NotImplementedError
end
|
#submit ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/shaf_client/form.rb', line 48
def submit
client.send(
http_method,
target,
payload: encoded_payload,
headers: {'Content-Type' => content_type}
)
end
|
#target ⇒ Object
32
33
34
|
# File 'lib/shaf_client/form.rb', line 32
def target
raise NotImplementedError
end
|
#title ⇒ Object
28
29
30
|
# File 'lib/shaf_client/form.rb', line 28
def title
raise NotImplementedError
end
|
#valid? ⇒ Boolean
57
58
59
60
61
62
63
64
|
# File 'lib/shaf_client/form.rb', line 57
def valid?
field_value_mapping
fields.all? do |field|
value = values[field.name.to_sym]
field.valid? value
end
end
|
#values ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/shaf_client/form.rb', line 11
def values
return @values if defined? @values
@values = fields.each_with_object({}) do |field, values|
values[field.name] = field.value
end
end
|