cuprum-cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/README.md +10 -0
  4. data/lib/cuprum/cli/argument.rb +2 -2
  5. data/lib/cuprum/cli/command.rb +2 -4
  6. data/lib/cuprum/cli/commands/ci/rspec_each_command.rb +34 -8
  7. data/lib/cuprum/cli/commands/ci.rb +8 -0
  8. data/lib/cuprum/cli/commands/file/new_command.rb +42 -49
  9. data/lib/cuprum/cli/commands/file.rb +8 -5
  10. data/lib/cuprum/cli/dependencies/clock/mock.rb +28 -0
  11. data/lib/cuprum/cli/dependencies/clock.rb +29 -0
  12. data/lib/cuprum/cli/dependencies/file_system/mock.rb +150 -18
  13. data/lib/cuprum/cli/dependencies/file_system.rb +145 -10
  14. data/lib/cuprum/cli/dependencies.rb +2 -0
  15. data/lib/cuprum/cli/errors.rb +0 -1
  16. data/lib/cuprum/cli/{commands/file/generate_file.rb → files/create_file.rb} +6 -48
  17. data/lib/cuprum/cli/{commands/file → files/engines}/render_erb.rb +6 -6
  18. data/lib/cuprum/cli/files/engines.rb +76 -0
  19. data/lib/cuprum/cli/{errors/files → files/errors}/file_not_writeable.rb +3 -3
  20. data/lib/cuprum/cli/files/errors/generator_error.rb +46 -0
  21. data/lib/cuprum/cli/{errors/files → files/errors}/missing_parameter.rb +5 -5
  22. data/lib/cuprum/cli/{errors/files → files/errors}/missing_template.rb +3 -3
  23. data/lib/cuprum/cli/{errors/files → files/errors}/template_error.rb +3 -3
  24. data/lib/cuprum/cli/files/errors.rb +19 -0
  25. data/lib/cuprum/cli/files/generator.rb +431 -0
  26. data/lib/cuprum/cli/files/generators/basic_generator.rb +15 -0
  27. data/lib/cuprum/cli/files/generators/rspec_generator.rb +19 -0
  28. data/lib/cuprum/cli/files/generators/ruby_generator.rb +32 -0
  29. data/lib/cuprum/cli/files/generators.rb +25 -0
  30. data/lib/cuprum/cli/files/template.rb +62 -0
  31. data/lib/cuprum/cli/files/templates/basic_template.rb +39 -0
  32. data/lib/cuprum/cli/files/templates/file_template.rb +60 -0
  33. data/lib/cuprum/cli/files/templates/string_template.rb +29 -0
  34. data/lib/cuprum/cli/files/templates.rb +59 -0
  35. data/lib/cuprum/cli/files.rb +18 -0
  36. data/lib/cuprum/cli/integrations/async/commands/rspec_each_command.rb +32 -0
  37. data/lib/cuprum/cli/integrations/async/commands.rb +11 -0
  38. data/lib/cuprum/cli/integrations/async.rb +21 -0
  39. data/lib/cuprum/cli/integrations/thor/registry.rb +7 -29
  40. data/lib/cuprum/cli/integrations/thor/task.rb +37 -7
  41. data/lib/cuprum/cli/metadata.rb +54 -5
  42. data/lib/cuprum/cli/option.rb +10 -4
  43. data/lib/cuprum/cli/options/class_methods.rb +19 -1
  44. data/lib/cuprum/cli/registry.rb +131 -55
  45. data/lib/cuprum/cli/rspec/deferred/dependencies/file_system_examples.rb +1303 -1001
  46. data/lib/cuprum/cli/rspec/deferred/generators_examples.rb +112 -0
  47. data/lib/cuprum/cli/rspec/deferred/metadata_examples.rb +300 -0
  48. data/lib/cuprum/cli/rspec/deferred/options_examples.rb +8 -2
  49. data/lib/cuprum/cli/rspec/deferred/registry_examples.rb +343 -108
  50. data/lib/cuprum/cli/rspec/deferred/templates_examples.rb +183 -0
  51. data/lib/cuprum/cli/version.rb +1 -1
  52. data/lib/cuprum/cli.rb +1 -0
  53. metadata +31 -14
  54. data/lib/cuprum/cli/commands/file/resolve_template.rb +0 -136
  55. data/lib/cuprum/cli/commands/file/templates.rb +0 -71
  56. data/lib/cuprum/cli/errors/files/template_not_resolved.rb +0 -54
  57. data/lib/cuprum/cli/errors/files.rb +0 -19
  58. /data/lib/cuprum/cli/{commands/file → files}/templates/rspec.rb.erb +0 -0
  59. /data/lib/cuprum/cli/{commands/file → files}/templates/ruby.rb.erb +0 -0
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/sleeping_king_studios/deferred/provider'
4
+
5
+ require 'cuprum/cli/rspec/deferred'
6
+
7
+ module Cuprum::Cli::RSpec::Deferred
8
+ # Deferred examples for testing file generator templates.
9
+ module TemplatesExamples
10
+ include RSpec::SleepingKingStudios::Deferred::Provider
11
+
12
+ deferred_examples 'should apply the configured engine' do
13
+ context 'when initialized with engine: ERB' do
14
+ let(:engine) { Cuprum::Cli::Files::Engines::ERB }
15
+ let(:options) { super().merge(engine:) }
16
+ let(:parameters) { defined?(super()) ? super() : {} }
17
+
18
+ it 'should return a passing result with the rendered template' do
19
+ expect(template.call(**parameters))
20
+ .to be_a_passing_result
21
+ .with_value(raw_value)
22
+ end
23
+
24
+ describe 'with extra parameters' do
25
+ let(:parameters) { super().merge(extra_parameter: 'extra value') }
26
+
27
+ it 'should return a passing result with the rendered template' do
28
+ expect(template.call(**parameters))
29
+ .to be_a_passing_result
30
+ .with_value(raw_value)
31
+ end
32
+ end
33
+
34
+ describe 'with a parameterized template' do
35
+ let(:raw_value) { '<h1><%= greeting %></h1>' }
36
+
37
+ describe 'with a missing parameter' do
38
+ let(:expected_template_name) do
39
+ next unless defined?(template_name)
40
+
41
+ value = template_name
42
+
43
+ value = instance_exec(&value) if value.is_a?(Proc)
44
+
45
+ value
46
+ end
47
+ let(:expected_error) do
48
+ Cuprum::Cli::Files::Errors::MissingParameter.new(
49
+ message: 'unable to render ERB template',
50
+ parameter_name: :greeting,
51
+ template_name: expected_template_name
52
+ )
53
+ end
54
+
55
+ it 'should return a failing result' do
56
+ expect(template.call(**parameters))
57
+ .to be_a_failing_result
58
+ .with_error(expected_error)
59
+ end
60
+ end
61
+
62
+ describe 'with a parameter of invalid type' do
63
+ let(:raw_value) { "<h1><%= greetings.join(', ') %></h1>" }
64
+ let(:parameters) do
65
+ super().merge(greetings: 'Greetings, starfighter!')
66
+ end
67
+ let(:expected_template_name) do
68
+ next unless defined?(template_name)
69
+
70
+ value = template_name
71
+
72
+ value = instance_exec(&value) if value.is_a?(Proc)
73
+
74
+ value
75
+ end
76
+ let(:expected_error) do
77
+ message =
78
+ begin
79
+ 'Greetings, starfighter!'.join
80
+ rescue NameError => exception
81
+ exception.message
82
+ end
83
+
84
+ Cuprum::Cli::Files::Errors::TemplateError.new(
85
+ message: "unable to render ERB template - #{message}",
86
+ template_name: expected_template_name
87
+ )
88
+ end
89
+
90
+ it 'should return a failing result' do
91
+ expect(template.call(**parameters))
92
+ .to be_a_failing_result
93
+ .with_error(expected_error)
94
+ end
95
+ end
96
+
97
+ describe 'with valid parameters' do
98
+ let(:parameters) do
99
+ super().merge(greeting: 'Greetings, starfighter!')
100
+ end
101
+ let(:expected_value) do
102
+ "<h1>#{parameters[:greeting]}</h1>"
103
+ end
104
+
105
+ it 'should return a passing result' do
106
+ expect(template.call(**parameters))
107
+ .to be_a_passing_result
108
+ .with_value(expected_value)
109
+ end
110
+ end
111
+
112
+ describe 'with extra parameters' do
113
+ let(:parameters) do
114
+ super().merge(
115
+ extra_parameter: 'extra value',
116
+ greeting: 'Greetings, starfighter!'
117
+ )
118
+ end
119
+ let(:expected_value) do
120
+ "<h1>#{parameters[:greeting]}</h1>"
121
+ end
122
+
123
+ it 'should return a passing result' do
124
+ expect(template.call(**parameters))
125
+ .to be_a_passing_result
126
+ .with_value(expected_value)
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ context 'when initialized with engine: an unknown engine' do
133
+ let(:engine) { 'spec.undefined.engine' }
134
+ let(:options) { super().merge(engine:) }
135
+ let(:parameters) { defined?(super()) ? super() : {} }
136
+ let(:expected_error) do
137
+ details = "unknown template engine #{engine.inspect}"
138
+
139
+ Cuprum::Cli::Files::Errors::TemplateError.new(
140
+ details:,
141
+ message: "unable to render template - #{details}"
142
+ )
143
+ end
144
+
145
+ it 'should return a failing result with a template error' do
146
+ expect(template.call(**parameters))
147
+ .to be_a_failing_result
148
+ .with_error(expected_error)
149
+ end
150
+ end
151
+ end
152
+
153
+ deferred_examples 'should implement the Template interface' do
154
+ describe '#call' do
155
+ let(:parameters) do
156
+ defined?(super()) ? super() : { parameter: 'value' }
157
+ end
158
+
159
+ it 'should define the method' do
160
+ expect(subject)
161
+ .to be_callable
162
+ .with(0).arguments
163
+ .and_any_keywords
164
+ end
165
+ end
166
+
167
+ describe '#engine' do
168
+ include_examples 'should define reader', :engine, nil
169
+
170
+ context 'when initialized with engine: value' do
171
+ let(:engine) { Cuprum::Cli::Files::Engines::ERB }
172
+ let(:options) { super().merge(engine:) }
173
+
174
+ it { expect(subject.engine).to be engine }
175
+ end
176
+ end
177
+
178
+ describe '#raw_value' do
179
+ include_examples 'should define private reader', :raw_value
180
+ end
181
+ end
182
+ end
183
+ end
@@ -11,7 +11,7 @@ module Cuprum
11
11
  # Major version.
