Class: LearnSubmit::Submission
- Inherits:
-
Object
- Object
- LearnSubmit::Submission
- Defined in:
- lib/learn_submit/submission.rb,
lib/learn_submit/submission/git_interactor.rb
Defined Under Namespace
Classes: GitInteractor
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#dot_learn ⇒ Object
readonly
Returns the value of attribute dot_learn.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#save ⇒ Object
readonly
Returns the value of attribute save.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #cleanup_tmp_file ⇒ Object
- #create ⇒ Object
-
#initialize(message:, save:) ⇒ Submission
constructor
A new instance of Submission.
- #setup_tmp_file ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(message:, save:) ⇒ Submission
Returns a new instance of Submission.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/learn_submit/submission.rb', line 11 def initialize(message:, save:) _login, @token = Netrc.read['learn-config'] @client = LearnWeb::Client.new(token: @token) @git = LearnSubmit::Submission::GitInteractor.new(username: user.username, message: ) @file_path = File.('~/.learn-submit-tmp') = @save = save @dot_learn = YAML.load(File.read("#{FileUtils.pwd}/.learn")) if File.exist?("#{FileUtils.pwd}/.learn") end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def client @client end |
#dot_learn ⇒ Object (readonly)
Returns the value of attribute dot_learn.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def dot_learn @dot_learn end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def file_path @file_path end |
#git ⇒ Object (readonly)
Returns the value of attribute git.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def git @git end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def end |
#save ⇒ Object (readonly)
Returns the value of attribute save.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def save @save end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/learn_submit/submission.rb', line 5 def token @token end |
Class Method Details
.create(message: nil, save: false) ⇒ Object
7 8 9 |
# File 'lib/learn_submit/submission.rb', line 7 def self.create(message: nil, save: false) new(message: , save: save).create end |
Instance Method Details
#cleanup_tmp_file ⇒ Object
37 38 39 |
# File 'lib/learn_submit/submission.rb', line 37 def cleanup_tmp_file File.write(file_path, 'Done.') end |
#create ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/learn_submit/submission.rb', line 22 def create setup_tmp_file commit_and_push! if !save submit! end end |
#setup_tmp_file ⇒ Object
32 33 34 35 |
# File 'lib/learn_submit/submission.rb', line 32 def setup_tmp_file FileUtils.touch(file_path) File.write(file_path, '') end |
#user ⇒ Object
41 42 43 |
# File 'lib/learn_submit/submission.rb', line 41 def user @user ||= client.me end |