mumuki-domain 7.0.6 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c111563c53bbd8b40ee80ea56f0d3dc90f8c8ac666ca1688fb8419745bc63cff
4
- data.tar.gz: 298300bc4e45eda5c512c637b91e90f10cc13c80b6e7fa9155c485b4bfce56ad
3
+ metadata.gz: fe0f9389e1714c564320f373c82d35b3b84a3c27bd68af16584c68c4f38639f8
4
+ data.tar.gz: ca0b57c648127393d93ffab7c5beee55d6abdb31e80f37f33b787f33470ec171
5
5
  SHA512:
6
- metadata.gz: f452c3d9383b0b59a458a88332e879351e342d63e574e512bb1c70adb9b3b3a11c24019ac86a86425910d72a19a8c9f686ee62bab4924add598c827df1843003
7
- data.tar.gz: 8afb07a6b0ea3d070311fd70008f008059366889ee78509dff3f17b47a10713b4d30c4db04a5926bc3d439ce5a1183ca846057ddd80b39e620b3b39315b6fc9a
6
+ metadata.gz: 1cd397c42e1b6f16d4b903a5829087758eeb75ca190c2eb0902866a688a124f982e18fca28ca997d26b118eb8a0efa3a35f37b23b3e0a3ffab292fd7ee6c70ee
7
+ data.tar.gz: 49a329e6663553e44e6865e44224d9f27fa0befefd6bdcfb04fe460800a9b42a5f7aadd56c09793dbf7c8983531aae6a54f7a75659676e0eb3b9e23795590e7c
data/README.md CHANGED
@@ -5,28 +5,32 @@
5
5
  ### `Language`
6
6
 
7
7
  ```
8
- name
9
8
  comment_type
10
- runner_url
11
- output_content_type
12
- prompt
13
- extension
14
- highlight_mode
15
- visible_success_output
16
9
  devicon
17
- triable
10
+ editor_css_urls
11
+ editor_html_urls
12
+ editor_js_urls
13
+ editor_shows_loading_content
14
+ expectations
15
+ extension
18
16
  feedback
19
- queriable
17
+ highlight_mode
18
+ layout_css_urls
19
+ layout_html_urls
20
+ layout_js_urls
21
+ layout_shows_loading_content
20
22
  multifile
23
+ name
24
+ output_content_type
25
+ prompt
26
+ queriable
27
+ runner_url
28
+ settings
21
29
  stateful_console
22
30
  test_extension
23
31
  test_template
24
- layout_js_urls
25
- layout_html_urls
26
- layout_css_urls
27
- editor_js_urls
28
- editor_html_urls
29
- editor_css_urls
32
+ triable
33
+ visible_success_output
30
34
  ```
31
35
 
32
36
  _as defined in `Language#to_resource_h`_
@@ -67,9 +67,9 @@ class ApplicationRecord < ActiveRecord::Base
67
67
 
68
68
  def self.aggregate_of(association)
69
69
  class_eval do
70
- define_method(:rebuild!) do |children|
70
+ define_method("rebuild_#{association}!") do |children|
71
71
  transaction do
72
- self.send(association).all_except(children).delete_all
72
+ self.send(association).all_except(children).destroy_all
73
73
  self.update! association => children
74
74
  children.each &:save!
75
75
  end
data/app/models/book.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  class Book < Content
2
2
  numbered :chapters
3
3
  aggregate_of :chapters
4
+ aggregate_of :complements
4
5
 
5
6
  has_many :chapters, -> { order(number: :asc) }, dependent: :destroy
7
+ has_many :topics, through: :chapters
6
8
  has_many :complements, dependent: :destroy
7
9
 
8
10
  has_many :exercises, through: :chapters
@@ -11,6 +13,8 @@ class Book < Content
11
13
 
12
14
  delegate :first_lesson, to: :first_chapter
13
15
 
16
+ alias_method :children, :topics
17
+
14
18
  def to_s
15
19
  slug
16
20
  end
@@ -23,13 +27,11 @@ class Book < Content
23
27
  user.try(:last_lesson)|| first_lesson
