Class: Forger::Base
- Inherits:
-
Object
- Object
- Forger::Base
- Defined in:
- lib/forger/base.rb
Direct Known Subclasses
Ami, Cleaner::Ami, Create, Create::Params, Create::Waiter, Destroy, Profile, Script::Compile, Script::Compress, Script::Upload, Waiter::Ami
Constant Summary collapse
- BUILD_ROOT =
constants really only used by script classes
"/tmp/forger/#{File.basename(Dir.pwd)}"
- SCRIPTS_INFO_PATH =
"#{BUILD_ROOT}/data/scripts_info.txt"
Instance Method Summary collapse
-
#derandomize(name) ⇒ Object
Strip the random string at end of the ec2 instance name.
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#randomize(name) ⇒ Object
Appends a short random string at the end of the ec2 instance name.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 |
# File 'lib/forger/base.rb', line 7 def initialize(={}) @options = .clone @name = randomize(@options[:name]) Forger.validate_in_project! end |
Instance Method Details
#derandomize(name) ⇒ Object
Strip the random string at end of the ec2 instance name
33 34 35 36 37 38 39 |
# File 'lib/forger/base.rb', line 33 def derandomize(name) if @options[:randomize] name.sub(/-(\w{3})$/,'') # strip the random part at the end else name end end |
#randomize(name) ⇒ Object
Appends a short random string at the end of the ec2 instance name. Later we will strip this same random string from the name. Very makes it convenient. We can just type:
forger create server --randomize
instead of:
forger create server-123 --profile server
23 24 25 26 27 28 29 30 |
# File 'lib/forger/base.rb', line 23 def randomize(name) if @options[:randomize] random = (0...3).map { (65 + rand(26)).chr }.join.downcase # Ex: jhx [name, random].join('-') else name end end |