Class: GitCommitStory
- Inherits:
-
Object
- Object
- GitCommitStory
- Defined in:
- lib/git-commit-story.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #commit ⇒ Object
- #final_commit_message ⇒ Object
- #get_message_from_prompt ⇒ Object
-
#initialize(options) ⇒ GitCommitStory
constructor
A new instance of GitCommitStory.
- #options_from_config_file ⇒ Object
- #save_config_file ⇒ Object
- #story_id ⇒ Object
- #strip_leading_pound(string) ⇒ Object
Constructor Details
#initialize(options) ⇒ GitCommitStory
Returns a new instance of GitCommitStory.
7 8 9 10 11 12 |
# File 'lib/git-commit-story.rb', line 7 def initialize() @config_file_name = ".git-commit-story.yml" = .merge!() = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/git-commit-story.rb', line 5 def end |
Instance Method Details
#commit ⇒ Object
78 79 80 81 82 83 |
# File 'lib/git-commit-story.rb', line 78 def commit = %Q(git commit -m "#{final_commit_message}") result = system() [:previous_story_id] = story_id save_config_file end |
#final_commit_message ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/git-commit-story.rb', line 58 def = "" if [:commit_message] = [:commit_message] else = end "#{message}\n\nStory: #{story_id}" end |
#get_message_from_prompt ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/git-commit-story.rb', line 68 def $stdout.print "Enter a commit message: " = $stdin.gets if .length == 0 puts "No message supplied" abort end .strip end |
#options_from_config_file ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/git-commit-story.rb', line 14 def if File.exist?(@config_file_name) = YAML.load_file(@config_file_name) else {} end end |
#save_config_file ⇒ Object
22 23 24 |
# File 'lib/git-commit-story.rb', line 22 def save_config_file File.open(@config_file_name, "w") { |f| f.puts .to_yaml } end |
#story_id ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/git-commit-story.rb', line 26 def story_id if [:story_id] strip_leading_pound [:story_id] else prompt = if [:previous_story_id] "Enter a story [#{@options[:previous_story_id]}]: " else "Enter a story: " end $stdout.print prompt response = $stdin.gets.strip if response == "" if [:previous_story_id] [:story_id] = [:previous_story_id] else puts "No story id was supplied" abort end else [:story_id] = strip_leading_pound response end end end |
#strip_leading_pound(string) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/git-commit-story.rb', line 50 def strip_leading_pound(string) if string[0] == "#" string[1..-1] else string end end |