Class: Hyraft::Rule::CircuitCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/hyraft/rule/engine/circuit_command.rb

Class Method Summary collapse

Class Method Details

.circuit_template(circuit_name) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hyraft/rule/engine/circuit_command.rb', line 36

def self.circuit_template(circuit_name)
  <<~RUBY
    class #{circuit_name} < Engine::Circuit
      def initialize(gateway)
        @gateway = gateway
      end

      def create(params)
        # Implement create logic
      end

      def find(id)
        # Implement find logic
      end

      def list
        # Implement list logic
      end

      def update(params)
        # Implement update logic
      end

      def delete(id)
        # Implement delete logic
      end

      def execute(input = {})
        operation = input[:operation]
        params = input[:params] || {}
        
        case operation
        when :create then create(params)
        when :list then list
        when :find then find(params[:id])
        when :update then update(params)
        when :delete then delete(params[:id])
        else
          raise "Unknown operation: \#{operation}"
        end
      end
    end
  RUBY
end

.show_usageObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/hyraft/rule/engine/circuit_command.rb', line 25

def self.show_usage
  puts "Usage: hyraft-rule circuit <CircuitName> [target_dir]"
  puts ""
  puts "Examples:"
  puts "  hyraft-rule circuit ArticlesCircuit"
  puts "  hyraft-rule circuit UsersCircuit"
  puts "  hyraft-rule circuit ProductsCircuit"
  puts ""
  puts "This creates business processes in engine/circuit/"
end

.start(args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hyraft/rule/engine/circuit_command.rb', line 8

def self.start(args)
  circuit_name = args[0]
  return show_usage unless circuit_name

  target_dir = args[1] || "."
  circuit_dir = File.join(target_dir, "engine/circuit")
  filename = circuit_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase + ".rb"
  full_path = File.join(circuit_dir, filename)

  FileUtils.mkdir_p(circuit_dir)
  File.write(full_path, circuit_template(circuit_name))

  puts "✓ Created circuit: #{full_path}"
end