mumukit-sync 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +12 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +49 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/mumukit/sync.rb +28 -0
  13. data/lib/mumukit/sync/inflator.rb +14 -0
  14. data/lib/mumukit/sync/inflator/choice.rb +11 -0
  15. data/lib/mumukit/sync/inflator/exercise.rb +11 -0
  16. data/lib/mumukit/sync/inflator/gobstones_kids_boards.rb +35 -0
  17. data/lib/mumukit/sync/inflator/multiple_choice.rb +15 -0
  18. data/lib/mumukit/sync/inflator/single_choice.rb +12 -0
  19. data/lib/mumukit/sync/store.rb +12 -0
  20. data/lib/mumukit/sync/store/bibliotheca.rb +23 -0
  21. data/lib/mumukit/sync/store/github.rb +59 -0
  22. data/lib/mumukit/sync/store/github/bot.rb +76 -0
  23. data/lib/mumukit/sync/store/github/exercise_builder.rb +19 -0
  24. data/lib/mumukit/sync/store/github/git_lib.rb +14 -0
  25. data/lib/mumukit/sync/store/github/guide_builder.rb +43 -0
  26. data/lib/mumukit/sync/store/github/guide_export.rb +50 -0
  27. data/lib/mumukit/sync/store/github/guide_import.rb +14 -0
  28. data/lib/mumukit/sync/store/github/guide_reader.rb +88 -0
  29. data/lib/mumukit/sync/store/github/guide_writer.rb +89 -0
  30. data/lib/mumukit/sync/store/github/licenses/COPYRIGHT.txt.erb +5 -0
  31. data/lib/mumukit/sync/store/github/licenses/LICENSE.txt +428 -0
  32. data/lib/mumukit/sync/store/github/licenses/README.md.erb +6 -0
  33. data/lib/mumukit/sync/store/github/operation.rb +47 -0
  34. data/lib/mumukit/sync/store/github/ordering.rb +23 -0
  35. data/lib/mumukit/sync/store/github/schema.rb +123 -0
  36. data/lib/mumukit/sync/store/github/schema/exercise.rb +37 -0
  37. data/lib/mumukit/sync/store/github/schema/guide.rb +28 -0
  38. data/lib/mumukit/sync/store/github/with_file_reading.rb +19 -0
  39. data/lib/mumukit/sync/store/json.rb +27 -0
  40. data/lib/mumukit/sync/store/thesaurus.rb +19 -0
  41. data/lib/mumukit/sync/syncer.rb +63 -0
  42. data/lib/mumukit/sync/version.rb +5 -0
  43. data/mumukit-sync.gemspec +34 -0
  44. metadata +198 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f7baaa8e76bf058e052f2780556fb3d65117180
