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, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!

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

Instance Method Details

#assets_urls_for(kind, content_type) ⇒ Object



80
81
82
# File 'app/models/language.rb', line 80

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



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

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

#directives_comment_typeObject



76
77
78
# File 'app/models/language.rb', line 76

def directives_comment_type
  Mumukit::Directives::CommentType.parse comment_type
end

#directives_interpolationsObject



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

def directives_interpolations
  new_directive Mumukit::Directives::Interpolations
end

#directives_sectionsObject



64
65
66
# File 'app/models/language.rb', line 64

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!Object



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

def import!
  import_from_json! bridge.importable_info
end

#import_from_json!(json) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/language.rb', line 42

def import_from_json!(json)

  assign_attributes json.slice(:name,
                               :comment_type,
                               :output_content_type,
                               :prompt,
                               :extension,
                               :highlight_mode,
                               :visible_success_output,
                               :devicon,
                               :triable,
                               :queriable,
                               :stateful_console,
                               :layout_js_urls,
                               :layout_html_urls,
                               :layout_css_urls,
                               :editor_js_urls,
                               :editor_html_urls,
                               :editor_css_urls)
  save!
end

#interpolate(interpolee, *interpolations) ⇒ Object



68
69
70
# File 'app/models/language.rb', line 68

def interpolate(interpolee, *interpolations)
  interpolations.inject(interpolee) { |content, interpolation| directives_interpolations.interpolate(content, interpolation).first }
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

#to_sObject



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

def to_s
  name
end