Module: Sequent::Core::Helpers::ParamSupport
- Included in:
- BaseCommand, ValueObject
- Defined in:
- lib/sequent/core/helpers/param_support.rb
Overview
Class to support binding from a params hash like the one from Sinatra
You typically do not need to include this module in your classes. If you extend from Sequent::Core::ValueObject, Sequent::Core::Event or Sequent::Core::BaseCommand you will get this functionality for free.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(host_class) ⇒ Object
extend host class with class methods when we’re included.
Instance Method Summary collapse
Class Method Details
.included(host_class) ⇒ Object
extend host class with class methods when we’re included
33 34 35 |
# File 'lib/sequent/core/helpers/param_support.rb', line 33 def self.included(host_class) host_class.extend(ClassMethods) end |
Instance Method Details
#as_params ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sequent/core/helpers/param_support.rb', line 41 def as_params hash = HashWithIndifferentAccess.new self.class.types.each do |field| value = self.instance_variable_get("@#{field[0]}") next if field[0] == "errors" if value.respond_to?(:as_params) && value.kind_of?(ValueObject) value = value.as_params elsif value.kind_of?(Array) value = value.map { |val| val.kind_of?(ValueObject) ? val.as_params : val } elsif value.is_a? DateTime value = value.iso8601 elsif value.is_a? Date value = value.strftime("%d-%m-%Y") # TODO Remove to TypeConverter end hash[field[0]] = value end hash end |