Class: Igniter::Extensions::Contracts::Creator::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/extensions/contracts/creator/scope.rb

Constant Summary collapse

PRESETS =
{
  app_local: {
    root: "app/lib",
    spec_root: "spec/lib",
    example_root: "examples",
    readme_path: "docs/igniter-packs/README.md",
    packaging_hints: [
      "keep the pack close to the host app while the API is still moving",
      "prefer app-local namespacing before extracting a shared gem"
    ]
  },
  monorepo_package: {
    root: "lib",
    spec_root: "spec",
    example_root: "examples",
    readme_path: "README.md",
    packaging_hints: [
      "add package-owned specs and a runnable example before promoting the pack",
      "keep the public entrypoint independent from igniter-core and contracts internals"
    ]
  },
  standalone_gem: {
    root: "lib",
    spec_root: "spec",
    example_root: "examples",
    readme_path: "README.md",
    packaging_hints: [
      "publish only after the pack has a stable public entrypoint and package-owned example",
      "treat the pack as a distributable gem with a small explicit surface"
    ]
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, root:, spec_root:, example_root:, readme_path:, packaging_hints:) ⇒ Scope

Returns a new instance of Scope.



55
56
57
58
59
60
61
62
63
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 55

def initialize(name:, root:, spec_root:, example_root:, readme_path:, packaging_hints:)
  @name = name.to_sym
  @root = root
  @spec_root = spec_root
  @example_root = example_root
  @readme_path = readme_path
  @packaging_hints = packaging_hints.dup.freeze
  freeze
end

Instance Attribute Details

#example_rootObject (readonly)

Returns the value of attribute example_root.



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 41

def example_root
  @example_root
end

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 41

def name
  @name
end

#packaging_hintsObject (readonly)

Returns the value of attribute packaging_hints.



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 41

def packaging_hints
  @packaging_hints
end

#readme_pathObject (readonly)

Returns the value of attribute readme_path.



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 41

def readme_path
  @readme_path
end

#rootObject (readonly)

Returns the value of attribute root.



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 41

def root
  @root
end

#spec_rootObject (readonly)

Returns the value of attribute spec_root.



41
42
43
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 41

def spec_root
  @spec_root
end

Class Method Details

.availableObject



43
44
45
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 43

def self.available
  PRESETS.keys
end

.build(scope) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 47

def self.build(scope)
  preset = PRESETS.fetch(scope.to_sym) do
    raise ArgumentError, "unknown creator scope #{scope.inspect}"
  end

  new(name: scope, **preset)
end

Instance Method Details

#to_hObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/igniter/extensions/contracts/creator/scope.rb', line 65

def to_h
  {
    name: name,
    root: root,
    spec_root: spec_root,
    example_root: example_root,
    readme_path: readme_path,
    packaging_hints: packaging_hints
  }
end