Sha256: 6adfed39d02c2c4780fe39ffe528bfd87ae551fa09b4acbff328ec882c7fab00

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

module DataMapper
  module Validations
    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

14 entries across 14 versions & 2 rubygems

Version Path
ardm-validations-1.2.0 spec/fixtures/ethernet_frame.rb
dm-validations-1.2.0 spec/fixtures/ethernet_frame.rb
dm-validations-1.2.0.rc2 spec/fixtures/ethernet_frame.rb
dm-validations-1.2.0.rc1 spec/fixtures/ethernet_frame.rb
dm-validations-1.1.0 spec/fixtures/ethernet_frame.rb
dm-validations-1.1.0.rc3 spec/fixtures/ethernet_frame.rb
dm-validations-1.1.0.rc2 spec/fixtures/ethernet_frame.rb
dm-validations-1.1.0.rc1 spec/fixtures/ethernet_frame.rb
dm-validations-1.0.2 spec/fixtures/ethernet_frame.rb
dm-validations-1.0.1 spec/fixtures/ethernet_frame.rb
dm-validations-1.0.0 spec/fixtures/ethernet_frame.rb
dm-validations-1.0.0.rc3 spec/fixtures/ethernet_frame.rb
dm-validations-1.0.0.rc2 spec/fixtures/ethernet_frame.rb
dm-validations-1.0.0.rc1 spec/fixtures/ethernet_frame.rb