Class: Malevich::DSL
- Inherits:
-
Object
- Object
- Malevich::DSL
- Defined in:
- lib/malevich/dsl.rb
Constant Summary collapse
- PLUGIN_EXT =
'.rb'
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Class Method Summary collapse
Instance Method Summary collapse
- #always_start(val) ⇒ Object (also: #auto, #auto_start)
- #collect(*name, &block) ⇒ Object
- #critical(val) ⇒ Object (also: #critical=)
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #interval(val) ⇒ Object
- #run_if(*name, &block) ⇒ Object
- #settings(attr, val) ⇒ Object (also: #config, #defaults, #plugin)
- #state(attr, val) ⇒ Object (also: #states)
- #warning(val) ⇒ Object (also: #warning=)
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
8 9 10 |
# File 'lib/malevich/dsl.rb', line 8 def initialize @plugins = Array.new end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
6 7 8 |
# File 'lib/malevich/dsl.rb', line 6 def plugins @plugins end |
Class Method Details
.load(paths) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/malevich/dsl.rb', line 59 def self.load(paths) dsl = Malevich::DSL.new paths.map do |path| File.directory?(path) ? Dir["#{path}/*#{PLUGIN_EXT}"].sort : path end.flatten.each do |path| begin log :debug, "Load plugin #{path}" dsl.plugins << Malevich::Plugin.new(File.basename(path, PLUGIN_EXT)) dsl.instance_eval(File.read(path), path) rescue ScriptError dsl.plugins.pop # todo: plugin.new creates log :error, "ScriptError: plugin from file #{path}" end end dsl.plugins end |
Instance Method Details
#always_start(val) ⇒ Object Also known as: auto, auto_start
16 17 18 |
# File 'lib/malevich/dsl.rb', line 16 def always_start(val) plugins.last.always_start = !!val end |
#collect(*name, &block) ⇒ Object
54 55 56 57 |
# File 'lib/malevich/dsl.rb', line 54 def collect(*name, &block) return unless plugins.last.suitable_platform?(name) plugins.last.collect = block end |
#critical(val) ⇒ Object Also known as: critical=
34 35 36 |
# File 'lib/malevich/dsl.rb', line 34 def critical(val) plugins.last.settings[:critical] = val end |
#interval(val) ⇒ Object
12 13 14 |
# File 'lib/malevich/dsl.rb', line 12 def interval(val) plugins.last.interval = val.to_f end |
#run_if(*name, &block) ⇒ Object
23 24 25 26 |
# File 'lib/malevich/dsl.rb', line 23 def run_if(*name, &block) return unless plugins.last.suitable_platform?(name) plugins.last.run_if = block end |
#settings(attr, val) ⇒ Object Also known as: config, defaults, plugin
46 47 48 |
# File 'lib/malevich/dsl.rb', line 46 def settings(attr, val) plugins.last.settings[attr] = val end |
#state(attr, val) ⇒ Object Also known as: states
28 29 30 |
# File 'lib/malevich/dsl.rb', line 28 def state(attr, val) plugins.last.settings[attr] = val end |
#warning(val) ⇒ Object Also known as: warning=
40 41 42 |
# File 'lib/malevich/dsl.rb', line 40 def warning(val) plugins.last.settings[:warning] = val end |