Class: CfnDsl::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- CfnDsl::RakeTask
- Defined in:
- lib/cfndsl/rake_task.rb
Overview
Rake TaskLib rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#cfndsl_opts ⇒ Object
deprecated
Deprecated.
pre 1.x rake task generator
Instance Method Summary collapse
-
#initialize(name = nil) {|_self| ... } ⇒ RakeTask
constructor
Creates Cloudformation generation tasks.
-
#json(name:, files:, pathmap:, pretty: false, extras: [], **json_opts) ⇒ Object
Convert DSL sources to json.
-
#specification(file:, name: nil, version: nil) ⇒ Object
Use a custom specification file.
-
#yaml(name:, files:, pathmap:, extras: [], **yaml_opts) ⇒ Object
Convert DSL sources to yaml.
Constructor Details
#initialize(name = nil) {|_self| ... } ⇒ RakeTask
Creates Cloudformation generation tasks
directory ‘tmp’
namespace :samples do
CfnDsl::RakeTask.new do |t|
t.specification(file: 'tmp/cloudformation_resources.json')
desc 'Generate CloudFormation Json'
t.json(name: :json, files: ["sample/*.rb"], pathmap: 'tmp/%f.json', pretty: true, extras: FileList.new('sample/*.yaml') )
t.yaml(name: :yaml, files: 'sample/t1.rb', pathmap: 'tmp/%f.yaml', extras: '%X.yaml')
end
end
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cfndsl/rake_task.rb', line 38 def initialize(name = nil) @tasks = [] @spec_task = nil last_desc = ::Rake.application.last_description desc nil yield self if block_given? if cfndsl_opts desc last_desc if last_desc task(name || :generate) { |_t, _args| cfndsl_opts[:files].each { |opts| generate(opts) } } else define_base_tasks(name || :generate, last_desc) end end |
Instance Attribute Details
#cfndsl_opts ⇒ Object
pre 1.x rake task generator
20 21 22 |
# File 'lib/cfndsl/rake_task.rb', line 20 def cfndsl_opts @cfndsl_opts end |
Instance Method Details
#json(name:, files:, pathmap:, pretty: false, extras: [], **json_opts) ⇒ Object
Convert DSL sources to json
Generates file tasks for each of the matching file in the files FileList. Each task is dependant on the source,
the specification file, and the required extras files such that if the timestamp of any of these is earlier
the target file will be regenerated.
Finally task <name> is generated that depends on all the generated targets.
rubocop:disable Metrics/ParameterLists
113 114 115 116 117 118 119 |
# File 'lib/cfndsl/rake_task.rb', line 113 def json(name:, files:, pathmap:, pretty: false, extras: [], **json_opts) json_method = pretty ? :pretty_generate : :generate generate_model_tasks(name: name, files: files, pathmap: pathmap, extras: extras) do |model, f| f.write(JSON.send(json_method, model, **json_opts)) end self end |
#specification(file:, name: nil, version: nil) ⇒ Object
Add capability to provide a user spec/patches dir
Use a custom specification file
This specification file will be used for any generation tasks
Creates a file task to download from upstream source, with an optional additional named task that depends on it.
The minimum required version can be specified with the version parameter, which can be overriden by invoking rake with the ‘cfn_spec_task’ argument
CfnDsl::RakeTask.new() do |t|
t.specification(name: :update_spec, file: 'tmp/cloudformation_resources.json', version: '6.3'0)
end
# rake update_spec # >> Will ensure ‘tmp/cloudformation_resources.json’ exists and is at least 6.3.0 # rake update_spec # >> Will always try to download the latest available spec
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cfndsl/rake_task.rb', line 82 def specification(file:, name: nil, version: nil) if name desc 'Update Resource Specification' unless ::Rake.application.last_description task name, [:cfn_spec_version] => file end @spec_task = file(file, :cfn_spec_version) do |t, args| update_specification(t.name, args.with_defaults(cfn_spec_version: version)[:cfn_spec_version]) end @spec_task.define_singleton_method(:needed?) { true } # We always need to check self end |
#yaml(name:, files:, pathmap:, extras: [], **yaml_opts) ⇒ Object
Convert DSL sources to yaml
Generates file tasks for each of the matching file in the files FileList. Each task is dependant on the source,
the specification file, and the required extras files such that if the timestamp of any of these is earlier
the target file will be regenerated.
Finally task <name> is generated that depends on all the generated targets.
136 137 138 139 140 141 142 |
# File 'lib/cfndsl/rake_task.rb', line 136 def yaml(name:, files:, pathmap:, extras: [], **yaml_opts) generate_model_tasks(name: name, files: files, pathmap: pathmap, extras: extras) do |model, f| simple_model = JSON.parse(model.to_json) # convert model to a simple ruby object to avoid yaml tags YAML.dump(simple_model, f, **yaml_opts) end self end |