Sha256: 676ea947f3ac5674cbbe3ee85d47e5b6cdb788c7b118f04ddd7634c9880846b6

Contents?: true

Size: 679 Bytes

Versions: 6

Compression:

Stored size: 679 Bytes

Contents

# frozen_string_literal: true

module SuperSettings
  # Interface to expose mass setting attributes on an object. Setting attributes with a
  # hash will simply call the attribute writers for each key in the hash.
  module Attributes
    class UnknownAttributeError < StandardError
    end

    def initialize(attributes = nil)
      self.attributes = attributes if attributes
    end

    def attributes=(values)
      values.each do |name, value|
        if respond_to?("#{name}=", true)
          send("#{name}=", value)
        else
          raise UnknownAttributeError.new("unknown attribute #{name.to_s.inspect} for #{self.class}")
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
super_settings-1.0.1 lib/super_settings/attributes.rb
super_settings-1.0.0 lib/super_settings/attributes.rb
super_settings-0.0.1.rc3 lib/super_settings/attributes.rb
super_settings-0.0.1.rc2 lib/super_settings/attributes.rb
super_settings-0.0.1.rc1 lib/super_settings/attributes.rb
super_settings-0.0.0.rc1 lib/super_settings/attributes.rb