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. commands: itself is left commented since an empty commands: {} is indistinguishable from omitting the key.

<<~YAML.chomp
  # optional; custom subcommands, e.g. `wip test` — see README
  # commands:
  #   test:
  #     optional; exec (default, runs in the running container) | run (fresh container) | build
  #     type: exec

  #     TODO
  #     command: bundle exec rspec
YAML

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Initializer.

Raises:



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

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



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

def call
  compose? ? compose_template : container_template
end

#compose?Boolean

Returns:

  • (Boolean)


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

def compose? = !!compose_file