Class: ShafClient::Form

Inherits:
Resource show all
Defined in:
lib/shaf_client/form.rb

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!

Methods inherited from BaseResource

#actions, #attribute, #curie, #embedded, #initialize, #link, #rel?, #to_h, #to_s

Constructor Details

This class inherits a constructor from ShafClient::Resource

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_methodObject



29
30
31
# File 'lib/shaf_client/form.rb', line 29

def http_method
  attribute(:method).downcase.to_sym
end

#submitObject



33
34
35
# File 'lib/shaf_client/form.rb', line 33

def submit
  client.send(http_method, target, payload: @values)
end

#targetObject



25
26
27
# File 'lib/shaf_client/form.rb', line 25

def target
  attribute(:href)
end

#valid?Boolean

Returns:

  • (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

#valuesObject



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