File: phantom.rb

package info (click to toggle)
mikutter 4.1.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,260 kB
  • sloc: ruby: 20,126; sh: 183; makefile: 19
file content (48 lines) | stat: -rw-r--r-- 979 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-

module Plugin::Settings
  # Setting DSLの、入れ子になったsettingsだけを抜き出すためのクラス。
  class Phantom
    attr_reader :detected

    def initialize(plugin_slug, &block)
      @plugin_slug = plugin_slug
      @detected = Array.new
      begin
        instance_eval(&block)
      rescue
        @detected = [].freeze
      end
      @detected.freeze
    end

    Gtk::FormDSL.instance_methods.each do |name|
      define_method(name) do |*|
        MOCK
      end
    end

    def settings(name, &block)
      @detected << Record.new(name, block, @plugin_slug)
    end

    def method_missing(name, *rest, &block)
      case name.to_sym
      when *Gtk::FormDSL.instance_methods
        MOCK
      else
        Plugin.instance(@plugin_slug).__send__(name, *rest, &block)
      end
    end

    class Mock
      def method_missing(name, *rest, **kwrest, &block)
        MOCK
      end
    end

    MOCK = Mock.new

  end

end