Class: Mumukit::Sync::Store::Github::GuideExport

Inherits:
Operation
  • Object
show all
Includes:
WithSchema
Defined in:
lib/mumukit/sync/store/github/guide_export.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WithSchema

#build_fields_h, #exercise_schema, #guide_schema

Methods inherited from Operation

#ensure_post_commit_hook!, #run!, #with_local_repo

Constructor Details

#initialize(options) ⇒ GuideExport

Returns a new instance of GuideExport.



7
8
9
10
11
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 7

def initialize(options)
  super(options)
  @guide_resource_h = options[:document]
  @author_email = options[:author_email]
end

Instance Attribute Details

#author_emailObject

Returns the value of attribute author_email.



5
6
7
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 5

def author_email
  @author_email
end

#botObject

Returns the value of attribute bot.



5
6
7
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 5

def bot
  @bot
end

#guide_resource_hObject

Returns the value of attribute guide_resource_h.



5
6
7
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 5

def guide_resource_h
  @guide_resource_h
end

Instance Method Details

#before_run_in_local_repoObject



21
22
23
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 21

def before_run_in_local_repo
  bot.ensure_exists! repo, guide_resource_h[:private]
end

#can_run?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 17

def can_run?
  bot.authenticated?
end

#repoObject



13
14
15
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 13

def repo
  @repo ||= Mumukit::Auth::Slug.parse(guide_resource_h[:slug])
end

#run_in_local_repo(dir, local_repo) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/mumukit/sync/store/github/guide_export.rb', line 25

def run_in_local_repo(dir, local_repo)
  clear_repo local_repo
  GuideWriter.new(dir).write_guide! guide_resource_h
  local_repo.add(all: true)
  local_repo.commit("Mumuki Export on #{Time.now}", commit_options)
  local_repo.push
rescue StandardError => e
  puts "Could not export guide #{guide_resource_h[:slug]} to git #{e}"
end