Sha256: 10edd873c27079aff0f1bddb2dcf4ff744251e7a8e4af41d1417e4e0c8bf12f7

Contents?: true

Size: 578 Bytes

Versions: 71

Compression:

Stored size: 578 Bytes

Contents

# 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

71 entries across 71 versions & 1 rubygems

Version Path
tracksperanto-2.8.6 lib/tracksperanto/safety.rb
tracksperanto-2.8.5 lib/tracksperanto/safety.rb
tracksperanto-2.8.4 lib/tracksperanto/safety.rb
tracksperanto-2.8.2 lib/tracksperanto/safety.rb
tracksperanto-2.8.1 lib/tracksperanto/safety.rb
tracksperanto-2.8.0 lib/tracksperanto/safety.rb
tracksperanto-2.7.0 lib/tracksperanto/safety.rb
tracksperanto-2.6.3 lib/tracksperanto/safety.rb
tracksperanto-2.6.2 lib/tracksperanto/safety.rb
tracksperanto-2.6.1 lib/tracksperanto/safety.rb
tracksperanto-2.6.0 lib/tracksperanto/safety.rb
tracksperanto-2.5.0 lib/tracksperanto/safety.rb
tracksperanto-2.4.1 lib/tracksperanto/safety.rb
tracksperanto-2.3.3 lib/tracksperanto/safety.rb
tracksperanto-2.3.2 lib/tracksperanto/safety.rb
tracksperanto-2.3.1 lib/tracksperanto/safety.rb
tracksperanto-2.3.0 lib/tracksperanto/safety.rb
tracksperanto-2.2.4 lib/tracksperanto/safety.rb
tracksperanto-2.2.2 lib/tracksperanto/safety.rb
tracksperanto-2.2.0 lib/tracksperanto/safety.rb