Module: Scales::Helper::PartialResolver
- Defined in:
- lib/scales-core/helper/partial_resolver.rb
Constant Summary collapse
- PARTIAL_REGEX =
/(Scales\.partial ["|'](.*)["|'])/
Class Method Summary collapse
- .includes_partial?(value) ⇒ Boolean
- .resolve(redis, key) ⇒ Object
- .resolve_partial(redis, value) ⇒ Object
Class Method Details
.includes_partial?(value) ⇒ Boolean
20 21 22 |
# File 'lib/scales-core/helper/partial_resolver.rb', line 20 def includes_partial?(value) value =~ PARTIAL_REGEX end |
.resolve(redis, key) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/scales-core/helper/partial_resolver.rb', line 9 def resolve(redis, key) value = redis.get(key) i = 0 while includes_partial?(value) do value = resolve_partial(redis, value) end value end |
.resolve_partial(redis, value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/scales-core/helper/partial_resolver.rb', line 24 def resolve_partial(redis, value) matched = value.match(PARTIAL_REGEX) tag, key = matched[1], matched[2] partial = redis.get(Storage::PARTIAL_PREFIX + key) value.gsub(tag, partial) end |