12
12
  MAJOR = 0
13
13
  # Minor version.
14
- MINOR = 1
14
+ MINOR = 2
15
15
  # Patch version.
16
16
  PATCH = 0
17
17
  # Prerelease version.
data/lib/cuprum/cli.rb CHANGED
@@ -16,6 +16,7 @@ module Cuprum
16
16
  autoload :Commands, 'cuprum/cli/commands'
17
17
  autoload :Dependencies, 'cuprum/cli/dependencies'
18
18
  autoload :Errors, 'cuprum/cli/errors'
19
+ autoload :Files, 'cuprum/cli/files'
19
20
  autoload :Metadata, 'cuprum/cli/metadata'
20
21
  autoload :Option, 'cuprum/cli/option'
21
22
  autoload :Options, 'cuprum/cli/options'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuprum-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
@@ -95,14 +95,10 @@ files:
95
95
  - lib/cuprum/cli/commands/ci/rspec_each_command.rb
96
96
  - lib/cuprum/cli/commands/echo_command.rb
97
97
  - lib/cuprum/cli/commands/file.rb
98
- - lib/cuprum/cli/commands/file/generate_file.rb
99
98
  - lib/cuprum/cli/commands/file/new_command.rb
100
- - lib/cuprum/cli/commands/file/render_erb.rb
101
- - lib/cuprum/cli/commands/file/resolve_template.rb
102
- - lib/cuprum/cli/commands/file/templates.rb
103
- - lib/cuprum/cli/commands/file/templates/rspec.rb.erb
104
- - lib/cuprum/cli/commands/file/templates/ruby.rb.erb
105
99
  - lib/cuprum/cli/dependencies.rb
