Sha256: 5f3ee0d9665a3e67433f7193d10c4974ce46ec8465d9ba186953149867f6ede5

Contents?: true

Size: 781 Bytes

Versions: 1

Compression:

Stored size: 781 Bytes

Contents

class Product
  attr_reader :product_id, :title, :master_id, :customer_id

  def initialize(product_id, title, master_id, customer_id)
    validate_null('product_id', product_id)
    validate_null('title', title)
    validate_null('master_id', master_id)
    validate_null('customer_id', customer_id)

    validate_title_length(title)

    @product_id = product_id
    @title = title
    @master_id = master_id
    @customer_id = customer_id
  end

  private

  def validate_null(name, value)
    if value.nil?
      raise ArgumentError, "Argument  '#{name}' cannot be null"
    end
  end

  def validate_title_length(title)
    if title.length > 255
      raise ArgumentError, "The title contains more than 255 characters: #{title}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jewerly_system-1.0.0 lib/source/models/product.rb