Class: Collavre::Comments::ActionExecutor::ExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
app/services/collavre/comments/action_executor.rb

Defined Under Namespace

Classes: InvalidActionError

Constant Summary collapse

SUPPORTED_ACTIONS =
{
  "create_creative" => :create_creative,
  "update_creative" => :update_creative,
  "delete_creative" => :delete_creative,
  "approve_tool" => :approve_tool,
  "execute_tool" => :execute_tool
}.freeze
CREATIVE_ATTRIBUTES =
%w[description progress].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment) ⇒ ExecutionContext

Returns a new instance of ExecutionContext.



83
84
85
# File 'app/services/collavre/comments/action_executor.rb', line 83

def initialize(comment)
  @comment = comment
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



87
88
89
# File 'app/services/collavre/comments/action_executor.rb', line 87

def comment
  @comment
end

Instance Method Details

#evaluate(code) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/services/collavre/comments/action_executor.rb', line 89

def evaluate(code)
  payload = parse_payload(code)

  actions = Array(payload["actions"])
  if actions.present?
    Comment.transaction do
      actions.each do |action_payload|
        process_action(action_payload)
      end
    end
  else
    process_action(payload)
  end
end