4
+ data.tar.gz: 600774b772fc093e84e65725772886b952b21bf7
5
+ SHA512:
6
+ metadata.gz: 39ea6d27c387074ab92beac6e6af8d2c3bc6e07f8be9426afc7fbd26fa2161c3f3657ada11e1cd334696d0469fc7dc04f4dfb433e09527b854c87c4dfbc647d3
7
+ data.tar.gz: 717401eaf93664c692023bc31a0975e1c4bf3fd98ea3b70ad343401a1dca77c64e3bb8b7da29e8d3ba271ec8cde0574b452a733554839bbda4f5be795f14b17e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.10.6
5
+ deploy:
6
+ provider: rubygems
7
+ api_key:
8
+ secure: f0boGHzgJp2bzHbxBEZAEgJ7hO8Iv5Ays6HHfm5nOphg+SMKkmqGpEPPCwbCiiw4ZQ5KyAbxjLvclMzDknpku3v13fXtVlVWyGMH+vpHZnKmgsPWzJ29XTEEzC1FNc1WYEtxhXaCQ9W8xB00j4ahukmVRJOTt+TD0hRsaRXtY0T7HC9JQQkT1x52qf3rhxRM1dgfRJdorB545xAxpyHx1Psy0kCSx+mVRlF0pETRvAy84X6Igjyvc2ovgGKbpRVeA1e5TsWrKjNoBbeKXDBzdND4hDpa9dyshgO33edo4qN4RWh+WPdQTeu8opv8sBOA7sH/Dzx20nII8DDeSPon9jYa7B8DBb1m/DnjjhTmka96n3WBbSeXSCEWGs+KgQO6OBNIR0gghOl3P380ocMLN9nWCNFwTBc/zUY6AsoQyV2hQI5rivTldJOAClEvDGDzZFl2bTRyic4jcn8U/USS7M3Rp3/s4si8km6s0Oy8FLtfnOINznM6quQiDjaXgI5acxx18AncQeqV4nmWxnEALI1i96McJvj3ONZOpzRlp2t1A3Qx5AdbypP9IKgHuBHGSq9W+oifuSN7xRh6Q/yuoWRgo39pdw075LhnUQgX8MVevVU4kGVwGPslirMQb5prf3lvLEQrZhAcGGgrq/vST1ZGesViFwV53LvM3nZGnRs=
9
+ gem: mumukit-sync
10
+ on:
11
+ tags: true
12
+ repo: mumuki/mumukit-sync
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at franco@mumuki.org. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Franco Bulgarelli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ [![Stories in Ready](https://badge.waffle.io/mumuki/mumukit-sync.png?label=ready&title=Ready)](https://waffle.io/mumuki/mumukit-sync)
2
+ [![Build Status](https://travis-ci.org/mumuki/mumukit-sync.svg?branch=master)](https://travis-ci.org/mumuki/mumukit-sync)
3
+ [![Code Climate](https://codeclimate.com/github/mumuki/mumukit-sync/badges/gpa.svg)](https://codeclimate.com/github/mumuki/mumukit-sync)
4
+ [![Test Coverage](https://codeclimate.com/github/mumuki/mumukit-sync/badges/coverage.svg)](https://codeclimate.com/github/mumuki/mumukit-sync)
5
+
6
+
7
+ # Mumukit::Sync
8
+
9
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mumukit/sync`. To experiment with that code, run `bin/console` for an interactive prompt.
10
+
11
+ TODO: Delete this and the text above, and describe your gem
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'mumukit-sync'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install mumukit-sync
28
+
29
+ ## Usage
30
+
31
+ TODO: Write usage instructions here
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mumukit-sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the Mumukit::Sync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mumukit-sync/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mumukit/sync"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require 'git'
2
+ require 'octokit'
3
+
4
+
5
+ require "mumukit/sync/version"
6
+
7
+ module Mumukit
8
+ module Sync
9
+ ## Creates a sync key, composed of a `kind` and `id`
10
+ def self.key(kind, id)
11
+ struct kind: kind, id: id
12
+ end
13
+
14
+ def self.constantize(kind)
15
+ classify(kind).constantize
16
+ end
17
+
18
+ def self.classify(kind)
19
+ kind.to_s.classify
20
+ end
21
+ end
22
+ end
23
+
24
+ require 'mumukit/core'
25
+
26
+ require_relative './sync/syncer'
27
+ require_relative './sync/store'
28
+ require_relative './sync/inflator'
@@ -0,0 +1,14 @@
1
+ module Mumukit::Sync
2
+ module Inflator
3
+ def self.inflate_with!(sync_key, resource_h, inflators)
4
+ inflators.each { |it| it.inflate! sync_key, resource_h }
5
+ end
6
+ end
7
+ end
8
+
9
+ require_relative './inflator/exercise'
10
+ require_relative './inflator/choice'
11
+ require_relative './inflator/single_choice'
12
+ require_relative './inflator/multiple_choice'
13
+ require_relative './inflator/gobstones_kids_boards'
14
+
@@ -0,0 +1,11 @@
1
+ module Mumukit::Sync::Inflator
2
+ class Choice < Exercise
3
+ def inflate_exercise!(exercise_h, language_name, guide_h)
4
+ return unless language_name == 'text'
5
+ return unless exercise_h[:editor] == editor_type
6
+ return if exercise_h[:test]
7
+
8
+ exercise_h[:test] = choices_to_test(exercise_h[:choices])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Mumukit::Sync::Inflator
2
+ class Exercise
3
+ def inflate!(key, resource_h)
4
+ return unless key.kind == :guide
5
+ resource_h[:exercises]&.each do |it|
6
+ language = it.dig(:language, :name) || resource_h.dig(:language, :name)
7
+ inflate_exercise! it, language, resource_h
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ module Mumukit::Sync::Inflator
2
+ class GobstonesKidsBoards < Exercise
3
+ def inflate_exercise!(exercise_h, language_name, guide_h)
4
+ return unless language_name == 'gobstones'
5
+ return unless exercise_h[:layout] == 'input_kids'
6
+ return unless exercise_h[:test]
7
+
8
+ spec = YAML.load(exercise_h[:test])
9
+ example = spec&.dig('examples')&.first
10
+ with_head = spec&.dig('check_head_position')
11
+
12
+ return unless example
13
+
14
+ exercise_h[:initial_state] = initial_board example
15
+ exercise_h[:final_state] = final_board example, with_head
16
+ end
17
+
18
+ def to_gs_board(board, with_head)
19
+ "<gs-board#{with_head ? "" : " without-header"}> #{board} </gs-board>" if board
20
+ end
21
+
22
+
23
+ def initial_board(example)
24
+ to_gs_board(example['initial_board'], true)
25
+ end
26
+
27
+ def final_board(example, with_head)
28
+ to_gs_board(example['final_board'], with_head) || self.class.boom_board
29
+ end
30
+
31
+ def self.boom_board
32
+ "<img src='https://user-images.githubusercontent.com/1631752/37945593-54b482c0-3157-11e8-9f32-bd25d7bf901b.png'>"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module Mumukit::Sync::Inflator
2
+ class MultipleChoice < Choice
3
+ def editor_type
4
+ 'multiple_choice'
5
+ end
6
+
7
+ def choices_to_test(choices)
8
+ value = choices.each_with_index
9
+ .map { |choice, index| choice.merge(:index => index.to_s) }
10
+ .select { |choice| choice[:checked] }
11
+ .map { |choice| choice[:index] }.join(':')
12
+ {'equal' => value}.to_yaml
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Mumukit::Sync::Inflator
2
+ class SingleChoice < Choice
3
+ def editor_type
4
+ 'single_choice'
5
+ end
6
+
7
+ def choices_to_test(choices)
8
+ choice = choices.find { |choice| choice[:checked] }
9
+ {'equal' => choice[:value]}.to_yaml
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'mumukit/bridge'
2
+
3
+ module Mumukit::Sync
4
+ module Store
5
+ end
6
+ end
7
+
8
+
9
+ require_relative './store/github'
10
+ require_relative './store/json'
11
+ require_relative './store/thesaurus'
12
+ require_relative './store/bibliotheca'
@@ -0,0 +1,23 @@
1
+ module Mumukit::Sync::Store
2
+ class Bibliotheca
3
+ def initialize(bibliotheca_bridge)
4
+ @bibliotheca_bridge = bibliotheca_bridge
5
+ end
6
+
7
+ def sync_keys
8
+ %w(guide topic book).flat_map do |kind|
9
+ @bibliotheca_bridge
10
+ .send(kind.to_s.pluralize)
11
+ .map { |it| Mumukit::Sync.key kind, it['slug'] }
12
+ end
13
+ end
14
+
15
+ def read_resource(sync_key)
16
+ @bibliotheca_bridge.send(sync_key.kind, sync_key.id)
17
+ end
18
+
19
+ def write_resource!(*)
20
+ raise 'Read-only store'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ module Mumukit::Sync::Store
2
+ class Github
3
+ def initialize(bot, author_email = nil, web_hook_base_url = nil)
4
+ @bot = bot
5
+ @author_email = author_email || bot.email
6
+ @web_hook_base_url = web_hook_base_url
7
+ end
8
+
9
+ def sync_keys
10
+ raise 'Non-discoverable store'
11
+ end
12
+
13
+ def read_resource(sync_key)
14
+ return unless sync_key.kind == :guide
15
+
16
+ Mumukit::Sync::Store::Github::GuideImport.new(
17
+ bot: @bot,
18
+ repo: sync_key.id,
19
+ web_hook_base_url: @web_hook_base_url).run!
20
+ end
21
+
22
+ def write_resource!(sync_key, resource_h)
23
+ return unless sync_key.kind == :guide
24
+
25
+ Mumukit::Sync::Store::Github::GuideExport.new(
26
+ slug: sync_key.id,
27
+ document: resource_h,
28
+ author_email: @author_email,
29
+ web_hook_base_url: @web_hook_base_url,
30
+ bot: @bot).run!
31
+ end
32
+ end
33
+
34
+ ## FIXME REMOVE
35
+ class Github::Bot
36
+ def upload_asset!(slug, filename, content)
37
+ path = "assets/#{filename.gsub(/\.(.*){2,4}/) { |it| "_#{(Time.now.to_f * 1000).to_i}#{it}" }}"
38
+ octokit.create_contents(slug.to_s,
39
+ path,
40
+ 'Uploading new asset',
41
+ content).content.to_h
42
+ end
43
+ end
44
+ end
45
+
46
+ require 'mumukit/auth'
47
+
48
+ require_relative './github/bot'
49
+ require_relative './github/git_lib'
50
+ require_relative './github/with_file_reading'
51
+ require_relative './github/guide_reader'
52
+ require_relative './github/guide_builder'
53
+ require_relative './github/exercise_builder'
54
+ require_relative './github/guide_writer'
55
+ require_relative './github/operation'
56
+ require_relative './github/guide_export'
57
+ require_relative './github/guide_import'
58
+ require_relative './github/ordering'
59
+ require_relative './github/schema'