Sha256: 1aa7b22700b497b8765a13031e38798073e60c5821b8fd71e1795f324a73de1a

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

module DataMapper
  module Validation
    module Fixtures

      # for pedants: we refer to DIX Ethernet here
      class EthernetFrame

        #
        # Behaviors
        #

        include DataMapper::Resource

        #
        # Properties
        #

        attr_accessor :link_support_fragmentation

        # we have to have a key in a DM resource
        property :id, Serial

        without_auto_validations do
          property :destination_mac, String
          property :source_mac,      String
          property :ether_type,      String
          property :payload,         Text
          property :crc,             String
        end

        #
        # Validations
        #

        validates_length_of :destination_mac, :source_mac, :equals => 6
        validates_length_of :ether_type, :equals => 2
        validates_length_of :payload, :min => 46, :max => 1500, :unless => :link_support_fragmentation
        # :is is alias for :equal
        validates_length_of :crc, :is => 4

        def self.valid_instance
          # these are obvisouly not bits, and not in hexadecimal
          # format either, but give fixture models some slack
          attributes = {
            :destination_mac => "7b7d93",
            :source_mac      => "abe763",
            :ether_type      => "88",
            :payload         => "Imagine yourself a beautiful bag full of bits here",
            :crc             => "4132"
          }
          new(attributes)
        end
      end # EthernetFrame
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
sbf-dm-validations-1.4.0 spec/fixtures/ethernet_frame.rb
sbf-dm-validations-1.3.0 spec/fixtures/ethernet_frame.rb
sbf-dm-validations-1.3.0.beta spec/fixtures/ethernet_frame.rb
aequitas-0.0.1 spec_legacy/fixtures/ethernet_frame.rb