Skip to content

Commit

Permalink
Merge pull request #1 from lowjoel/language-definitions
Browse files Browse the repository at this point in the history
Import the language definitions from the Web application.
  • Loading branch information
WANG QIANG committed Jan 13, 2016
2 parents 0adb159 + fd6c9ed commit 61d91cc
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Ignore bundler config and gems.
/.bundle
/vendor/bundle
/Gemfile.lock

# Ignore generated code coverage information
/spec/coverage/*
Expand Down
2 changes: 2 additions & 0 deletions coursemology-polyglot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ programming languages supported in Coursemology.
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'codeclimate-test-reporter'

spec.add_dependency 'activesupport', '~> 4.2.0', '>= 4.2.2'
end
14 changes: 11 additions & 3 deletions lib/coursemology/polyglot.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
require 'active_support/all'
require 'coursemology/polyglot/version'

module Coursemology
module Polyglot
# Your code goes here...
module Coursemology::Polyglot
extend ActiveSupport::Autoload

eager_autoload do
autoload :Language
end

def self.eager_load!
super
Coursemology::Polyglot::Language.eager_load!
end
end
45 changes: 45 additions & 0 deletions lib/coursemology/polyglot/language.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
if defined?(ActiveRecord)
# :nocov:
# TODO: This is for compatibility with the Web application. A future refactoring might be able
# to remove this dependency.
class Coursemology::Polyglot::Language < ActiveRecord::Base; end
# :nocov:
else
class Coursemology::Polyglot::Language; end
end

class Coursemology::Polyglot::Language
extend ActiveSupport::Autoload

eager_autoload do
autoload :Python
end

# Gets the display name of the language.
#
# @abstract
# @return [String]
def self.display_name
fail NotImplementedError
end

# The stylesheets that need to be packaged with the rest of the application.
#
# This should include the Rouge/Pygments stylesheet for formatting code.
#
# @abstract
# @return [Array<String>]
def self.stylesheets
fail NotImplementedError
end

# The script files that need to be packaged with the rest of the application.
#
# This should include the Ace mode for the language.
#
# @abstract
# @return [Array<String>]
def self.javascript
fail NotImplementedError
end
end
17 changes: 17 additions & 0 deletions lib/coursemology/polyglot/language/python.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Coursemology::Polyglot::Language::Python < Coursemology::Polyglot::Language
class Python2Point7 < Coursemology::Polyglot::Language::Python
class << self
def display_name
'Python 2.7'
end
end
end

class Python3Point4 < Coursemology::Polyglot::Language::Python
class << self
def display_name
'Python 3.4'
end
end
end
end
15 changes: 15 additions & 0 deletions spec/coursemology/polyglot/language/python_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

RSpec.describe Coursemology::Polyglot::Language::Python do
describe Coursemology::Polyglot::Language::Python::Python2Point7 do
it 'returns the correct display name' do
expect(subject.class.display_name).to eq('Python 2.7')
end
end

describe Coursemology::Polyglot::Language::Python::Python3Point4 do
it 'returns the correct display name' do
expect(subject.class.display_name).to eq('Python 3.4')
end
end
end
21 changes: 21 additions & 0 deletions spec/coursemology/polyglot/language_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

RSpec.describe Coursemology::Polyglot::Language do
describe '.display_name' do
it 'fails with NotImplementedError' do
expect { subject.class.display_name }.to raise_error(NotImplementedError)
end
end

describe '.stylesheets' do
it 'fails with NotImplementedError' do
expect { subject.class.stylesheets }.to raise_error(NotImplementedError)
end
end

describe '.javascript' do
it 'fails with NotImplementedError' do
expect { subject.class.javascript }.to raise_error(NotImplementedError)
end
end
end
4 changes: 0 additions & 4 deletions spec/coursemology/polyglot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
it 'has a version number' do
expect(Coursemology::Polyglot::VERSION).not_to be nil
end

it 'does something useful' do
expect(false).to eq(true)
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed

config.before(:suite) do
Coursemology::Polyglot.eager_load!
end
end

0 comments on commit 61d91cc

Please sign in to comment.