Class: Ignore::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ignore/command.rb

Class Method Summary collapse

Class Method Details

.append(name) ⇒ Object



60
61
62
63
# File 'lib/ignore/command.rb', line 60

def append(name)
  contents = storage.load(name)
  gitignore.append(contents,name)
end

.cleanObject



69
70
71
# File 'lib/ignore/command.rb', line 69

def clean
  storage.clear
end

.delegate(first, second) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ignore/command.rb', line 11

def delegate(first, second)
  return help                   if first == 'help'
  return list                   if first == 'list'
  return clean                  if first == 'clean'
  return update                 if first == 'update'
  return saveas(second)         if first == 'saveas' and second
  return getfile(second,:show)  if first == 'show' and second
  return getfile(first,:append) if first and second.nil?
  
  storage #fetch and print help
  help
end

.execute(*args) ⇒ Object



5
6
7
8
9
# File 'lib/ignore/command.rb', line 5

def execute(*args)
  first = args.shift
  second = args.shift
  delegate(first, second)
end

.getfile(language, callback) ⇒ Object



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
# File 'lib/ignore/command.rb', line 29

def getfile(language, callback)
  exact = storage.match(language)
  
  return self.send(callback, exact.first) unless exact.empty? 

  loose = storage.match(language, false)
  
  case
    when loose.length  < 1
      output("No such gitignore #{language}")
    
    when loose.length == 1
      self.send( callback, loose.first )
    
    when (loose.length > 1 and loose.length < 5)
      output "Please specify: \n#{loose.reduce(""){|res,name| res+=name+"\n"}}"
    
    when loose.length > 5
      output "Please be more specific"
    
    else
      output("uh-oh? something went wrong")
  end

end

.gitignoreObject



98
99
100
# File 'lib/ignore/command.rb', line 98

def gitignore
  @gitignore ||= Gitignore.new
end

.helpObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ignore/command.rb', line 78

def help()
  text= %{
  ignore : help -------------------------------------------------------

  ignore <language>           add specified languages gitignore to working directory
  ignore list                 list available gitignores
  ignore show <language>      print the language to STDOUT (use with '| less')
  ignore update               update from github.com/github/gitignore
  ignore clean                empty your local ~/.ignores folder
  ignore help                 show help

  see https://github.com/samirahmed/ignore for more documentation
    }
  output(text)
end

.inputObject



102
103
104
# File 'lib/ignore/command.rb', line 102

def input
  $stdin
end

.listObject



24
25
26
27
# File 'lib/ignore/command.rb', line 24

def list
  list = storage.list
  output( list.reduce(""){|res,line| res+= line.chomp('.gitignore')+"\n" })
end

.outprint(s) ⇒ Object



106
107
108
# File 'lib/ignore/command.rb', line 106

def outprint(s)
  print(s)
end

.output(s) ⇒ Object



110
111
112
# File 'lib/ignore/command.rb', line 110

def output(s)
  puts(s)
end

.saveas(name) ⇒ Object



73
74
75
76
# File 'lib/ignore/command.rb', line 73

def saveas( name )
  return storage.write(name,gitignore.read) if gitignore.exists?
  return output("No .gitignore found in the #{gitignore.path}")
end

.show(name) ⇒ Object



55
56
57
58
# File 'lib/ignore/command.rb', line 55

def show(name)
  contents = storage.load(name)
  output(contents)
end

.storageObject



94
95
96
# File 'lib/ignore/command.rb', line 94

def storage
  @storage ||= Storage.new
end

.updateObject



65
66
67
# File 'lib/ignore/command.rb', line 65

def update
  storage.update
end