Sha256: d3e0b9bd8ea057b7e268a936fa072d0f117254c5c271e2b4b72da3750ae038c4

Contents?: true

Size: 606 Bytes

Versions: 42

Compression:

Stored size: 606 Bytes

Contents

# -*- encoding : utf-8 -*-
# Implements the +safe_reader+ class method which will define (or override) readers that
# raise if ivar is nil
module Tracksperanto::Safety
  def self.included(into)
    into.extend(self)
    super
  end
  
  # Inject a reader that checks for nil
  def safe_reader(*attributes)
    attributes.each do | an_attr |
      alias_method "#{an_attr}_without_nil_protection", an_attr
      define_method(an_attr) do
        val = send("#{an_attr}_without_nil_protection")
        raise "Expected #{an_attr} on #{self} not to be nil" if val.nil?
        val
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
tracksperanto-3.5.9 lib/tracksperanto/safety.rb
tracksperanto-3.5.8 lib/tracksperanto/safety.rb
tracksperanto-3.5.7 lib/tracksperanto/safety.rb
tracksperanto-3.5.6 lib/tracksperanto/safety.rb
tracksperanto-3.5.5 lib/tracksperanto/safety.rb
tracksperanto-3.5.4 lib/tracksperanto/safety.rb
tracksperanto-3.5.2 lib/tracksperanto/safety.rb
tracksperanto-3.5.1 lib/tracksperanto/safety.rb
tracksperanto-3.5.0 lib/tracksperanto/safety.rb
tracksperanto-3.4.1 lib/tracksperanto/safety.rb
tracksperanto-3.4.0 lib/tracksperanto/safety.rb
tracksperanto-3.3.13 lib/tracksperanto/safety.rb
tracksperanto-3.3.12 lib/tracksperanto/safety.rb
tracksperanto-3.3.11 lib/tracksperanto/safety.rb
tracksperanto-3.3.10 lib/tracksperanto/safety.rb
tracksperanto-3.3.9 lib/tracksperanto/safety.rb
tracksperanto-3.3.8 lib/tracksperanto/safety.rb
tracksperanto-3.3.7 lib/tracksperanto/safety.rb
tracksperanto-3.3.6 lib/tracksperanto/safety.rb
tracksperanto-3.3.0.pre lib/tracksperanto/safety.rb