Class: Sfn::Utils::StackExporter
- Inherits:
-
Object
- Object
- Sfn::Utils::StackExporter
- Includes:
- Bogo::AnimalStrings, JSON
- Defined in:
- lib/sfn/utils/stack_exporter.rb
Overview
Stack serialization helper
Constant Summary collapse
- DEFAULT_CHEF_ENVIRONMENT =
default chef environment name
"_default"
- DEFAULT_OPTIONS =
default instance options
Mash.new( :chef_popsicle => true, :ignored_parameters => ["Environment", "StackCreator", "Creator"], :chef_environment_parameter => "Environment", )
- DEFAULT_EXPORT_STRUCTURE =
default structure of export payload
{ :stack => Mash.new( :template => nil, :options => { :parameters => Mash.new, :capabilities => [], :notification_topics => [], }, ), :generator => { :timestamp => Time.now.to_i, :name => "SparkleFormation", :version => Sfn::VERSION.version, :provider => nil, }, }
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
- #stack ⇒ Miasma::Models::Orchestration::Stack readonly
- #stack_export ⇒ Hash readonly
Instance Method Summary collapse
-
#export ⇒ Hash
Export stack.
-
#initialize(stack, options = {}) ⇒ StackExporter
constructor
Create new instance.
-
#method_missing(*args) ⇒ Object
Provide query methods on options hash.
Methods included from JSON
#_format_json, #_from_json, #_to_json
Constructor Details
#initialize(stack, options = {}) ⇒ StackExporter
Create new instance
57 58 59 60 61 |
# File 'lib/sfn/utils/stack_exporter.rb', line 57 def initialize(stack, = {}) @stack = stack @options = DEFAULT_OPTIONS.merge() @stack_export = Smash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
Provide query methods on options hash
90 91 92 93 94 95 96 97 |
# File 'lib/sfn/utils/stack_exporter.rb', line 90 def method_missing(*args) m = args.first.to_s if m.end_with?("?") && .has_key?(k = m.sub("?", "").to_sym) !![k] else super end end |
Instance Attribute Details
#options ⇒ Hash (readonly)
45 46 47 |
# File 'lib/sfn/utils/stack_exporter.rb', line 45 def @options end |
#stack ⇒ Miasma::Models::Orchestration::Stack (readonly)
43 44 45 |
# File 'lib/sfn/utils/stack_exporter.rb', line 43 def stack @stack end |
#stack_export ⇒ Hash (readonly)
47 48 49 |
# File 'lib/sfn/utils/stack_exporter.rb', line 47 def stack_export @stack_export end |
Instance Method Details
#export ⇒ Hash
Export stack
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sfn/utils/stack_exporter.rb', line 66 def export @stack_export = Smash.new(DEFAULT_EXPORT_STRUCTURE).tap do |stack_export| [:parameters, :capabilities, :notification_topics].each do |key| if val = stack.send(key) stack_export[:stack][key] = val end end stack_export[:stack][:template] = stack.template stack_export[:generator][:timestamp] = Time.now.to_i stack_export[:generator][:provider] = stack.provider.connection.provider if chef_popsicle? && defined?(Chef) freeze_runlists(stack_export) end remove_ignored_parameters(stack_export) stack_export[:stack][:template] = _to_json( stack_export[:stack][:template] ) end end |