lib/operatic/result.rb in operatic-0.4.0 vs lib/operatic/result.rb in operatic-0.5.0

- old
+ new

@@ -1,9 +1,9 @@ module Operatic class Result # Generate a subclass of {Result} with named +attrs+ accessors. This - # wouldn't normally be called directly, see {ClassMethods#result} for + # wouldn't normally be called directly, see {ClassMethods#result_attr} for # example usage. # # @param attrs [Array<Symbol>] a list of convenience data accessors. def self.generate(*attrs) Class.new(self) do @@ -20,9 +20,19 @@ end def initialize @data = {} @success = true + end + + # Read data that's attached to the result. + def [](key) + @data[key] + end + + # Set data on the result. + def []=(key, value) + @data[key] = value end # Mark the result as a failure, optionally attach +data+ via kwargs, and # freeze the object so it cannot be modified further. #