Class: Ana::Command

Inherits:
Thor
  • Object
show all
Includes:
Scalars, Thor::Actions
Defined in:
lib/ana/command.rb

Constant Summary

Constants included from Scalars

Scalars::GEM_DOES_NOT_EXIST, Scalars::GEM_NOT_FOUND, Scalars::GEM_VER_NOT_FOUND, Scalars::TTL, Scalars::URI_TYPE

Instance Method Summary collapse

Instance Method Details

#download(gem) ⇒ Object



150
151
152
153
# File 'lib/ana/command.rb', line 150

def download(gem)
  return if gem_does_not_exist?(gem)
  open gem, 'lib'
end

#find_version(gem, ver = 'no-input') ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ana/command.rb', line 100

def find_version(gem, ver='no-input')
  return if gem_does_not_exist?(gem)
  if ver == 'no-input'
    say 'Please specify a version'
    return
  end
  gem_hash = get_gem_json!(gem, type: 'versions')
  versions = gem_hash.collect { |x| x['number'] }
  if versions.include? ver
    gem_infos gem
  else
    print_gem_version_not_found!
  end
end

#fuzzy_search(gem) ⇒ Object



124
125
126
127
# File 'lib/ana/command.rb', line 124

def fuzzy_search(gem)
  return if gem_does_not_exist?(gem)
  system("gem search -r #{Shellwords.escape gem}")
end

#gem_dependencies(gem, type = 'runtime') ⇒ Object



62
63
64
65
66
67
68
# File 'lib/ana/command.rb', line 62

def gem_dependencies(gem, type='runtime')
  return if gem_does_not_exist?(gem)
  gem_hash = get_gem_json!(gem, type: 'gems')
  gem_hash['dependencies'][type].each do |arr|
    puts "#{arr['name'].ljust(20)} #{arr['requirements']}"
  end
end

#gem_infos(gem) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ana/command.rb', line 44

def gem_infos(gem)
  return if gem_does_not_exist?(gem)
  gem_hash = get_gem_json!(gem, type: 'gems')
  say gem_hash['info']
  say "Has been downloaded for #{colorize(gem_hash['downloads'], RED)} times!"
  say "The Latest version is #{colorize(gem_hash['version'], BLUE)}."
  say "Respectful Author(s): #{colorize(gem_hash['authors'], YELLOW)}."
  if gem_hash['licenses'][0].nil?
    say "NO LICENSE :P"
  else
    say "LICENSE under #{colorize(gem_hash['licenses'][0], MAGENTA)}"
  end
end

#initObject



32
33
34
# File 'lib/ana/command.rb', line 32

def init
  empty_directory full_path('~/.gemjsons')
end

#latest_version(gem) ⇒ Object



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

def latest_version(gem)
  return if gem_does_not_exist?(gem)
  gem_hash = get_gem_json!(gem, type: 'gems')
  say("Latest version is #{gem_hash['version']}.", :blue) if gem_hash
end

#open(gem, open_type = 'home') ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ana/command.rb', line 133

def open(gem, open_type='home')
  return if gem_does_not_exist?(gem)
  gem_hash = get_gem_json!(gem, type: 'gems')
  url = if URI_TYPE.keys.include? open_type
          skip = false
          gem_hash[URI_TYPE[open_type]]
        else
          say "#{open_type} is not a valid type :( \n"
          print_valid_uri_open_types!
          skip = true
        end
  Launchy.open(url) if url.present? && skip == false
  say "Nothing to open, this gem probably does not have #{open_type} page" if url.blank? || skip
end

#search(gem) ⇒ Object



117
118
119
120
# File 'lib/ana/command.rb', line 117

def search(gem)
  return if gem_does_not_exist?(gem)
  latest_version(gem)
end

#versionObject



37
38
39
# File 'lib/ana/command.rb', line 37

def version
  say "#{Ana::VERSION::STRING}"
end

#versions(gem, count = 10) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ana/command.rb', line 81

def versions(gem, count=10)
  if number?(count.to_s) == false
    say "#{count} is not a number :("
    return
  end
  return if gem_does_not_exist?(gem)
  gem_hash = get_gem_json!(gem, type: 'versions')
  if count == 'all' || count.to_i > gem_hash.count
    count = gem_hash.count
  end
  say("Last #{count} versions of #{gem} are...")
  [*0..count.to_i-1].each do |n|
    say("#{gem_hash[n]['built_at'][0..9]} : #{gem_hash[n]['number']}")
  end
end