Sha256: f6b5cb468d8dd2c44215be141a38a8f8d2de57ebacc8810c0ce5a53ebb5818d4

Contents?: true

Size: 914 Bytes

Versions: 11

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

# @api private
# @since 0.1.0
class SmartCore::Validator::Attribute
  # @return [Symbol]
  #
  # @api private
  # @since 0.1.0
  attr_reader :name

  # @param name [String, Symbol]
  # @param default_value [Proc, Object]
  # @return [void]
  #
  # @api private
  # @since 0.1.0
  def initialize(name, default_value = nil)
    unless name.is_a?(Symbol) || name.is_a?(String)
      raise(
        SmartCore::Validator::IncorrectAttributeNameError,
        'Attribute name should be a symbol or a string'
      )
    end

    @name = name.to_sym
    @default_value = default_value
  end

  # @return [Any]
  #
  # @api private
  # @since 0.1.0
  def default_value
    @default_value.is_a?(Proc) ? @default_value.call : @default_value
  end

  # @return [SmartCore::Validator::Attribute]
  #
  # @api private
  # @since 0.1.0
  def dup
    self.class.new(name, @default_value)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
smart_core-0.8.1 lib/smart_core/validator/attribute.rb
smart_core-0.8.0 lib/smart_core/validator/attribute.rb
smart_core-0.7.0 lib/smart_core/validator/attribute.rb
smart_core-0.6.0 lib/smart_core/validator/attribute.rb
smart_core-0.5.2 lib/smart_core/validator/attribute.rb
smart_core-0.5.1 lib/smart_core/validator/attribute.rb
smart_core-0.5.0 lib/smart_core/validator/attribute.rb
smart_core-0.4.0 lib/smart_core/validator/attribute.rb
smart_core-0.3.0 lib/smart_core/validator/attribute.rb
smart_core-0.2.0 lib/smart_core/validator/attribute.rb
smart_core-0.1.0 lib/smart_core/validator/attribute.rb