coursemology-polyglot 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41fbf94d1e17c8f4c04396345c1bf4b8df6dc7c2
4
- data.tar.gz: 238a558ddd5e82c4135934ddd877ce62b0384056
3
+ metadata.gz: adb65659222b8379e474afaf85155592557f66fc
4
+ data.tar.gz: bc9932cd23bdb2e9fa8c361abe45d2123f243101
5
5
  SHA512:
6
- metadata.gz: bf23bb01e21f1331ee554b3ae444305b4d65e9d5312c0f60e9558c442dee3df4a0c2a072590a7b23945be02f86eaf749da115fa23cc2804034d2149d266075ba
7
- data.tar.gz: ed9d45a66456363884fa16db6534d488eeeb3717b9ccea6cbd427ade6f21353c922124001313953df76ad9ea9f682fd225a5ee3f0389ad94d0111c4fffb55618
6
+ metadata.gz: b3fe16093ab865f4b64f6e7dadc8c5682e2c538db4f33e24526444844ef223b725637d67b367b16971565fdf57864c7a6a1faebc1986c58880e0fb176db74c9f
7
+ data.tar.gz: afa94849bd67f275640ba7cdd47bb190a9e85275933306dea4108e88a860eed53484ff4127eb5a003a7cec45b174cc3685daa22351ec9e3b9aff18798132c7a4
@@ -4,4 +4,26 @@
4
4
  # This is deliberately defined so that consumers of this library can inject methods into all
5
5
  # concrete languages' classes.
6
6
  module Coursemology::Polyglot::ConcreteLanguage::ClassMethods
7
+ # The default algorithm for translating a language to a corresponding Docker image name.
8
+ #
9
+ # This will:
10
+ # 1. Strip the +Coursemology::Polyglot::Language+ prefix.
11
+ # 2. Underscore the name.
12
+ # 3. Replace *n*Point*n* strings with dots (e.g. Python2Point7 to Python2.7).
13
+ # 4. Replace slashes with dashes.
14
+ def docker_image
15
+ # Remove the Coursemology::Polyglot::Language prefix
16
+ class_name = name
17
+ class_name = class_name.sub(/^Coursemology::Polyglot::Language::/, '')
18
+
19
+ # Use the underscored name
20
+ class_name = class_name.underscore
21
+
22
+ # Replace the "_point" string with a decimal
23
+ class_name.gsub!(/(?<=[\d])_point(?=[\d])/, '.')
24
+
25
+ # Replace slashes with dashes
26
+ class_name.tr!('/', '-')
27
+ class_name
28
+ end
7
29
  end
@@ -32,14 +32,15 @@ class Coursemology::Polyglot::Language
32
32
  # Concrete languages can be instantiated and used.
33
33
  #
34
34
  # @param [String] display_name The display name for the language
35
- def self.concrete_language(display_name)
35
+ # @param [String] docker_image The Docker image to use for the given language. This defaults to
36
+ # the string generated by +Coursemology::Polyglot::ConcreteLanguage.docker_image+.
37
+ def self.concrete_language(display_name, docker_image: nil)
36
38
  include Coursemology::Polyglot::ConcreteLanguage
37
39
  extend Coursemology::Polyglot::ConcreteLanguage::ClassMethods
38
40
 
39
41
  concrete_class_methods = Module.new do
40
- define_method(:display_name) do
41
- display_name
42
- end
42
+ define_method(:display_name) { display_name }
43
+ define_method(:docker_image) { docker_image } if docker_image
43
44
  end
44
45
 
45
46
  extend concrete_class_methods
@@ -1,9 +1,9 @@
1
1
  class Coursemology::Polyglot::Language::Python < Coursemology::Polyglot::Language
2
2
  class Python2Point7 < Coursemology::Polyglot::Language::Python
3
- concrete_language 'Python 2.7'
3
+ concrete_language 'Python 2.7', docker_image: 'python:2.7'
4
4
  end
5
5
 
6
6
  class Python3Point4 < Coursemology::Polyglot::Language::Python
7
- concrete_language 'Python 3.4'
7
+ concrete_language 'Python 3.4', docker_image: 'python:3.4'
8
8
  end
9
9
  end
@@ -1,4 +1,4 @@
1
1
  module Coursemology; end
2
2
  module Coursemology::Polyglot
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coursemology-polyglot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Low
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler