Sha256: b846c4b99f5356b0a75053228b138a4ff9eb888928d081e3c037b1bd21ea2ff5

Contents?: true

Size: 988 Bytes

Versions: 4

Compression:

Stored size: 988 Bytes

Contents

module Putter
  class WatcherData
    attr_accessor :label, :proxy_methods

    def initialize(options, klass)
      @label = set_label(options[:label], klass)
      @proxy_methods = set_methods(options[:methods], klass.singleton_class)
    end

    def set_label(label, klass)
      if !label.nil? && label != ""
        label
      else
        klass.name
      end
    end

    def set_methods(methods, singleton_klass)
      if methods.nil?
        methods_to_proxy(singleton_klass)
      elsif !methods.is_a?(Array)
        [methods]
      else
        methods
      end
    end

    def methods_to_proxy(singleton_klass)
      ignored_methods = Putter.configuration.methods_blacklist.map(&:to_sym)

      Putter.configuration.ignore_methods_from.each do |klass|
        ignored_methods += klass.methods
      end

      whitelist = Putter.configuration.methods_whitelist.map(&:to_sym) + [:new]

      singleton_klass.instance_methods - ignored_methods + whitelist
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
putter-0.6.1 lib/putter/watcher_data.rb
putter-0.6.0 lib/putter/watcher_data.rb
putter-0.5.1 lib/putter/watcher_data.rb
putter-0.5.0 lib/putter/watcher_data.rb