Module: Clive::StateActions
- Included in:
- Base, Command, Option::Runner
- Defined in:
- lib/clive/option/runner.rb
Overview
Methods for modifying a state object. Requires that the instance variable @state exists and that it responds to #fetch
, #store
and #key?
.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#has?(key) ⇒ Boolean
State has
key
?. - #set(key, value) ⇒ Object
- #update(*args) ⇒ Object
Instance Method Details
#get(key) ⇒ Object
15 16 17 |
# File 'lib/clive/option/runner.rb', line 15 def get(key) @state.fetch key end |
#has?(key) ⇒ Boolean
Returns State has key
?.
77 78 79 |
# File 'lib/clive/option/runner.rb', line 77 def has?(key) @state.key? key end |
#set(key, value) ⇒ Object
27 28 29 |
# File 'lib/clive/option/runner.rb', line 27 def set(key, value) @state.store key, value end |
#update(key, method, *args) ⇒ Object #update(key, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/clive/option/runner.rb', line 53 def update(*args) if block_given? key = args.first set key, yield(get(key)) elsif args.size > 1 key, method = args.shift, args.shift set key, get(key).send(method, *args) else raise ArgumentError, "wrong number of arguments (#{args.size} for 2)" end end |