100
+ - lib/cuprum/cli/dependencies/clock.rb
101
+ - lib/cuprum/cli/dependencies/clock/mock.rb
106
102
  - lib/cuprum/cli/dependencies/file_system.rb
107
103
  - lib/cuprum/cli/dependencies/file_system/mock.rb
108
104
  - lib/cuprum/cli/dependencies/standard_io.rb
@@ -111,14 +107,33 @@ files:
111
107
  - lib/cuprum/cli/dependencies/system_command.rb
112
108
  - lib/cuprum/cli/dependencies/system_command/mock.rb
113
109
  - lib/cuprum/cli/errors.rb
114
- - lib/cuprum/cli/errors/files.rb
115
- - lib/cuprum/cli/errors/files/file_not_writeable.rb
116
- - lib/cuprum/cli/errors/files/missing_parameter.rb
117
- - lib/cuprum/cli/errors/files/missing_template.rb
118
- - lib/cuprum/cli/errors/files/template_error.rb
119
- - lib/cuprum/cli/errors/files/template_not_resolved.rb
120
110
  - lib/cuprum/cli/errors/system_command_failure.rb
111
+ - lib/cuprum/cli/files.rb
112
+ - lib/cuprum/cli/files/create_file.rb
113
+ - lib/cuprum/cli/files/engines.rb
114
+ - lib/cuprum/cli/files/engines/render_erb.rb
115
+ - lib/cuprum/cli/files/errors.rb
116
+ - lib/cuprum/cli/files/errors/file_not_writeable.rb
117
+ - lib/cuprum/cli/files/errors/generator_error.rb
118
+ - lib/cuprum/cli/files/errors/missing_parameter.rb
119
+ - lib/cuprum/cli/files/errors/missing_template.rb
120
+ - lib/cuprum/cli/files/errors/template_error.rb
121
+ - lib/cuprum/cli/files/generator.rb
122
+ - lib/cuprum/cli/files/generators.rb
123
+ - lib/cuprum/cli/files/generators/basic_generator.rb
124
+ - lib/cuprum/cli/files/generators/rspec_generator.rb
125
+ - lib/cuprum/cli/files/generators/ruby_generator.rb
126
+ - lib/cuprum/cli/files/template.rb
127
+ - lib/cuprum/cli/files/templates.rb
128
+ - lib/cuprum/cli/files/templates/basic_template.rb
129
+ - lib/cuprum/cli/files/templates/file_template.rb
130
+ - lib/cuprum/cli/files/templates/rspec.rb.erb
131
+ - lib/cuprum/cli/files/templates/ruby.rb.erb
132
+ - lib/cuprum/cli/files/templates/string_template.rb
121
133
  - lib/cuprum/cli/integrations.rb
