lib/trackler/implementation.rb in trackler-2.1.0.18 vs lib/trackler/implementation.rb in trackler-2.1.0.19
- old
+ new
@@ -1,6 +1,7 @@
require 'pathname'
+require 'forwardable'
require_relative 'file_bundle'
module Trackler
# Implementation is a language-specific implementation of an exercise.
class Implementation
@@ -8,20 +9,28 @@
"\/HINTS\.md$",
"\/\.$",
"/\.meta/"
]
- attr_reader :track, :problem
+ extend Forwardable
+ def_delegators :@problem, :name, :blurb, :description, :source_markdown, :slug, :source, :metadata, :root, :active?, :deprecated?, :source_url, :description_url, :canonical_data_url, :metadata_url
+
def initialize(track, problem)
@track = track
@problem = problem
end
- def file_bundle
- @file_bundle ||= FileBundle.new(implementation_dir, regexes_to_ignore)
+ def initialize_copy(original)
+ super
+ @files = original.files.dup
end
+ def problem
+ warn "DEPRECATION WARNING: The `problem` method is deprecated, Implementation can do everything that Problem can, so call the method directly."
+ @problem
+ end
+
def exists?
File.exist?(implementation_dir)
end
def files
@@ -61,73 +70,58 @@
track.id
end
private
+ attr_reader :track
+
def regexes_to_ignore
- (IGNORE_PATTERNS + [@track.ignore_pattern]).map do |pattern|
+ (IGNORE_PATTERNS + [track.ignore_pattern]).map do |pattern|
Regexp.new(pattern, Regexp::IGNORECASE)
end
end
+ def file_bundle
+ @file_bundle ||= FileBundle.new(implementation_dir, regexes_to_ignore)
+ end
+
def implementation_dir
@implementation_dir ||= track.dir.join(exercise_dir)
end
def exercise_dir
- if File.exist?(track.dir.join('exercises'))
- File.join('exercises', problem.slug)
- else
- problem.slug
- end
+ File.join('exercises', slug)
end
def assemble_readme
<<-README
-# #{readme_title}
+# #{name}
-#{problem.blurb}
-
#{readme_body}
-#{readme_source}
+#{source_markdown}
#{incomplete_solutions_body}
README
end
- def readme_title
- problem.name
- end
-
def readme_body
- [
- problem.description,
- implementation_hints,
- track.hints,
- ].reject(&:empty?).join("\n").strip
+ [
+ description,
+ implementation_hints,
+ track.hints,
+ ].reject(&:empty?).join("\n").strip
end
- def readme_source
- problem.source_markdown
- end
-
def incomplete_solutions_body
<<-README
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
README
end
def implementation_hints
- read File.join(implementation_dir, 'HINTS.md')
- end
-
- def read(f)
- if File.exist?(f)
- File.read(f)
- else
- ""
- end
+ hints_file = File.join(implementation_dir, 'HINTS.md')
+ File.exist?(hints_file) ? File.read(hints_file) : ''
end
end
end