Class: Wip::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/wip/initializer.rb

Overview

Builds a starter wip.yml. Detects an existing compose file next to the target (the same filenames ComposeBridge auto-detects) to decide between mode: compose-native and mode: container, since that's the one decision wip init can't leave to a placeholder.

Constant Summary collapse

TEMPLATE_LABELS =

--template values wip init accepts, and the label used in the exclude: comment.

{
  'rails' => 'Rails',
  'node' => 'Node.js',
  'rust' => 'Rust',
  'csharp' => 'C#'
}.freeze
TEMPLATE_EXCLUDES =

sync.exclude patterns written live for each --template. They mirror that stack's own github/gitignore template — directories that are either regenerated inside the container or too large/irrelevant to mirror over rsync.

{
  'rails' => %w[.git log/ tmp/ storage/ public/assets/ public/packs/ .bundle/ vendor/bundle/
                coverage/ node_modules/],
  'node' => %w[.git node_modules/ dist/ build/ .next/ .cache/ coverage/],
  'rust' => %w[.git target/],
  'csharp' => %w[.git bin/ obj/ .vs/ packages/]
}.freeze
FALLBACK_EXCLUDES =

Used when --template is omitted — the same starting point the README's own example uses.

%w[.git tmp/ node_modules/].freeze
COMMANDS_EXAMPLE =

Appended to both templates after dependencies/compose. interaction: itself is left commented since an empty interaction: {} is indistinguishable from omitting the key.

<<~YAML.chomp
  # optional; custom subcommands, e.g. `wip test` — see README
  # (interaction: is the primary key; commands: is accepted as an alias — the two are
  # mutually exclusive, so pick one)
  # interaction:
  #   test:
  #     optional; exec (default, runs in the running container) | run (fresh container) | build
  #     type: exec

  #     command: ls
YAML

Instance Method Summary collapse

Constructor Details

#initialize(dir: Dir.pwd, template: nil) ⇒ Initializer

Returns a new instance of Initializer.

Raises:



48
49
50
51
52
53
54
# File 'lib/wip/initializer.rb', line 48

def initialize(dir: Dir.pwd, template: nil)
  raise Error, "unknown --template #{template.inspect} (valid: #{TEMPLATE_LABELS.keys.join(', ')})" \
    if template && !TEMPLATE_LABELS.key?(template)

  @dir = dir
  @template = template
end

Instance Method Details

#callObject



58
59
60
# File 'lib/wip/initializer.rb', line 58

def call
  compose? ? compose_template : container_template
end

#compose?Boolean

Returns:

  • (Boolean)


56
# File 'lib/wip/initializer.rb', line 56

def compose? = !!compose_file