Class: Dckerize::Runner
- Inherits:
-
Object
- Object
- Dckerize::Runner
- Defined in:
- lib/dckerize/runner.rb
Constant Summary collapse
- VALID_DBS =
['mysql', 'postgres', 'mongo']
- VALID_EXTRAS =
['elasticsearch', 'redis', 'memcached']
- ERROR_MESSAGE =
'USAGE: dckerize up APP_NAME --database=<mysql|postgres|mongo> [--extras=elasticsearch,redis,memcached]'- VAGRANT_FOLDER_EXISTS =
'ERROR: vagrant folder already exists.'- CONF_FOLDER_EXISTS =
'ERROR: conf folder already exists.'- DOCKERFILE_EXISTS =
'ERROR: Dockerfile already exists.'- DOCKERCOMPOSE_EXISTS =
'ERROR: docker-compose already exists.'
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
11 12 13 |
# File 'lib/dckerize/runner.rb', line 11 def initialize() = end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dckerize/runner.rb', line 15 def execute extras = [] db = '' raise ERROR_MESSAGE unless valid? [2..-1].each do |option| splitted_option = option.split('=') if splitted_option[0] == '--database' db = splitted_option[1] elsif splitted_option[0] == '--extras' extras << splitted_option[1].split(',') else raise_error ERROR_MESSAGE end end Dckerize::Generator.new([1], db, extras.flatten).up end |
#valid? ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dckerize/runner.rb', line 32 def valid? # first option should always be up return false if [0] != 'up' # db is mandatory return false unless .grep(/--database=/).any? # only valid options allowed # for dbs and extras [2..-1].each do |option| if option.split('=')[0] == '--database' return false unless VALID_DBS.include?(option.split('=')[1]) elsif option.split('=')[0] == '--extras' (option.split('=')[1]).split(',').each do |extra| return false unless VALID_EXTRAS.include?(extra) end else return false end end true end |