Class: GitCommands::Branch
- Inherits:
-
Object
- Object
- GitCommands::Branch
- Defined in:
- lib/git_commands/branch.rb
Constant Summary collapse
- MASTER =
"master"- ORIGIN =
"origin/"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .by_file(names_file) ⇒ Object
- .by_names(names_list) ⇒ Object
- .by_pattern(pattern) ⇒ Object
- .factory(src) ⇒ Object
- .strip_origin(name) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name) ⇒ Branch
constructor
A new instance of Branch.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Branch
Returns a new instance of Branch.
40 41 42 |
# File 'lib/git_commands/branch.rb', line 40 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/git_commands/branch.rb', line 38 def name @name end |
Class Method Details
.by_file(names_file) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/git_commands/branch.rb', line 16 def self.by_file(names_file) return [] unless File.file?(names_file) File.foreach(names_file).map do |name| new(name.strip) end.select(&:valid?) end |
.by_names(names_list) ⇒ Object
10 11 12 13 14 |
# File 'lib/git_commands/branch.rb', line 10 def self.by_names(names_list) String(names_list).split(",").map do |name| new(name.strip) end.select(&:valid?) end |
.by_pattern(pattern) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/git_commands/branch.rb', line 23 def self.by_pattern(pattern) return [] unless pattern.index("*") `git branch -r --list #{ORIGIN}#{pattern}`.split("\n").map do |name| new(strip_origin(name)) end end |
.factory(src) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/git_commands/branch.rb', line 30 def self.factory(src) return [] unless src branches = by_file(src) branches = by_pattern(src) if branches.empty? branches = by_names(src) if branches.empty? branches end |
.strip_origin(name) ⇒ Object
6 7 8 |
# File 'lib/git_commands/branch.rb', line 6 def self.strip_origin(name) name.strip.split(ORIGIN).last end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/git_commands/branch.rb', line 54 def ==(other) self.name == other.name end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/git_commands/branch.rb', line 44 def to_s @name end |
#valid? ⇒ Boolean
48 49 50 51 52 |
# File 'lib/git_commands/branch.rb', line 48 def valid? return false if master? return false unless exists? true end |