Sha256: 10625d33954fcf8a82b7439d45defcd04ab7a9f93ab5c4c113797c7be9e6c256
Contents?: true
Size: 1.07 KB
Versions: 5
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require "forwardable" module Strict module Attributes class Configuration include Enumerable extend Forwardable class UnknownAttributeError < Error attr_reader :attribute_name def initialize(attribute_name:) super(message_from(attribute_name: attribute_name)) @attribute_name = attribute_name end private def message_from(attribute_name:) "Strict tried to find an attribute named #{attribute_name} but was unable. " \ "It's likely this in an internal bug, feel free to open an issue at #{Strict::ISSUE_TRACKER} for help." end end def_delegator :attributes, :each attr_reader :attributes def initialize(attributes:) @attributes = attributes @attributes_index = attributes.to_h { |a| [a.name, a] } end def named!(name) attributes_index.fetch(name) { raise UnknownAttributeError.new(attribute_name: name) } end private attr_reader :attributes_index end end end
Version data entries
5 entries across 5 versions & 1 rubygems