class Pdf4me::ComplexAction
Attributes
client[R]
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 16 def initialize(attributes = {}) assign_attributes(attributes) end
Public Instance Methods
assign_attributes(attributes = {})
click to toggle source
# 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()
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 33 def errors errors = attributes.map do |attribute| send(attribute).errors.full_messages end errors.flatten end
run()
click to toggle source
# 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?()
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 29 def valid? valid_objects? && valid_instances? end
Protected Instance Methods
attributes()
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 42 def attributes self.class::ATTRIBUTES end
serialize_attributes()
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 58 def serialize_attributes attributes.each_with_object({}) do |attribute, hash| hash[attribute.camelize(:lower)] = send(attribute).attributes end end
valid_instances?()
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 52 def valid_instances? attributes.all? do |attribute| send(attribute).valid? end end
valid_objects?()
click to toggle source
# File lib/pdf4me/actions/complex_action.rb, line 46 def valid_objects? attributes.all? do |value| send(value).class.name == "pdf4me/#{value}".classify end end