Sha256: cb20ca400bca2b5e4178496478fa4ed9039858714661cc223069765843c5725c

Contents?: true

Size: 919 Bytes

Versions: 3

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module Concern
    module Attributes
      # A separated range typed attribute helper.
      module Range
        extend ActiveSupport::Concern

        class_methods do
          # Register a range attribute.
          #
          # @param name [Symbol, String] the name of the attribute
          # @param _args [Hash{Symbol => Mixed}] additional options
          def typed_attr_range(name, **_args)
            class_eval <<-RUBY, __FILE__, __LINE__ + 1
              def #{name}
                # We cannot handle nil values
                return unless @#{name}

                # Otherwise we assume the hash contains a +lower+ and +upper+
                # key from which we assemble the range
                hash = @#{name}
                hash[:lower]..hash[:upper]
              end
            RUBY
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pricehubble-1.6.0 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.5.1 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.5.0 lib/price_hubble/entity/concern/attributes/range.rb