class Shaman::Init
Attributes
options[R]
Public Class Methods
check()
click to toggle source
# File lib/shaman/init.rb, line 6 def self.check return unless ENV['SHAMAN_TOKEN'].nil? error! "SHAMAN_TOKEN not defined. Please find it at #{LABS_URL}/users/me" end
init(options)
click to toggle source
# File lib/shaman/init.rb, line 11 def self.init(options) new(options).call end
new(options)
click to toggle source
# File lib/shaman/init.rb, line 15 def initialize(options) @options = options end
Public Instance Methods
call()
click to toggle source
# File lib/shaman/init.rb, line 19 def call @platform = choose_platform if options.platform.nil? @project_id = choose_project_id if options.project_id.nil? write_config prompt.ok '.shaman.yml created' prompt.say(File.read(PROJECT_CONFIG_PATH), color: :cyan) end
Private Instance Methods
choose_platform()
click to toggle source
# File lib/shaman/init.rb, line 31 def choose_platform prompt.select('Choose platform:', [:android, :ios, :zip, :air, :web]) end
choose_project_id()
click to toggle source
# File lib/shaman/init.rb, line 35 def choose_project_id prompt.enum_select('Choose project:') do |menu| menu.enum '.' projects.each do |project| menu.choice "#{project['name']} (#{project['id']})", project['id'] end end end
favorites()
click to toggle source
# File lib/shaman/init.rb, line 70 def favorites options.favorites end
platform()
click to toggle source
# File lib/shaman/init.rb, line 82 def platform @platform || options.platform end
project_id()
click to toggle source
# File lib/shaman/init.rb, line 78 def project_id @project_id || options.project_id.to_i end
projects()
click to toggle source
# File lib/shaman/init.rb, line 59 def projects return @projects if @projects response = HTTP.get( "#{LABS_URL}/api/v1/projects", params: { token: ENV['SHAMAN_TOKEN'], favorites: favorites, search: search, platform: platform } ) @projects = JSON.parse(response.body) end
search()
click to toggle source
# File lib/shaman/init.rb, line 74 def search options.search end
write_config()
click to toggle source
# File lib/shaman/init.rb, line 44 def write_config project = projects.detect { |p| p['id'] == project_id } error!('wrong project id') if project.nil? config = {} project['environments'].each do |environment| next unless environment['platform'] == platform.to_s release_path = prompt.ask("Release path for #{environment['name']}", default: 'path/to/release') config[environment['name']] = { release_path: release_path, token: environment['token'] } end File.open(PROJECT_CONFIG_PATH, 'w') { |f| f.write(YAML.dump(config)) } end