| 1 |
|
| 2 |
|
| 3 |
module Plugin::Settings |
| 4 |
DSL_METHODS = [ |
| 5 |
:label, |
| 6 |
:settings, |
| 7 |
:create_inner_setting, |
| 8 |
:multitext, |
| 9 |
:fileselect, |
| 10 |
:photoselect, |
| 11 |
:font, |
| 12 |
:select, |
| 13 |
:dirselect, |
| 14 |
:inputpass, |
| 15 |
:multi, |
| 16 |
:about, |
| 17 |
:listview, |
| 18 |
:fontcolor, |
| 19 |
:multiselect, |
| 20 |
:adjustment, |
| 21 |
:keybind, |
| 22 |
:color, |
| 23 |
:link, |
| 24 |
:input, |
| 25 |
:boolean |
| 26 |
] |
| 27 |
ingsだけを抜き出すためのクラス。 |
| 28 |
class Phantom |
| 29 |
attr_reader :title, :plugin, :dsl_procedure |
| 30 |
|
| 31 |
def initialize(title:, plugin:, &block) |
| 32 |
raise ArgumentError, 'Block requred.' unless block |
| 33 |
@title = -title |
| 34 |
@plugin = plugin |
| 35 |
@dsl_procedure = block |
| 36 |
@children = nil |
| 37 |
end |
| 38 |
|
| 39 |
def children |
| 40 |
return @children if @children |
| 41 |
@children = [] |
| 42 |
instance_eval(&@dsl_procedure) |
| 43 |
@children.freeze |
| 44 |
rescue |
| 45 |
@children = [].freeze |
| 46 |
end |
| 47 |
|
| 48 |
DSL_METHODS.each do |name| |
| 49 |
define_method(name) do |*| |
| 50 |
MOCK |
| 51 |
end |
| 52 |
end |
| 53 |
|
| 54 |
def settings(name, &block) |
| 55 |
@children << Phantom.new( |
| 56 |
title: name, |
| 57 |
plugin: @plugin, |
| 58 |
&block |
| 59 |
) |
| 60 |
nil |
| 61 |
end |
| 62 |
|
| 63 |
def method_missing(name, *rest, &block) |
| 64 |
case name.to_sym |
| 65 |
when *DSL_METHODS |
| 66 |
MOCK |
| 67 |
else |
| 68 |
@plugin.__send__(name, *rest, &block) |
| 69 |
end |
| 70 |
end |
| 71 |
|
| 72 |
class Mock |
| 73 |
def method_missing(name, *rest, **kwrest, &block) |
| 74 |
MOCK |
| 75 |
end |
| 76 |
end |
| 77 |
|
| 78 |
MOCK = Mock.new |
| 79 |
|
| 80 |
end |
| 81 |
|
| 82 |
end |