Sha256: 34a12e5c60e452b7496badc38631df918a54f13098405afa0d0e9cc39fc8feb2

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Putter
  class FollowerData
    attr_accessor :label

    def initialize(object, proxy, options)
      @proxy = proxy
      @proxied_methods = options[:methods] || []
      set_label(options[:label], object)
    end

    def add_method?(method)
      return false if @proxy.instance_methods.include?(method)
      return true if @proxied_methods.include?(method)
      return true if is_allowed_method?(method)
      return false if is_denied_method?(method)
      return false if is_ignored_method?(method)
      return true if @proxied_methods.empty?
    end

    private

    def set_label(label, object)
      if !label.nil?
        @label = label
      elsif object.class == Class
        @label = object.name
      else
        @label = object.class.name + " instance"
      end
    end

    def is_allowed_method?(method)
      ::Putter.configuration.methods_allowlist.map(&:to_sym).include?(method.to_sym)
    end

    def is_denied_method?(method)
      ::Putter.configuration.methods_denylist.map(&:to_sym).include?(method.to_sym)
    end

    def is_ignored_method?(method)
      ::Putter.configuration.ignore_methods_from.each do |klass|
        return true if klass.methods.include?(method.to_sym)
        return true if klass.instance_methods.include?(method.to_sym)
      end
      return false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
putter-0.7.0 lib/putter/follower_data.rb