Class: Octopolo::GitHub::Label

Inherits:
Object
  • Object
show all
Extended by:
ConfigWrapper
Defined in:
lib/octopolo/github/label.rb

Instance Attribute Summary collapse

Attributes included from ConfigWrapper

#config

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Label

Returns a new instance of Label.



12
13
14
15
# File 'lib/octopolo/github/label.rb', line 12

def initialize(args)
  self.name = args[:name]
  self.color = args[:color]
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



10
11
12
# File 'lib/octopolo/github/label.rb', line 10

def color
  @color
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/octopolo/github/label.rb', line 9

def name
  @name
end

Class Method Details

.allObject

Public: Grabs all labels from either file or github

This is the method to override for labels from files


23
24
25
# File 'lib/octopolo/github/label.rb', line 23

def self.all
  all_from_repo
end

.build_label_array(*labels) ⇒ Object

Public: Finds or creates each of the passed in labels

labels - label objects, can be a single label, an array of labels,

or a list of labels

returns - an array of labels.



51
52
53
# File 'lib/octopolo/github/label.rb', line 51

def self.build_label_array(*labels)
  Array(labels).flatten.each {|label| first_or_create(label)}
end

.first_or_create(label) ⇒ Object

Public: Checks to see if label exists on remote, if not makes one.

label - a label object



39
40
41
42
43
# File 'lib/octopolo/github/label.rb', line 39

def self.first_or_create(label)
  unless all_from_repo.include?(label)
    GitHub.add_label(config.github_repo, label.name, label.color)
  end
end

.get_names(label_array) ⇒ Object

Public: Gets the names of labels

label_array - an array of labels

returns - an array of all names from label_array



32
33
34
# File 'lib/octopolo/github/label.rb', line 32

def self.get_names(label_array)
  label_array.map{ |label| label.name }
end

Instance Method Details

#==(obj) ⇒ Object



17
18
19
# File 'lib/octopolo/github/label.rb', line 17

def == (obj)
  (self.name == obj.name) ? true : false
end