Module: Albacore::ConfigDSL
- Included in:
- Asmver::Config, Build::Config, CmdConfig, IsPackage::Config, NugetsPack::Config, Sql::Config, SqlPackage::Config, TestRunner::Config
- Defined in:
- lib/albacore/config_dsl.rb
Overview
a small DSL to mix into your configuration classes
Instance Method Summary collapse
-
#attr_path(*syms, &block) ⇒ Object
creates a new attr_writer for the symbols passed, such that a write to that method will normalise the paths of the written value: you can pass an optional callback.
-
#attr_path_accessor(*syms, &block) ⇒ Object
read/write attribute with rewriting of set values to match the system’s paths.
Instance Method Details
#attr_path(*syms, &block) ⇒ Object
creates a new attr_writer for the symbols passed, such that a write to that method will normalise the paths of the written value: you can pass an optional callback
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/albacore/config_dsl.rb', line 9 def attr_path *syms, &block given = block_given? syms.each do |sym| # this is the callback method when the value is set self.send(:define_method, :"__on_#{sym}") do |val| instance_exec(val, &block) if given end # this is the setter, it also calls the callback method # defined above. self.class_eval( %{def #{sym}= val @#{sym} = ::Albacore::Paths.normalise_slashes val __on_#{sym} @#{sym} end}) end end |
#attr_path_accessor(*syms, &block) ⇒ Object
read/write attribute with rewriting of set values to match the system’s paths
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/albacore/config_dsl.rb', line 31 def attr_path_accessor *syms, &block given = block_given? syms.each do |sym| # this is the callback method when the value is set self.send(:define_method, :"__on_#{sym}") do |val| instance_exec(val, &block) if given end # this is the setter and getter. The setter also calls # the callback method defined above. self.class_eval( %{def #{sym}= val @#{sym} = ::Albacore::Paths.normalise_slashes val __on_#{sym} @#{sym} end}) self.class_eval( %{def #{sym} @#{sym} end}) end end |