Sha256: 0096940b08d3ff13626aa97a10680b45cd65246da6f28c6b8f2203413acb4857

Contents?: true

Size: 925 Bytes

Versions: 15

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module EntityConcern
    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

15 entries across 15 versions & 1 rubygems

Version Path
pricehubble-1.3.0 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.2.5 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.2.4 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.2.3 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.2.2 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.2.1 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.2.0 lib/price_hubble/entity/concern/attributes/range.rb
pricehubble-1.1.0 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-1.0.0 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-0.4.2 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-0.4.1 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-0.4.0 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-0.3.0 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-0.2.0 lib/pricehubble/entity/concern/attributes/range.rb
pricehubble-0.1.0 lib/pricehubble/entity/concern/attributes/range.rb