Sha256: 9febc7070ca9a9c84aa26a9c056d0a308f26a78b8be67675cd8e71069461fc07

Contents?: true

Size: 652 Bytes

Versions: 4

Compression:

Stored size: 652 Bytes

Contents

module Dialers
  module AssignAttributes
    # Assign the attributes hash into the object calling attribute writers of the object
    # if the object can respond to them.
    #
    # @param object [Object] any object with some or no attribute writers.
    # @param attributes [Hash<Symbol, Object>] the attributes using symbols and objects.
    #
    # @return [Object] the same object passed as parameter.
    def self.call(object, attributes)
      attributes.each do |key, value|
        writer = "#{key}=".to_sym
        if object.respond_to?(writer)
          object.public_send(writer, value)
        end
      end
      object
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dialers-0.2.2 lib/dialers/assign_attributes.rb
dialers-0.1.2 lib/dialers/assign_attributes.rb
dialers-0.1.1 lib/dialers/assign_attributes.rb
dialers-0.1.0 lib/dialers/assign_attributes.rb