Class: Excom::Plugins::Executable::State
- Inherits:
-
Object
- Object
- Excom::Plugins::Executable::State
- Defined in:
- lib/excom/plugins/executable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear! ⇒ Object
-
#initialize(values = {}) ⇒ State
constructor
A new instance of State.
- #prop_names ⇒ Object
- #replace(other) ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ State
Returns a new instance of State.
23 24 25 |
# File 'lib/excom/plugins/executable.rb', line 23 def initialize(values = {}) @values = values end |
Class Method Details
.add_prop(*props) ⇒ Object
12 13 14 15 |
# File 'lib/excom/plugins/executable.rb', line 12 def self.add_prop(*props) prop_names.push(*props) props.each{ |prop| def_prop_accessor(prop) } end |
.def_prop_accessor(name) ⇒ Object
17 18 19 20 21 |
# File 'lib/excom/plugins/executable.rb', line 17 def self.def_prop_accessor(name) define_method(name) { @values[name] } define_method("#{name}=") { |value| @values[name] = value } define_method("has_#{name}?") { @values.key?(name) } end |
.prop_names ⇒ Object
8 9 10 |
# File 'lib/excom/plugins/executable.rb', line 8 def self.prop_names @prop_names ||= [] end |
Instance Method Details
#clear! ⇒ Object
27 28 29 |
# File 'lib/excom/plugins/executable.rb', line 27 def clear! @values.clear end |
#prop_names ⇒ Object
31 32 33 |
# File 'lib/excom/plugins/executable.rb', line 31 def prop_names self.class.prop_names end |
#replace(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/excom/plugins/executable.rb', line 35 def replace(other) missing_props = prop_names - other.prop_names unless missing_props.empty? raise ArgumentError, "cannot accept execution state #{other} due to missing props: #{missing_props}" end prop_names.each do |prop| @values[prop] = other.public_send(prop) end end |