Class: Language

Inherits:
ApplicationRecord show all
Includes:
WithCaseInsensitiveSearch
Defined in:
app/models/language.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, numbered, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes

Class Method Details

.for_name(name) ⇒ Object



30
31
32
# File 'app/models/language.rb', line 30

def self.for_name(name)
  find_by_ignore_case!(:name, name) if name
end

.locate_resource(runner_url) ⇒ Object



62
63
64
# File 'app/models/language.rb', line 62

def self.locate_resource(runner_url)
  find_or_initialize_by(runner_url: runner_url).tap { |it| it.save(validate: false) }
end

Instance Method Details

#assets_urls_for(kind, content_type) ⇒ Object



52
53
54
# File 'app/models/language.rb', line 52

def assets_urls_for(kind, content_type)
  send "#{kind}_#{content_type}_urls"
end

#bridgeObject



14
15
16
# File 'app/models/language.rb', line 14

def bridge
  Mumukit::Bridge::Runner.new(runner_url)
end

#deviconObject



34
35
36
# File 'app/models/language.rb', line 34

def devicon
  self[:devicon] || name.downcase
end

#directives_sectionsObject



47
48
49
# File 'app/models/language.rb', line 47

def directives_sections
  new_directive Mumukit::Directives::Sections
end

#highlight_modeObject



18
19
20
# File 'app/models/language.rb', line 18

def highlight_mode
  self[:highlight_mode] || name
end

#import_from_resource_h!(resource_h) ⇒ Object



42
43
44
45
# File 'app/models/language.rb', line 42

def import_from_resource_h!(resource_h)
  assign_attributes resource_h.except(:runner_url)
  save!
end

#interpolate_references_for(assignment, field) ⇒ Object

TODO this should be a Mumukit::Directives::Directive and be part of a pipeline



58
59
60
# File 'app/models/language.rb', line 58

def interpolate_references_for(assignment, field)
  interpolate(field, assignment.submitter.interpolations, lambda { |content| replace_content_reference(assignment, content) })
end

#output_content_typeObject



22
23
24
# File 'app/models/language.rb', line 22

def output_content_type
  Mumukit::ContentType.for(self[:output_content_type])
end

#sync_keyObject



38
39
40
# File 'app/models/language.rb', line 38

def sync_key
  Mumukit::Sync.key :language, runner_url
end

#to_embedded_resource_hObject



66
67
68
# File 'app/models/language.rb', line 66

def to_embedded_resource_h
  as_json(only: [:name, :extension, :test_extension]).symbolize_keys
end

#to_resource_hObject



70
71
72
73
74
75
# File 'app/models/language.rb', line 70

def to_resource_h
  as_json(only: %i(comment_type devicon editor_css_urls editor_html_urls editor_js_urls
                  extension feedback highlight_mode layout_css_urls layout_html_urls
                  layout_js_urls name output_content_type prompt queriable runner_url
                  stateful_console test_extension test_template triable visible_success_output)).symbolize_keys
end

#to_sObject



26
27
28
# File 'app/models/language.rb', line 26

def to_s
  name
end