Class: Limer::Gitpt
- Inherits:
-
Object
- Object
- Limer::Gitpt
- Defined in:
- lib/limer/gitpt.rb
Instance Attribute Summary collapse
-
#applicable_stories ⇒ Object
readonly
Returns the value of attribute applicable_stories.
-
#highline ⇒ Object
readonly
Returns the value of attribute highline.
-
#memberships ⇒ Object
readonly
Returns the value of attribute memberships.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#setting_file ⇒ Object
readonly
Returns the value of attribute setting_file.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #bold(string) ⇒ Object
- #choose_story ⇒ Object
- #hello ⇒ Object
- #highlight(string) ⇒ Object
-
#initialize ⇒ Gitpt
constructor
A new instance of Gitpt.
- #load_project ⇒ Object
- #load_setting ⇒ Object
- #loading(message, &block) ⇒ Object
- #missing(string) ⇒ Object
- #request_settings ⇒ Object
- #run ⇒ Object
- #settings_valid? ⇒ Boolean
- #stored ⇒ Object
Constructor Details
#initialize ⇒ Gitpt
Returns a new instance of Gitpt.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/limer/gitpt.rb', line 11 def initialize @highline = HighLine.new @setting_file = File.join(ENV['HOME'], '.gitpt') load_setting hello unless settings_valid? request_settings while not settings_valid? stored if not settings_valid? PivotalTracker::Client.use_ssl = true PivotalTracker::Client.token = token end |
Instance Attribute Details
#applicable_stories ⇒ Object (readonly)
Returns the value of attribute applicable_stories.
9 10 11 |
# File 'lib/limer/gitpt.rb', line 9 def applicable_stories @applicable_stories end |
#highline ⇒ Object (readonly)
Returns the value of attribute highline.
9 10 11 |
# File 'lib/limer/gitpt.rb', line 9 def highline @highline end |
#memberships ⇒ Object (readonly)
Returns the value of attribute memberships.
9 10 11 |
# File 'lib/limer/gitpt.rb', line 9 def memberships @memberships end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/limer/gitpt.rb', line 9 def name @name end |
#setting_file ⇒ Object (readonly)
Returns the value of attribute setting_file.
9 10 11 |
# File 'lib/limer/gitpt.rb', line 9 def setting_file @setting_file end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/limer/gitpt.rb', line 9 def token @token end |
Instance Method Details
#bold(string) ⇒ Object
31 32 33 |
# File 'lib/limer/gitpt.rb', line 31 def bold string HighLine::BOLD + string + HighLine::RESET end |
#choose_story ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/limer/gitpt.rb', line 107 def choose_story selected_story = nil @highline.choose do || .header = HighLine::BLUE + "Story сонгоно уу" + HighLine::RESET @applicable_stories.each do |story| owner_name = story.owned_by owner = if owner_name owners = memberships.select{|member| member.name == owner_name} owners.first ? owners.first.name: '?' else '?' end state = story.current_state if state == 'started' state = HighLine::GREEN + state + HighLine::RESET elsif state != 'finished' state = HighLine::RED + state + HighLine::RESET end state += HighLine::BOLD if owner == @name label = "(" + HighLine::YELLOW + "#{owner}"+ HighLine::RESET + ", #{state}) #{story.name} - " + HighLine::BLUE + story.story_type.capitalize + HighLine::RESET label = bold(label) if owner == @name .choice(label) { selected_story = story } end .choice 'Гарах' do |chosen| exit 1 end .hidden '' end if selected_story = nil @highline.choose do || .header = "Төрлөө сонгоно уу" .choices "fixed","delivers","Гарах" do |chosen| if chosen == "Гарах" exit 1 end = chosen end .hidden '' end = "[#{} ##{selected_story.id}] #{selected_story.name}" # puts commit_message exec('git', 'commit', '-m', ) end end |
#hello ⇒ Object
35 36 37 38 |
# File 'lib/limer/gitpt.rb', line 35 def hello @highline.say HighLine::RESET @highline.say "Welcome to #{bold 'Limer'}.\n\n" end |
#highlight(string) ⇒ Object
23 24 25 |
# File 'lib/limer/gitpt.rb', line 23 def highlight string bold HighLine::BLUE + string end |
#load_project ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/limer/gitpt.rb', line 61 def load_project project_id_file = '.pt_project_id' if File.exists? project_id_file project_ids = File.read(project_id_file).split(/[\s]+/).map(&:to_i) end unless project_ids and project_ids.size > 0 @highline.say "Project id олдсонгүй." + bold(".pt_project_id") + " файлд хадгалана уу" exit 1 end loading 'Pivotal Tracker холболт хийгдэж байна: ... ' do projects = project_ids.collect do |project_id| PivotalTracker::Project.find(project_id) end @memberships = projects.collect(&:memberships).map(&:all).flatten @applicable_stories = projects.collect do |project| project.stories.all(:state => 'started,finished,rejected') end.flatten end end |
#load_setting ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/limer/gitpt.rb', line 52 def load_setting if File.exists? setting_file settings = YAML.load(File.read setting_file) @name= settings[:name] @token = settings[:token] else end end |
#loading(message, &block) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/limer/gitpt.rb', line 83 def loading(, &block) print STDOUT.flush yield print "\r" + ' ' * .size + "\r" # Remove loading message STDOUT.flush end |
#missing(string) ⇒ Object
27 28 29 |
# File 'lib/limer/gitpt.rb', line 27 def missing string bold HighLine::RED + string end |
#request_settings ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/limer/gitpt.rb', line 91 def request_settings @highline.say missing('Тохиргооны файл байхгүй байна.') @highline.say "Pivotal Tracker холбогдох тохиргоог хийнэ үү.\n\n" @token = @highline.ask bold("API key: ") @name= @highline.ask bold("Pivotal Tracker дээрх нэр: ") @highline.say "\n" settings = { :token => @token, :name=> @name} File.open setting_file, 'w' do |file| file.write settings.to_yaml end load_setting end |
#run ⇒ Object
158 159 160 161 |
# File 'lib/limer/gitpt.rb', line 158 def run load_project choose_story end |
#settings_valid? ⇒ Boolean
40 41 42 |
# File 'lib/limer/gitpt.rb', line 40 def settings_valid? token and token.size > 0 end |
#stored ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/limer/gitpt.rb', line 44 def stored @highline.say " Thank you. Your settings have been stored at #{highlight @settings_file} You may remove that file for the wizard to reappear. ----------------------------------------------------" end |