Sha256: 812cb0975c44967db913a6282871f272cc73fc27cadbf582bc512f586cf32d66

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

require_relative 'state_inspector'
require_relative 'reporter'

module StateInspector
  module Snoop
    def Snoop.extended(base)
      base.include ClassMethods
    end

    module ClassMethods
      def state_inspector
        StateInspector.new(self)
      end

      def tell_si *args, &block
        if informant?
          key = self.respond_to?(:class_eval) ? self : self.class
          Reporter[key].update(self, *args, &block)
        end
      end

      def toggle_informant
        state_inspector.snoop_setters(
          *(self.respond_to?(:class_eval) ? self : self.class).
          instance_methods.grep(/=\z/) - Object.methods
        ) unless @state_inspector || self.class.instance_variable_get(:@state_inspector)

        @informant = !@informant
      end

      def informant?
        @informant || self.class.instance_variable_get(:@informant)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
state_inspector-1.0.2 lib/state_inspector/snoop.rb
state_inspector-1.0.1 lib/state_inspector/snoop.rb
state_inspector-1.0.0 lib/state_inspector/snoop.rb
state_inspector-1.0.0.rc1 lib/state_inspector/snoop.rb