Class: AddGem
- Inherits:
-
Object
- Object
- AddGem
- Defined in:
- lib/envGen/add_gem.rb
Constant Summary collapse
- @@gems =
gets updated list of all current RubyGems gems
`gem list --remote`.split("\n")
Instance Attribute Summary collapse
-
#gemName ⇒ Object
Returns the value of attribute gemName.
-
#gemsFound ⇒ Object
Returns the value of attribute gemsFound.
Class Method Summary collapse
Instance Method Summary collapse
-
#exactGem?(gemString) ⇒ Boolean
takes in a search term and a gem to match against.
-
#findPartialNames ⇒ Object
partial name search.
-
#gemEntry ⇒ Object
handles gem entry.
- #gemExists? ⇒ Boolean
- #gemSearch ⇒ Object
-
#inConfig? ⇒ Boolean
looks through environment for gem.
-
#initialize(input) ⇒ AddGem
constructor
input is gem name, called with @gemName.
- #noExactGem ⇒ Object
- #write ⇒ Object
- #writeExactGem ⇒ Object
Constructor Details
#initialize(input) ⇒ AddGem
input is gem name, called with @gemName
12 13 14 |
# File 'lib/envGen/add_gem.rb', line 12 def initialize(input) # input is gem name, called with @gemName @gemName = input end |
Instance Attribute Details
#gemName ⇒ Object
Returns the value of attribute gemName.
4 5 6 |
# File 'lib/envGen/add_gem.rb', line 4 def gemName @gemName end |
#gemsFound ⇒ Object
Returns the value of attribute gemsFound.
4 5 6 |
# File 'lib/envGen/add_gem.rb', line 4 def gemsFound @gemsFound end |
Class Method Details
.gems ⇒ Object
8 9 10 |
# File 'lib/envGen/add_gem.rb', line 8 def self.gems @@gems end |
Instance Method Details
#exactGem?(gemString) ⇒ Boolean
takes in a search term and a gem to match against
21 22 23 |
# File 'lib/envGen/add_gem.rb', line 21 def exactGem?(gemString) # takes in a search term and a gem to match against gemString.split(" ").first == gemName.downcase end |
#findPartialNames ⇒ Object
partial name search
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/envGen/add_gem.rb', line 55 def findPartialNames # partial name search gemsFound = [] puts "Searching through #{@@gems.count} gems..." AddGem.gems.each do |gemString| # searching through gems + version numbers if exactGem?(gemString) gemsFound.unshift("** #{gemString}") # highlights exact match elsif gemString.include?(gemName.downcase) gemsFound << gemString end end gemsFound end |
#gemEntry ⇒ Object
handles gem entry
45 46 47 48 49 50 51 52 53 |
# File 'lib/envGen/add_gem.rb', line 45 def gemEntry # handles gem entry if !inConfig? && gemExists? writeExactGem elsif inConfig? && gemExists? # add gem if doesn't exist puts "'#{gemName}' already added" else noExactGem end end |
#gemExists? ⇒ Boolean
25 26 27 |
# File 'lib/envGen/add_gem.rb', line 25 def gemExists? @@gems.select {|gem| gem.split(" ").first == gemName }.count > 0 end |
#gemSearch ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/envGen/add_gem.rb', line 68 def gemSearch gemsFound = findPartialNames if gemsFound.count == 0 puts "No exact match for '#{gemName.downcase}' found" else puts "\nFound #{gemsFound.count} gems:" gemsFound.each {|gem| puts gem} end end |
#inConfig? ⇒ Boolean
looks through environment for gem
16 17 18 19 |
# File 'lib/envGen/add_gem.rb', line 16 def inConfig? # looks through environment for gem # binding.pry File.readlines("config/environment.rb").grep("gem '#{gemName}'\n").count > 0 end |
#noExactGem ⇒ Object
40 41 42 43 |
# File 'lib/envGen/add_gem.rb', line 40 def noExactGem puts "No exact match for '#{gemName}' found" puts "Search for partial gem name with 'gem -s [gem]'" end |
#write ⇒ Object
29 30 31 32 33 |
# File 'lib/envGen/add_gem.rb', line 29 def write File.open("config/environment.rb", "a") {|env| env.puts "gem '#{gemName}'" } end |
#writeExactGem ⇒ Object
35 36 37 38 |
# File 'lib/envGen/add_gem.rb', line 35 def writeExactGem write puts "Added '#{gemName}'" end |