134
+ - lib/cuprum/cli/integrations/async.rb
135
+ - lib/cuprum/cli/integrations/async/commands.rb
136
+ - lib/cuprum/cli/integrations/async/commands/rspec_each_command.rb
122
137
  - lib/cuprum/cli/integrations/thor.rb
123
138
  - lib/cuprum/cli/integrations/thor/arguments_parser.rb
124
139
  - lib/cuprum/cli/integrations/thor/registry.rb
@@ -137,9 +152,11 @@ files:
137
152
  - lib/cuprum/cli/rspec/deferred/ci/report_examples.rb
138
153
  - lib/cuprum/cli/rspec/deferred/dependencies.rb
139
154
  - lib/cuprum/cli/rspec/deferred/dependencies/file_system_examples.rb
155
+ - lib/cuprum/cli/rspec/deferred/generators_examples.rb
140
156
  - lib/cuprum/cli/rspec/deferred/metadata_examples.rb
141
157
  - lib/cuprum/cli/rspec/deferred/options_examples.rb
142
158
  - lib/cuprum/cli/rspec/deferred/registry_examples.rb
159
+ - lib/cuprum/cli/rspec/deferred/templates_examples.rb
143
160
  - lib/cuprum/cli/version.rb
144
161
  homepage: http://sleepingkingstudios.com
145
162
  licenses:
@@ -167,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
184
  - !ruby/object:Gem::Version
168
185
  version: '0'
169
186
  requirements: []
170
- rubygems_version: 4.0.15
187
+ rubygems_version: 4.0.20
171
188
  specification_version: 4
172
189
  summary: A command-line utility powered by Cuprum.
