Class: Pdf4me::ComplexAction
- Inherits:
-
Object
- Object
- Pdf4me::ComplexAction
- Defined in:
- lib/pdf4me/actions/complex_action.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #assign_attributes(attributes = {}) ⇒ Object
- #errors ⇒ Object
-
#initialize(attributes = {}) ⇒ ComplexAction
constructor
A new instance of ComplexAction.
- #run ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ ComplexAction
Returns a new instance of ComplexAction.
16 17 18 |
# File 'lib/pdf4me/actions/complex_action.rb', line 16 def initialize(attributes = {}) assign_attributes(attributes) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/pdf4me/actions/complex_action.rb', line 3 def client @client end |
Instance Method Details
#assign_attributes(attributes = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/pdf4me/actions/complex_action.rb', line 9 def assign_attributes(attributes = {}) attributes.to_h.each do |key, value| writer_method = "#{key}=" send(writer_method, value) if respond_to?(writer_method) end end |
#errors ⇒ Object
33 34 35 36 37 38 |
# File 'lib/pdf4me/actions/complex_action.rb', line 33 def errors errors = attributes.map do |attribute| send(attribute).errors. end errors.flatten end |
#run ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pdf4me/actions/complex_action.rb', line 20 def run return unless valid? response = client.post( path, serialize_attributes.to_json ) Pdf4me.const_get("#{self.class.name}Res").from_response(response) end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/pdf4me/actions/complex_action.rb', line 29 def valid? valid_objects? && valid_instances? end |