Sha256: fc4a6bee9acba9a23d871c295c910028c41277c9cbd1b31400574aba229de2fc

Contents?: true

Size: 911 Bytes

Versions: 8

Compression:

Stored size: 911 Bytes

Contents

require 'set'

module Raven
  module BetterAttrAccessor

    def attributes
      Hash[
        self.class.attributes.map do |attr|
          [attr, send(attr)]
        end
      ]
    end

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def attributes
        @attributes ||= Set.new

        if superclass.include? BetterAttrAccessor
          @attributes + superclass.attributes
        else
          @attributes
        end
      end

      def attr_accessor(attr, options = {})
        @attributes ||= Set.new
        @attributes << attr.to_s

        define_method attr do
          if instance_variable_defined? "@#{attr}"
            instance_variable_get "@#{attr}"
          elsif options.key? :default
            instance_variable_set "@#{attr}", options[:default].dup
          end
        end
        attr_writer attr
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
sentry-raven-0.12.3 lib/raven/better_attr_accessor.rb
sentry-raven-0.12.2 lib/raven/better_attr_accessor.rb
sentry-raven-0.12.1 lib/raven/better_attr_accessor.rb
sentry-raven-0.12.0 lib/raven/better_attr_accessor.rb
mustwin-sentry-raven-0.11.2 lib/raven/better_attr_accessor.rb
sentry-raven-0.11.2 lib/raven/better_attr_accessor.rb
sentry-raven-0.11.1 lib/raven/better_attr_accessor.rb
sentry-raven-0.10.1 lib/raven/better_attr_accessor.rb