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.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/learn_submit/submission.rb', line 12 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') @message = @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.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def client @client end |
#dot_learn ⇒ Object (readonly)
Returns the value of attribute dot_learn.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def dot_learn @dot_learn end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def file_path @file_path end |
#git ⇒ Object (readonly)
Returns the value of attribute git.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def git @git end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def @message end |
#save ⇒ Object (readonly)
Returns the value of attribute save.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def save @save end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/learn_submit/submission.rb', line 6 def token @token end |
Class Method Details
.create(message: nil, save: false) ⇒ Object
8 9 10 |
# File 'lib/learn_submit/submission.rb', line 8 def self.create(message: nil, save: false) new(message: , save: save).create end |
Instance Method Details
#cleanup_tmp_file ⇒ Object
38 39 40 |
# File 'lib/learn_submit/submission.rb', line 38 def cleanup_tmp_file File.write(file_path, 'Done.') end |
#create ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/learn_submit/submission.rb', line 23 def create setup_tmp_file commit_and_push! if !save submit! end end |
#setup_tmp_file ⇒ Object
33 34 35 36 |
# File 'lib/learn_submit/submission.rb', line 33 def setup_tmp_file FileUtils.touch(file_path) File.write(file_path, '') end |
#user ⇒ Object
42 43 44 |
# File 'lib/learn_submit/submission.rb', line 42 def user @user ||= client.me end |