24
28
  end
25
29
 
26
- after_save :reindex_usages!
27
-
28
30
  def import_from_resource_h!(resource_h)
29
31
  self.assign_attributes resource_h.except(:chapters, :complements, :id, :description)
30
32
  self.description = resource_h[:description]&.squeeze(' ')
31
33
 
32
- rebuild! resource_h[:chapters].map { |it| Topic.find_by!(slug: it).as_chapter_of(self) }
34
+ rebuild_chapters! resource_h[:chapters].map { |it| Topic.find_by!(slug: it).as_chapter_of(self) }
33
35
  rebuild_complements! resource_h[:complements].to_a.map { |it| Guide.find_by(slug: it)&.as_complement_of(self) }.compact
34
36
  end
35
37
 
@@ -39,15 +41,6 @@ class Book < Content
39
41
  complements: complements.map(&:slug))
40
42
  end
41
43
 
42
- def rebuild_complements!(complements) #FIXME use rebuild
43
- transaction do
44
- self.complements.all_except(complements).delete_all
45
- self.update! :complements => complements
46
- complements.each &:save!
47
- end
48
- reload
49
- end
50
-
51
44
  def index_usage!(organization)
52
45
  organization.index_usage_of! self, self
53
46
  [chapters, complements].flatten.each { |item| item.index_usage! organization }
@@ -1,5 +1,6 @@
1
1
  module GuideContainer
2
2
  extend ActiveSupport::Concern
3
+ include WithContent
3
4
 
4
5
  included do
5
6
  validates_presence_of :guide
@@ -0,0 +1,13 @@
1
+ module WithContent
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_destroy :destroy_usages!
6
+ end
7
+
8
+ private
9
+
10
+ def destroy_usages!
11
+ Usage.destroy_usages_for self
12
+ end
13
+ end
@@ -16,6 +16,21 @@ module WithUsages
16
16
  item.is_a?(type) ? item : nil
17
17
  end
18
18
 
19
+ class_methods do
20
+ def aggregate_of(association)
21
+ super
22
+
23
+ revamp "rebuild_#{association}!" do |_, this, children, hyper|
24
+ old_children = this.send association
25
+ added_children = children - old_children
26
+ hyper.(children)
27
+ this.usages.each { |it| it.index_children!(added_children) }
28
+
29
+ this
30
+ end
31
+ end
32
+ end
33
+
19
34
  private
20
35
 
21
36
  def ensure_unused!
@@ -108,7 +108,7 @@ class Exercise < ApplicationRecord
108
108
  end
109
109
 
110
110
  def choice_values
111
- self[:choice_values].presence || choices.map { |it| it.indifferent_get(:value) }
111
+ choices.map { |it| it.indifferent_get(:value) }
112
112
  end
113
113
 
114
114
  def choice_index_for(value)
data/app/models/guide.rb CHANGED
@@ -19,6 +19,8 @@ class Guide < Content
19
19
 
20
20
  enum type: [:learning, :practice]
21
21
 
22
+ alias_method :children, :exercises
23
+
22
24
  def clear_progress!(user, organization=Organization.current)
23
25
  transaction do
24
26
  exercises.each do |exercise|
data/app/models/topic.rb CHANGED
@@ -9,7 +9,7 @@ class Topic < Content
9
9
 
10
10
  markdown_on :appendix
11
11
 
12
- after_save :reindex_usages!
12
+ alias_method :children, :guides
13
13
 
14
14
  def pending_lessons(user)
15
15
  guides.
@@ -30,7 +30,7 @@ class Topic < Content
30
30
  def import_from_resource_h!(resource_h)
31
31
  self.assign_attributes resource_h.except(:lessons, :description)
32
32
  self.description = resource_h[:description].squeeze(' ')
33
- rebuild! resource_h[:lessons].to_a.map { |it| lesson_for(it) }
33
+ rebuild_lessons! resource_h[:lessons].to_a.map { |it| lesson_for(it) }
34
34
  end
35
35
 
36
36
  def to_expanded_resource_h
