Class: Neetob::CLI::Github::Search

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/github/search.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from Base

#client

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods inherited from Base

#check_for_apps_and_all_neeto_repos_option

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(apps, key_to_search, search_file_path, sandbox = false) ⇒ Search

Returns a new instance of Search.



11
12
13
14
15
16
17
# File 'lib/neetob/cli/github/search.rb', line 11

def initialize(apps, key_to_search, search_file_path, sandbox = false)
  super()
  @apps = apps
  @key_to_search = key_to_search
  @search_file_path = search_file_path
  @sandbox = sandbox
end

Instance Attribute Details

#appsObject

Returns the value of attribute apps.



9
10
11
# File 'lib/neetob/cli/github/search.rb', line 9

def apps
  @apps
end

#key_to_searchObject

Returns the value of attribute key_to_search.



9
10
11
# File 'lib/neetob/cli/github/search.rb', line 9

def key_to_search
  @key_to_search
end

#sandboxObject

Returns the value of attribute sandbox.



9
10
11
# File 'lib/neetob/cli/github/search.rb', line 9

def sandbox
  @sandbox
end

#search_file_pathObject

Returns the value of attribute search_file_path.



9
10
11
# File 'lib/neetob/cli/github/search.rb', line 9

def search_file_path
  @search_file_path
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/neetob/cli/github/search.rb', line 19

def run
  matching_apps = find_all_matching_apps(apps, :github, sandbox)
  matching_apps.each do |app|
    begin
      ui.info("\n Searching in \"#{app}/#{search_file_path}\" for \"#{key_to_search}\"\n")
      content = Base64.decode64(client.contents(app, path: search_file_path).content)
      ui.error("Keyword not found") and next unless content.include? key_to_search

      content.each_line do |line|
        ui.success(line) if line.include?(key_to_search)
      end
    rescue StandardError => e
      ExceptionHandler.new(e).process
    end
  end
end