Class: Igniter::Extensions::Contracts::Creator::Wizard
- Inherits:
-
Object
- Object
- Igniter::Extensions::Contracts::Creator::Wizard
- Defined in:
- lib/igniter/extensions/contracts/creator/wizard.rb
Constant Summary collapse
- PROFILE_EXAMPLES =
{ feature_node: ["examples/contracts/build_your_own_pack.rb"], diagnostic_bundle: ["examples/contracts/debug.rb", "examples/contracts/debug_pack_authoring.rb"], operational_adapter: ["examples/contracts/build_effect_executor_pack.rb", "examples/contracts/journal.rb"], bundle_pack: ["examples/contracts/compose_your_own_packs.rb", "examples/contracts/commerce.rb"] }.freeze
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#pack ⇒ Object
readonly
Returns the value of attribute pack.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#target_profile ⇒ Object
readonly
Returns the value of attribute target_profile.
Instance Method Summary collapse
- #apply(**updates) ⇒ Object
- #authoring_profile ⇒ Object
- #branching_hints ⇒ Object
- #current_decision ⇒ Object
- #effective_root ⇒ Object
-
#initialize(name: nil, kind: nil, namespace: "MyCompany::IgniterPacks", profile: nil, capabilities: nil, scope: nil, root: nil, mode: :skip_existing, pack: nil, target_profile: nil) ⇒ Wizard
constructor
A new instance of Wizard.
- #pending_decisions ⇒ Object
- #ready_for_workflow? ⇒ Boolean
- #ready_for_writer? ⇒ Boolean
- #recommended_examples ⇒ Object
- #recommended_packs ⇒ Object
- #suggested_root ⇒ Object
- #target_scope ⇒ Object
- #to_h ⇒ Object
- #workflow ⇒ Object
- #writer ⇒ Object
Constructor Details
#initialize(name: nil, kind: nil, namespace: "MyCompany::IgniterPacks", profile: nil, capabilities: nil, scope: nil, root: nil, mode: :skip_existing, pack: nil, target_profile: nil) ⇒ Wizard
Returns a new instance of Wizard.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 17 def initialize(name: nil, kind: nil, namespace: "MyCompany::IgniterPacks", profile: nil, capabilities: nil, scope: nil, root: nil, mode: :skip_existing, pack: nil, target_profile: nil) @name = normalize_name(name) @kind = kind&.to_sym @namespace = normalize_namespace(namespace) @profile = profile&.to_sym @capabilities = Array(capabilities).map(&:to_sym).uniq.freeze @scope = scope&.to_sym @root = root&.to_s @mode = mode.to_sym @pack = pack @target_profile = target_profile freeze end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def capabilities @capabilities end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def kind @kind end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def namespace @namespace end |
#pack ⇒ Object (readonly)
Returns the value of attribute pack.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def pack @pack end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def profile @profile end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def root @root end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def scope @scope end |
#target_profile ⇒ Object (readonly)
Returns the value of attribute target_profile.
15 16 17 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 15 def target_profile @target_profile end |
Instance Method Details
#apply(**updates) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 32 def apply(**updates) self.class.new( name: updates.fetch(:name, name), kind: updates.fetch(:kind, kind), namespace: updates.fetch(:namespace, namespace), profile: updates.fetch(:profile, profile), capabilities: updates.fetch(:capabilities, capabilities), scope: updates.fetch(:scope, scope), root: updates.fetch(:root, root), mode: updates.fetch(:mode, mode), pack: updates.fetch(:pack, pack), target_profile: updates.fetch(:target_profile, target_profile) ) end |
#authoring_profile ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 47 def return nil unless profile || kind || !capabilities.empty? Profile.build( profile: profile, kind: kind, capabilities: capabilities ) end |
#branching_hints ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 147 def branching_hints return [] unless hints = [] case .kind when :operational hints << "operational adapters usually want dev-time help from Igniter::Extensions::Contracts::JournalPack" hints << "prefer standalone_gem when the adapter will be reused across hosts" when :bundle if .capability?(:diagnostic) hints << "diagnostic bundles usually compose Igniter::Extensions::Contracts::ExecutionReportPack and Igniter::Extensions::Contracts::ProvenancePack" hints << "keep DebugPack as a development helper unless the bundle truly needs a runtime-facing debug surface" else hints << "bundle packs should stay thin and explicit about which packs they compose" end when :feature hints << "feature node packs often start app-local before being promoted into a monorepo package or gem" end hints.concat(.development_hints) hints.uniq end |
#current_decision ⇒ Object
128 129 130 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 128 def current_decision pending_decisions.first end |
#effective_root ⇒ Object
71 72 73 74 75 76 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 71 def effective_root return root unless root.nil? || root.empty? return nil unless scope suggested_root end |
#pending_decisions ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 87 def pending_decisions decisions = [] unless name decisions << { key: :name, prompt: "Choose a short pack name", options: [], hints: ["pick the public noun you want pack users to reach for"] } end unless decisions << { key: :profile, prompt: "Choose an authoring profile or provide capabilities", options: , hints: ["feature packs add graph semantics; operational packs add effect/executor behavior; bundles compose packs without semantic mutation"] } end unless target_scope decisions << { key: :scope, prompt: "Choose the target scope for the pack", options: , hints: branching_hints } end if ready_for_workflow? && root.nil? decisions << { key: :root, prompt: "Choose the filesystem root for generated files", options: [suggested_root].compact, hints: ["default root follows the chosen scope; override it only if the host repo layout needs it"] } end decisions end |
#ready_for_workflow? ⇒ Boolean
63 64 65 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 63 def ready_for_workflow? !name.nil? && !.nil? && !target_scope.nil? end |
#ready_for_writer? ⇒ Boolean
67 68 69 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 67 def ready_for_writer? ready_for_workflow? && !effective_root.nil? end |
#recommended_examples ⇒ Object
141 142 143 144 145 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 141 def recommended_examples return [] unless PROFILE_EXAMPLES.fetch(.name, PROFILE_EXAMPLES.fetch(fallback_profile_name, [])) end |
#recommended_packs ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 132 def recommended_packs return { runtime: [], development: [] } unless { runtime: .runtime_dependency_hints, development: .development_dependency_hints } end |
#suggested_root ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 78 def suggested_root case scope when :standalone_gem name ? "./#{name}" : "./my_pack" when :app_local, :monorepo_package "." end end |
#target_scope ⇒ Object
57 58 59 60 61 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 57 def target_scope return nil unless scope Scope.build(scope) end |
#to_h ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 195 def to_h { name: name, kind: kind, namespace: namespace, profile: profile, capabilities: capabilities, scope: scope, root: root, suggested_root: suggested_root, effective_root: effective_root, mode: mode, ready_for_workflow: ready_for_workflow?, ready_for_writer: ready_for_writer?, authoring_profile: &.to_h, target_scope: target_scope&.to_h, recommended_packs: recommended_packs, recommended_examples: recommended_examples, branching_hints: branching_hints, pending_decisions: pending_decisions } end |
#workflow ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 170 def workflow unless ready_for_workflow? raise ArgumentError, "creator wizard is missing decisions: #{pending_decisions.map do |decision| decision.fetch(:key) end.join(", ")}" end CreatorPack.workflow( name: name, kind: kind, namespace: namespace, profile: profile, capabilities: capabilities, scope: scope, pack: pack, target_profile: target_profile ) end |
#writer ⇒ Object
189 190 191 192 193 |
# File 'lib/igniter/extensions/contracts/creator/wizard.rb', line 189 def writer raise ArgumentError, "creator wizard needs a root before writing scaffold files" unless ready_for_writer? workflow.writer(root: effective_root, mode: mode) end |