Class: Appium::Thor::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/appium_thor/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionsObject

Returns all options as symbols. Required for defining delegators in init.rb



30
31
32
# File 'lib/appium_thor/config.rb', line 30

def self.options
  string_options + [:docs_block]
end

.set(&block) ⇒ Object

Enables setting config in the Thorfile

Appium::Thor::Config.set do

gem_name     'appium_thor'
github_owner 'appium'
github_name  'appium_thor'
version_file 'path/to/version.rb'

end



56
57
58
59
60
61
# File 'lib/appium_thor/config.rb', line 56

def self.set(&block)
  config = self.instance
  config.instance_eval &block
  config.init_and_validate
  config
end

.string_optionsObject

the subset of options that operate on strings



35
36
37
# File 'lib/appium_thor/config.rb', line 35

def self.string_options
  %w[gem_name github_name github_owner version_file].map(&:to_sym)
end

Instance Method Details

#docs_block(&block) ⇒ Object

block of code to execute that contains documentation generation logic



24
25
26
27
# File 'lib/appium_thor/config.rb', line 24

def docs_block(&block)
  return @docs_block if @docs_block
  @docs_block = block
end

#init_and_validateObject

Returns true if all options are truthy



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/appium_thor/config.rb', line 7

def init_and_validate
  # set default values
  if @gem_name
    @github_name  ||= @gem_name
    @version_file ||= "lib/#{@gem_name}/version.rb"
  end

  @github_owner ||= 'appium'

  # ensure all options are set
  all_set = @gem_name && @github_name && @github_owner && @version_file
  raise 'Must set gem_name, github_name, github_owner, version_file' unless all_set
  raise "version file doesn't exist #{@version_file}" unless File.exist?(@version_file)
end