173
190
  test_files: []
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cuprum/command'
4
-
5
- require 'cuprum/cli/commands/file'
6
- require 'cuprum/cli/errors/files/template_not_resolved'
7
-
8
- module Cuprum::Cli::Commands::File
9
- # Utility command for resolving a template and parameterized values.
10
- class ResolveTemplate < Cuprum::Command
11
- # @param templates [Array<Hash>] the defined templates.
12
- def initialize(templates:)
13
- super()
14
-
15
- @templates = templates
16
- end
17
-
18
- # @return [Array<Hash>] the defined templates.
19
- attr_reader :templates
20
-
21
- private
22
-
23
- def default_params(file_path:, **params) # rubocop:disable Metrics/MethodLength
24
- dir_name = File.dirname(file_path)
25
- ext_name = File.extname(file_path)
26
- base_name = File.basename(file_path)
27
- short_name = base_name.split('.').first
28
-
29
- {
30
- base_name:,
31
- dir_name:,
32
- ext_name:,
33
- file_path:,
34
- short_name:,
35
- **params
36
- }
37
- end
38
-
39
- def filter_templates(except:, file_templates:, only:)
40
- file_templates = [file_templates] unless file_templates.is_a?(Array)
41
- except = Array(except).map(&:to_s)
42
- only = Array(only).map(&:to_s)
43
-
44
- unless except.empty?
45
- file_templates = reject_templates(file_templates, *except)
46
- end
47
-
48
- unless only.empty?
49
- file_templates = select_templates(file_templates, *only)
50
- end
51
-
52
- file_templates
53
- end
54
-
55
- def match_pattern(pattern, file_path)
56
- case pattern
57
- when Proc
58
- pattern.call(file_path)
59
- when Regexp
60
- match_regexp(pattern, file_path)
61
- when String
62
- { file_path: } if file_path.end_with?(pattern)
63
- else
64
- # :nocov:
65
- false
66
- # :nocov:
67
- end
68
- end
69
-
70
- def match_regexp(pattern, file_path)
71
- pattern
72
- .match(file_path)
73
- &.named_captures
74
- &.then { |captures| tools.hash_tools.convert_keys_to_symbols(captures) }
75
- end
76
-
77
- def process(file_path, except: [], only: []) # rubocop:disable Metrics/MethodLength
78
- templates.each do |hsh|
79
- params = match_pattern(hsh.fetch(:pattern), file_path)
80
-
81
- next unless params
82
-
83
- file_templates = hsh.fetch(:templates)
84
- file_templates = step do
85
- filter_templates(file_templates:, except:, only:)
86
- end
87
-
88
- step { require_templates(file_path:, file_templates:, except:, only:) }
89
-
90
- return success([file_templates, default_params(file_path:, **params)])
91
- end
92
-
93
- message = 'no template matching file path'
94
-
95
- failure(template_not_resolved_error(file_path:, message:))
96
- end
97
-
98
- def reject_templates(file_templates, *filters)
99
- file_templates.reject do |template|
100
- types = template.fetch(:types, Array(template[:type])).map(&:to_s)
101
-
102
- types.any? { |type| filters.include?(type) }
103
- end
104
- end
105
-
106
- def require_templates(file_path:, file_templates:, except:, only:)
107
- return unless file_templates.empty?
108
-
109
- options = {}
110
- options[:except] = except unless except.empty?
111
- options[:only] = only unless only.empty?
112
-
113
- error = template_not_resolved_error(
114
- file_path:,
115
- message: 'all templates filtered out',
116
- options:
117
- )
118
-
119
- failure(error)
120
- end
121
-
122
- def select_templates(file_templates, *filters)
123
- file_templates.select do |template|
124
- types = template.fetch(:types, Array(template[:type])).map(&:to_s)
125
-
126
- types.any? { |type| filters.include?(type) }
127
- end
128
- end
129
-
130
- def template_not_resolved_error(**)
131
- Cuprum::Cli::Errors::Files::TemplateNotResolved.new(**)
132
- end
133
-
134
- def tools = @tools ||= SleepingKingStudios::Tools::Toolbelt.instance
135
- end
136
- end
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cuprum/cli/commands/file'
4
-
5
- module Cuprum::Cli::Commands::File
6
- # Namespace for defining templates for generated files.
7
- module Templates
8
- RSPEC_PATTERN = <<~PATTERN.strip.then { |pattern| /#{pattern}/xo }
9
- \\A
10
- (?<root_path>\\w+#{File::SEPARATOR})?
11
- (?<relative_path>(\\w+#{File::SEPARATOR})*)
12
- (?<base_name>\\w+)_spec\\.rb
13
- \\z
14
- PATTERN
15
- private_constant :RSPEC_PATTERN
16
-
17
- RUBY_PATTERN = <<~PATTERN.strip.then { |pattern| /#{pattern}/xo }
18
- \\A
19
- (?<root_path>\\w+#{File::SEPARATOR})?
20
- (?<relative_path>(\\w+#{File::SEPARATOR})*)
21
- (?<base_name>\\w+)\\.rb
22
- \\z
23
- PATTERN
24
- private_constant :RUBY_PATTERN
25
-
26
- TEMPLATES_PATH =
27
- File
28
- .join(
29
- Cuprum::Cli.gem_path,
30
- 'lib',
31
- 'cuprum',
32
- 'cli',
33
- 'commands',
34
- 'file',
35
- 'templates'
36
- )
37
- .freeze
38
- private_constant :TEMPLATES_PATH
39
-
40
- # Default templates used to generate Ruby and RSpec files.
41
- DEFAULT_TEMPLATES = [
42
- {
43
- name: 'RSpec File',
44
- pattern: RSPEC_PATTERN,
45
- templates: {
46
- file_path: '%<root_path>s%<relative_path>s%<base_name>s_spec.rb',
47
- template: File.join(TEMPLATES_PATH, 'rspec.rb.erb'),
48
- types: %i[ruby rspec spec test]
49
- }
50
- },
51
- {
52
- name: 'Ruby File (With Spec)',
53
- pattern: RUBY_PATTERN,
54
- templates: [
55
- {
56
- file_path: '%<root_path>s%<relative_path>s%<base_name>s.rb',
57
- template: File.join(TEMPLATES_PATH, 'ruby.rb.erb'),
58
- type: :ruby
59
- },
60
- {
61
- file_path: 'spec/%<relative_path>s%<base_name>s_spec.rb',
62
- template: File.join(TEMPLATES_PATH, 'rspec.rb.erb'),
63
- types: %i[ruby rspec spec test]
64
- }
65
- ]
66
- }
67
- ].then do |ary|
68
- SleepingKingStudios::Tools::Toolbelt.instance.array_tools.deep_freeze(ary)
69
- end
70
- end
71
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cuprum/cli/errors/files'
4
- require 'cuprum/cli/errors/files/template_error'
5
-
6
- module Cuprum::Cli::Errors::Files
7
- # Error returned when unable to resolve a template for a templated file.
8
- class TemplateNotResolved < Cuprum::Cli::Errors::Files::TemplateError
9
- # Short string used to identify the type of error.
10
- TYPE = 'cuprum.cli.errors.files.template_not_resolved'
11
-
12
- # @param file_path [String] the file path for the templated file.
13
- # @param details [String] additional information about the error.
14
- # @param message [String] an optional message to display.
15
- # @param options [Hash] options used when attempting to resolve the
16
- # template.
17
- def initialize(file_path:, details: nil, message: nil, options: {})
18
- @file_path = file_path
19
- @options = options
20
-
21
- super(details:, file_path:, message: default_message(message), options:)
22
- end
23
-
24
- # @return [String] the file path for the templated file.
25
- attr_reader :file_path
26
-
27
- # @return [Hash] options used when attempting to resolve the template.
28
- attr_reader :options
29
-
30
- private
31
-
32
- def as_json_data
33
- hsh = super
34
-
35
- hsh['file_path'] = file_path
36
- hsh['options'] = options.transform_keys(&:to_s) unless options.empty?
37
-
38
- hsh
39
- end
40
-
41
- def default_message(message)
42
- str = "unable to resolve template for file #{file_path}"
43
- str = "#{str} with options" unless options.empty?
44
-
45
- options.each.with_index do |(key, value), index|
46
- str += "#{',' unless index.zero?} #{key}: #{value.inspect}"
47
- end
48
-
49
- return str unless message && !message.empty?
50
-
51
- "#{str} - #{message}"
52
- end
53
- end
54
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cuprum/cli/errors'
4
-
5
- module Cuprum::Cli::Errors
6
- # Namespace for errors returned when creating or managing files.
7
- module Files
8
- autoload :FileNotWriteable,
9
- 'cuprum/cli/errors/files/file_not_writeable'
10
- autoload :MissingParameter,
11
- 'cuprum/cli/errors/files/missing_parameter'
12
- autoload :MissingTemplate,
13
- 'cuprum/cli/errors/files/missing_template'
14
- autoload :TemplateError,
15
- 'cuprum/cli/errors/files/template_error'
16
- autoload :TemplateNotResolved,
17
- 'cuprum/cli/errors/files/template_not_resolved'
18
- end
19
- end