Module: Querylet::Context
- Included in:
- Querylet
- Defined in:
- lib/querylet/context.rb
Instance Method Summary collapse
- #add_item(key, value) ⇒ Object
- #add_items(hash) ⇒ Object
- #get(value) ⇒ Object
- #with_temporary_context(args = {}) ⇒ Object
Instance Method Details
#add_item(key, value) ⇒ Object
7 8 9 |
# File 'lib/querylet/context.rb', line 7 def add_item(key, value) locals[key.to_sym] = value end |
#add_items(hash) ⇒ Object
11 12 13 |
# File 'lib/querylet/context.rb', line 11 def add_items(hash) hash.map { |k, v| add_item(k, v) } end |
#get(value) ⇒ Object
3 4 5 |
# File 'lib/querylet/context.rb', line 3 def get(value) @data.merge(locals)[value.to_sym] end |
#with_temporary_context(args = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/querylet/context.rb', line 15 def with_temporary_context(args = {}) saved = args.keys.collect { |key| [key, get(key.to_s)] }.to_h add_items(args) block_result = yield locals.merge!(saved) block_result end |