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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# -*- coding: utf-8 -*-
module Plugin::Settings
DSL_METHODS = [
:label,
:settings,
:create_inner_setting,
:multitext,
:fileselect,
:photoselect,
:font,
:select,
:dirselect,
:inputpass,
:multi,
:about,
:listview,
:fontcolor,
:multiselect,
:adjustment,
:keybind,
:color,
:link,
:input,
:boolean
]
# Setting DSLの、入れ子になったsettingsだけを抜き出すためのクラス。
class Phantom
attr_reader :title, :plugin, :dsl_procedure
def initialize(title:, plugin:, &block)
raise ArgumentError, 'Block requred.' unless block
@title = -title
@plugin = plugin
@dsl_procedure = block
@children = nil
end
def children
return @children if @children
@children = []
instance_eval(&@dsl_procedure)
@children.freeze
rescue
@children = [].freeze
end
DSL_METHODS.each do |name|
define_method(name) do |*|
MOCK
end
end
def settings(name, &block)
@children << Phantom.new(
title: name,
plugin: @plugin,
&block
)
nil
end
def method_missing(name, *rest, &block)
case name.to_sym
when *DSL_METHODS
MOCK
else
@plugin.__send__(name, *rest, &block)
end
end
class Mock
def method_missing(name, *rest, **kwrest, &block)
MOCK
end
end
MOCK = Mock.new
end
end
|