Class: Rmk::Vars
- Inherits:
-
Hash
- Object
- Hash
- Rmk::Vars
- Defined in:
- lib/rmk/vars.rb
Instance Attribute Summary collapse
-
#rmk ⇒ Object
readonly
Returns the value of attribute rmk.
-
#upstream ⇒ Object
readonly
Returns the value of attribute upstream.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, append = false, value) ⇒ Object
-
#downstream_new(clone_rmk: false) ⇒ Object
create new downstream vars which will lookup first, when not found then lookup current obj.
- #include?(name, inherit = true) ⇒ Boolean
-
#initialize(rmk, upstream) ⇒ Vars
constructor
A new instance of Vars.
-
#interpolate_str(str) ⇒ Object
preprocess str, and then unescape the result.
- #keys(inherit = true) ⇒ Object
- #org_keys ⇒ Object
-
#preprocess_str(str) ⇒ Object
only do #w+ interpolate.
-
#split_str(str) ⇒ Array<String>
preprocess str,and then split use white spaces, and then unescape each result, typically used for split file list.
-
#unescape_str(str) ⇒ Object
do all ‘$’ prefix escape str interpolate.
Constructor Details
#initialize(rmk, upstream) ⇒ Vars
Returns a new instance of Vars.
7 |
# File 'lib/rmk/vars.rb', line 7 def initialize(rmk, upstream) @rmk, @upstream = rmk, upstream end |
Instance Attribute Details
#rmk ⇒ Object (readonly)
Returns the value of attribute rmk.
8 9 10 |
# File 'lib/rmk/vars.rb', line 8 def rmk @rmk end |
#upstream ⇒ Object (readonly)
Returns the value of attribute upstream.
8 9 10 |
# File 'lib/rmk/vars.rb', line 8 def upstream @upstream end |
Instance Method Details
#[](name) ⇒ Object
16 |
# File 'lib/rmk/vars.rb', line 16 def [](name) @rmk[name] || fetch(name) end |
#[]=(name, append = false, value) ⇒ Object
18 19 20 21 |
# File 'lib/rmk/vars.rb', line 18 def []=(name, append = false, value) value = interpolate_str value.to_s super name, append ? self[name].to_s + value : value end |
#downstream_new(clone_rmk: false) ⇒ Object
create new downstream vars which will lookup first, when not found then lookup current obj
12 |
# File 'lib/rmk/vars.rb', line 12 def downstream_new(clone_rmk:false) Rmk::Vars.new clone_rmk ? @rmk.clone(freeze:false) : @rmk, self end |
#include?(name, inherit = true) ⇒ Boolean
25 |
# File 'lib/rmk/vars.rb', line 25 def include?(name, inherit = true) inherit ? @rmk.include?(name) || member?(name) : super(name) end |
#interpolate_str(str) ⇒ Object
preprocess str, and then unescape the result
40 |
# File 'lib/rmk/vars.rb', line 40 def interpolate_str(str) unescape_str preprocess_str str end |
#keys(inherit = true) ⇒ Object
31 |
# File 'lib/rmk/vars.rb', line 31 def keys(inherit = true) inherit ? @rmk.keys + get_keys : super() end |
#org_keys ⇒ Object
27 |
# File 'lib/rmk/vars.rb', line 27 alias_method :org_keys, :keys |
#preprocess_str(str) ⇒ Object
only do #w+ interpolate
34 |
# File 'lib/rmk/vars.rb', line 34 def preprocess_str(str) str.gsub(/\$((?:\$\$)*){(\w+)}/){"#{$1}#{self[$2]}"} end |
#split_str(str) ⇒ Array<String>
preprocess str,and then split use white spaces, and then unescape each result, typically used for split file list
45 46 47 48 49 50 51 52 53 |
# File 'lib/rmk/vars.rb', line 45 def split_str(str) str = preprocess_str str result = [] until str.empty? head, _, str = str.partition /(?<!\$)(?:\$\$)*\K\s+/ result << unescape_str(head) unless head.empty? end result end |
#unescape_str(str) ⇒ Object
do all ‘$’ prefix escape str interpolate
37 |
# File 'lib/rmk/vars.rb', line 37 def unescape_str(str) str.gsub(/\$(?:([\$\s>&])|(\w+))/){$1 || self[$2]} end |