@@ -1,5 +1,7 @@
1
1
  module TopicContainer
2
2
  extend ActiveSupport::Concern
3
+ include WithContent
4
+
3
5
  included do
4
6
  validates_presence_of :topic
5
7
 
@@ -10,7 +12,7 @@ module TopicContainer
10
12
  :description,
11
13
  :description_html,
12
14
  :description_teaser_html,
13
- :rebuild!,
15
+ :rebuild_lessons!,
14
16
  :lessons,
15
17
  :guides,
16
18
  :pending_guides,
data/app/models/usage.rb CHANGED
@@ -7,9 +7,22 @@ class Usage < ApplicationRecord
7
7
  scope :in_organization, ->(organization = Organization.current) { where(organization_id: organization.id) }
8
8
 
9
9
  before_save :set_slug
10
+ before_destroy :destroy_children_usages!
11
+
12
+ def self.destroy_all_where(query)
13
+ where(query).destroy_all
14
+ end
10
15
 
11
16
  def self.destroy_usages_for(record)
12
- Usage.where(parent_item: record).destroy_all
17
+ destroy_all_where(parent_item: record)
18
+ end
19
+
20
+ def destroy_children_usages!
21
+ item.children.each { |child| Usage.destroy_all_where(item: child, organization: organization) }
22
+ end
23
+
24
+ def index_children!(children)
25
+ children.each { |it| it.index_usage! organization }
13
26
  end
14
27
 
15
28
  private
@@ -0,0 +1,5 @@
1
+ class RemoveChoiceValuesFromExercises < ActiveRecord::Migration[5.1]
2
+ def change
3
+ remove_column :exercises, :choice_values, :string, array: true, default: [], null: false
4
+ end
5
+ end
@@ -65,6 +65,10 @@ FactoryBot.define do
65
65
 
66
66
  factory :exercise, parent: :problem
67
67
 
68
+ factory :indexed_exercise, parent: :exercise do
69
+ guide { create(:indexed_guide) }
70
+ end
71
+
68
72
  factory :x_equal_5_exercise, parent: :exercise do
69
73
  test { 'describe "x" $ do
70
74
  it "should be equal 5" $ do
@@ -27,4 +27,11 @@ FactoryBot.define do
27
27
  end
28
28
  end
29
29
 
30
+ factory :indexed_guide, parent: :guide do
31
+ after(:build) do |guide|
32
+ create(:lesson, guide: guide, topic: create(:indexed_topic))
33
+
34
+ reindex_current_organization!
35
+ end
36
+ end
30
37
  end
@@ -6,4 +6,10 @@ FactoryBot.define do
6
6
  slug { "mumuki/mumuki-sample-topic-#{SecureRandom.uuid}" }
7
7
  locale { :en }
8
8
  end
9
+
10
+ factory :indexed_topic, parent: :topic do
11
+ after(:build) do |topic|
12
+ create(:chapter, topic: topic)
13
+ end
14
+ end
9
15
  end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '7.0.6'
3
+ VERSION = '7.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-domain
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.6
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-09 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -265,6 +265,7 @@ files:
265
265
  - app/models/concerns/submittable/triable.rb
266
266
  - app/models/concerns/with_assignments.rb
267
267
  - app/models/concerns/with_case_insensitive_search.rb
268
+ - app/models/concerns/with_content.rb
268
269
  - app/models/concerns/with_description.rb
269
270
  - app/models/concerns/with_discussion_creation.rb
270
271
  - app/models/concerns/with_discussion_creation/subscription.rb
@@ -587,6 +588,7 @@ files:
587
588
  - db/migrate/20190918134321_remove_new_expectations.rb
588
589
  - db/migrate/20190918140026_add_custom_expectations.rb
589
590
  - db/migrate/20190929180601_add_expectations_to_language.rb
591
+ - db/migrate/20191022180238_remove_choice_values_from_exercises.rb
590
592
  - lib/mumuki/domain.rb
591
593
  - lib/mumuki/domain/engine.rb
592
594
  - lib/mumuki/domain/evaluation.rb