Class: Action::State

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
Wisper::Publisher
Defined in:
lib/action/state.rb,
lib/action/state/class_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

sequence_status

Constructor Details

#initialize(options = {}) ⇒ State

Returns a new instance of State.



11
12
13
14
15
16
17
# File 'lib/action/state.rb', line 11

def initialize options = {}
  options = options.symbolize_keys
  @action_class = options[:action_class]
  @action_class = @action_class.constantize if String === @action_class
  @config = options.fetch(:config, ActiveSupport::OrderedHash.new)
  @status = options.fetch(:status, :initial).to_sym
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/action/state.rb', line 9

def status
  @status
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/action/state.rb', line 38

def == other
  self.class == other.class && self.to_h == other.to_h
end

#create_actionObject



19
20
21
22
23
24
# File 'lib/action/state.rb', line 19

def create_action
  @action_class.new.configure do |config|
    config.replace(@config)
    config.freeze
  end
end

#to_hObject



30
31
32
33
34
35
36
# File 'lib/action/state.rb', line 30

def to_h
  {
    action_class: @action_class.name,
    config: @config,
    status: @status,
  }
end

#to_json(*options) ⇒ Object



26
27
28
# File 'lib/action/state.rb', line 26

def to_json *options
  to_h.to_json(*options)
end