Class: Hyraft::Rule::Circuit::PortCommand
- Inherits:
-
Object
- Object
- Hyraft::Rule::Circuit::PortCommand
- Defined in:
- lib/hyraft/rule/circuit/port_command.rb
Defined Under Namespace
Classes: Command
Class Method Summary collapse
Class Method Details
.generate_content(cmd) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hyraft/rule/circuit/port_command.rb', line 35 def self.generate_content(cmd) <<~RUBY # circuit/ports/#{cmd.filename} class #{cmd.class_name}InputPort < Hyraft::Port def create(#{cmd.singular_name}) = raise NotImplementedError def get(id) = raise NotImplementedError def list = raise NotImplementedError def update(id, #{cmd.singular_name}) = raise NotImplementedError def delete(id) = raise NotImplementedError end class #{cmd.class_name}OutputPort < Hyraft::Port def save(#{cmd.singular_name}) = raise NotImplementedError def find(id) = raise NotImplementedError def all = raise NotImplementedError def delete(id) = raise NotImplementedError end RUBY end |
.show_usage ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hyraft/rule/circuit/port_command.rb', line 56 def self.show_usage puts <<~USAGE Usage: hyraft-rule port <resource_name> [target_dir] Examples: hyraft-rule port articles hyraft-rule port users ./myapp This creates: circuit/ports/<resource_name>_port.rb USAGE end |
.start(args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hyraft/rule/circuit/port_command.rb', line 20 def self.start(args) return show_usage if args.empty? cmd = Command.new( resource_name: args[0], target_dir: args[1]&.match?(%r{[/.]|\.\.|\.\/}) ? args[1] : "." ) FileUtils.mkdir_p(cmd.port_dir) File.write(cmd.full_path, generate_content(cmd)) puts "\e[94m✓ Created port: #{cmd.full_path}\e[0m" puts "\e[38;5;214mResource: #{cmd.plural_name}\e[0m" end |