Class: Hyraft::Rule::PortCommand

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

Class Method Summary collapse

Class Method Details

.port_template(port_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hyraft/rule/engine/port_command.rb', line 37

def self.port_template(port_name)
  <<~RUBY
    class #{port_name} < Engine::Port
      def save(entity)
        raise NotImplementedError
      end
      
      def all
        raise NotImplementedError
      end
      
      def find(id)
        raise NotImplementedError
      end
      
      def delete(id)
        raise NotImplementedError
      end
    end
  RUBY
end

.show_usageObject



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

def self.show_usage
  puts "Usage: hyraft-rule port <PortName> [target_dir]"
  puts ""
  puts "Examples:"
  puts "  hyraft-rule port ArticlesGatewayPort"
  puts "  hyraft-rule port UsersGatewayPort"
  puts "  hyraft-rule port ProductsGatewayPort"
  puts ""
  puts "This creates interface ports in engine/port/"
end

.start(args) ⇒ Object



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

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

  target_dir = args[1] || "."
  port_dir = File.join(target_dir, "engine/port")
  # Convert CamelCase to snake_case with underscore
  filename = port_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase + ".rb"
  full_path = File.join(port_dir, filename)

  FileUtils.mkdir_p(port_dir)
  File.write(full_path, port_template(port_name))

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