Class: Commander::Setup
- Inherits:
-
Object
- Object
- Commander::Setup
- Defined in:
- lib/commander/setup.rb
Instance Attribute Summary collapse
-
#conf ⇒ Object
Returns the value of attribute conf.
Class Method Summary collapse
- .choose(choice) ⇒ Object
- .concat_cron_syntax ⇒ Object
- .configure ⇒ Object
- .get_user_input ⇒ Object
- .pick_cron_day ⇒ Object
- .pick_cron_time ⇒ Object
- .write_to_file(filename, content) ⇒ Object
Instance Attribute Details
#conf ⇒ Object
Returns the value of attribute conf.
9 10 11 |
# File 'lib/commander/setup.rb', line 9 def conf @conf end |
Class Method Details
.choose(choice) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/commander/setup.rb', line 74 def self.choose(choice) case choice.to_i when 1 puts 'Chose written language:' puts 'Day' puts 'e.g. Monday, Tuesday, ...' printf '>>' pick_cron_day puts 'Time..' puts 'e.g. 11, 21, 24, 8, 3' printf '>>' @hour = pick_cron_time puts 'Put this in your cron' puts 'Edit it with crontab -e' puts ("#{concat_cron_syntax} " + " /bin/bash -l -c " + "'"+"#{%x[which commander].chomp || %x[which commander2.0].chomp} -a"+"'").green when 2 puts 'Chose raw cron syntax' puts 'e.g. 0 0 27-31 * *' printf '>>' raw_syn = get_user_input puts 'Put this in your cron' puts 'Edit it with crontab -e' puts ("#{raw_syn} " + " /bin/bash -l -c " + "'"+"#{%x[which commander].chomp || %x[which commander2.0].chomp} -a"+"'").green when 3 write_to_file('.trello', @conf.to_yaml) exit('Success') else puts 'Nothing happend.' end end |
.concat_cron_syntax ⇒ Object
107 108 109 |
# File 'lib/commander/setup.rb', line 107 def self.concat_cron_syntax "0 #{@hour} 0 0 #{@cron_day}" end |
.configure ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/commander/setup.rb', line 17 def self.configure system('clear') puts 'Provide your Trello Board ID'.green puts 'If you don\'t know where to find it visit your board.' puts "https://trello.com/b/" + "YOURBOARDID".green+"/boardname etc.." printf '>>' @conf['board_id'] = get_user_input system('clear') puts 'Provide your Trello consumer key.'.green puts 'You can generate this key on.' puts 'Https://trello.com/1/appKey/generate' printf '>>' @conf['consumerkey'] = get_user_input system('clear') puts 'Provide your Trello consumer secret.'.green puts 'You can generate this key on.' puts 'Https://trello.com/1/appKey/generate' printf '>>' @conf['consumersecret'] = get_user_input system('clear') puts 'Finally provide the generated token.'.green puts 'Which you can get here.' puts "https://trello.com/1/authorize?key=#{@conf['consumerkey']}&name=happy-commander&expiration=never&response_type=token&scope=read,write" printf '>>' @conf['oauthtoken'] = get_user_input system('clear') puts 'Specify the card id (comments and assignments on this card).'.green puts 'See in card description.' puts 'Or in browser url.' puts "e.g https://trello.com/c/somecard/"+"2075".green+"-commanding-officer-of-the-week" printf '>>' @conf['card_id'] = get_user_input system('clear') puts 'Set the interval.'.green puts 'E.g. for every tuesday' puts 'Write: tuesday, or weekdays' puts 'At what time?' puts 'Write: 1pm, 10pm, 2pm, 1am and so on..' puts 'Or: raw cron syntax' puts 'Like: 0 0 27-31 * *' puts '' puts 'What syntax will you provide?' puts '1. Written language'.green puts '2. Raw cron syntax'.green puts '3. None' printf '>>' choose(get_user_input) system('clear') write_to_file('.trello', @conf.to_yaml) end |
.get_user_input ⇒ Object
13 14 15 |
# File 'lib/commander/setup.rb', line 13 def self.get_user_input $stdin.gets.chomp end |
.pick_cron_day ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/commander/setup.rb', line 124 def self.pick_cron_day day = get_user_input weekdays = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday) unless weekdays.include?(day) raise InvalidInputException, "Not a valid weekday: '#{day}'" end puts "selected: #{day}" @cron_day = weekdays.index(day) rescue InvalidInputException => e puts e. puts "Valid options are: #{weekdays}" retry end |
.pick_cron_time ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/commander/setup.rb', line 111 def self.pick_cron_time time = get_user_input.to_i unless (1..24).cover?(time) raise InvalidInputException, "Not a valid timeframe: #{time}" end puts "selected: #{time}" @hour = time rescue InvalidInputException => e puts e. puts "Valid values are: [1, 2, 3...22, 23, 24]" retry end |
.write_to_file(filename, content) ⇒ Object
138 139 140 141 142 |
# File 'lib/commander/setup.rb', line 138 def self.write_to_file(filename, content) File.open("#{File.join(Dir.home)}/.config/happy-commander/#{filename}.yml", 'w') do |f| f.write(content) end end |