Class: Github::Nippou::Settings
- Inherits:
-
Object
- Object
- Github::Nippou::Settings
- Defined in:
- lib/github/nippou/settings.rb
Defined Under Namespace
Classes: GettingAccessTokenError, GettingUserError
Instance Method Summary collapse
-
#access_token(verbose: true) ⇒ String
Getting GitHub personal access token.
-
#client ⇒ Object
Getting Octokit client.
-
#create_gist ⇒ Sawyer::Resource
Create gist with config/settings.yml.
-
#default_url ⇒ String
Getting default settings url.
-
#dictionary ⇒ OpenStruct
Getting dictionary settings.
-
#format ⇒ OpenStruct
Getting format settings.
-
#gist_id ⇒ String
Getting gist id which has settings.yml.
-
#thread_num ⇒ Integer
Getting thread number.
-
#url ⇒ String
Getting settings url.
-
#user(verbose: true) ⇒ String
Getting GitHub user.
Instance Method Details
#access_token(verbose: true) ⇒ String
Getting GitHub personal access token
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/github/nippou/settings.rb', line 37 def access_token(verbose: true) @access_token ||= case when ENV['GITHUB_NIPPOU_ACCESS_TOKEN'] ENV['GITHUB_NIPPOU_ACCESS_TOKEN'] when !`git config github-nippou.token`.chomp.empty? `git config github-nippou.token`.chomp else puts " !!!! GitHub Personal access token required. Please execute the following command. !!!!\n\n $ github-nippou init\n MESSAGE\n raise GettingAccessTokenError\n end\nend\n" if verbose |
#client ⇒ Object
Getting Octokit client
return [Octokit::Client]
86 87 88 |
# File 'lib/github/nippou/settings.rb', line 86 def client @client ||= Octokit::Client.new(login: user, access_token: access_token) end |
#create_gist ⇒ Sawyer::Resource
Create gist with config/settings.yml
93 94 95 96 97 98 99 |
# File 'lib/github/nippou/settings.rb', line 93 def create_gist client.create_gist( description: 'github-nippou settings', public: true, files: { 'settings.yml' => { content: default_settings.to_yaml }} ) end |
#default_url ⇒ String
Getting default settings url
116 117 118 |
# File 'lib/github/nippou/settings.rb', line 116 def default_url "https://github.com/masutaka/github-nippou/blob/v#{VERSION}/config/settings.yml" end |
#dictionary ⇒ OpenStruct
Getting dictionary settings
130 131 132 |
# File 'lib/github/nippou/settings.rb', line 130 def dictionary open_struct(data[:dictionary]) end |
#format ⇒ OpenStruct
Getting format settings
123 124 125 |
# File 'lib/github/nippou/settings.rb', line 123 def format open_struct(data[:format]) end |
#gist_id ⇒ String
Getting gist id which has settings.yml
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/github/nippou/settings.rb', line 57 def gist_id @gist_id ||= begin ENV['GITHUB_NIPPOU_SETTINGS_GIST_ID'] || begin git_config = `git config github-nippou.settings-gist-id`.chomp git_config.present? ? git_config : nil end end end |
#thread_num ⇒ Integer
Getting thread number
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/github/nippou/settings.rb', line 71 def thread_num @thread_num ||= case when ENV['GITHUB_NIPPOU_THREAD_NUM'] ENV['GITHUB_NIPPOU_THREAD_NUM'] when !`git config github-nippou.thread-num`.chomp.empty? `git config github-nippou.thread-num`.chomp else 5 end.to_i end |
#url ⇒ String
Getting settings url
104 105 106 107 108 109 110 111 |
# File 'lib/github/nippou/settings.rb', line 104 def url @url ||= if gist_id client.gist(gist_id).html_url else default_url end end |
#user(verbose: true) ⇒ String
Getting GitHub user
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/github/nippou/settings.rb', line 15 def user(verbose: true) @user ||= case when ENV['GITHUB_NIPPOU_USER'] ENV['GITHUB_NIPPOU_USER'] when !`git config github-nippou.user`.chomp.empty? `git config github-nippou.user`.chomp else puts " !!!! GitHub User required. Please execute the following command. !!!!\n\n $ github-nippou init\n MESSAGE\n raise GettingUserError\n end\nend\n" if verbose |