Module: TerraspaceBundler::Mod::Concerns::StackConcern
- Included in:
- TerraspaceBundler::Mod
- Defined in:
- lib/terraspace_bundler/mod/concerns/stack_concern.rb
Instance Method Summary collapse
- #all_stacks ⇒ Object
- #all_stacks?(*stacks) ⇒ Boolean
- #array_stacks(stacks) ⇒ Object
-
#normalize_stacks(option) ⇒ Object
Normalizes stack options to an Array of Hashes or just a single Hash.
- #stacks ⇒ Object (also: #stack)
Instance Method Details
#all_stacks ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/terraspace_bundler/mod/concerns/stack_concern.rb', line 19 def all_stacks stack = TerraspaceBundler::Exporter::Stacks::Stack.new(self) # to get the mod src path expr = "#{stack.examples_folder}/*" dirs = Dir.glob(expr).select { |path| File.directory?(path) } dirs.map do |dir| example = File.basename(dir) # Set name so multiple app/stacks are created instead of just one app/stack/MOD { name: example, src: example, } end end |
#all_stacks?(*stacks) ⇒ Boolean
15 16 17 |
# File 'lib/terraspace_bundler/mod/concerns/stack_concern.rb', line 15 def all_stacks?(*stacks) stacks.flatten == [:all] end |
#array_stacks(stacks) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/terraspace_bundler/mod/concerns/stack_concern.rb', line 33 def array_stacks(stacks) stacks.map do |example| if example.is_a?(Hash) example else { name: example, src: example, } end end end |
#normalize_stacks(option) ⇒ Object
Normalizes stack options to an Array of Hashes or just a single Hash
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/terraspace_bundler/mod/concerns/stack_concern.rb', line 47 def normalize_stacks(option) defaults = TB.config..dup result = case option when String [defaults.merge(src: option)] when Array option.map! {|s| normalize_stacks(s) } else # Hash [defaults.merge!(option)] end result.flatten end |
#stacks ⇒ Object Also known as: stack
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/terraspace_bundler/mod/concerns/stack_concern.rb', line 3 def stacks stacks = @props[:stacks] || @props[:stack] return unless stacks if all_stacks?(stacks) stacks = all_stacks elsif stacks.is_a?(Array) stacks = array_stacks(stacks) end normalize_stacks(stacks) end |