Sha256: b449ceba9209fb8d499b7cfe22b06465000c27bb8c28d2f7d93e92ea00fa3497
Contents?: true
Size: 1.91 KB
Versions: 193
Compression:
Stored size: 1.91 KB
Contents
module Trackler class GuaranteedFile attr_accessor :content def self.for(specification:, track:, filename:) [TrackFile, CommonFile].detect(-> {NullFile}) do |d| d.send(:exists?, specification: specification, track: track, filename: filename) end.send(:new, specification: specification, track: track, filename: filename) end private attr_accessor :track, :filename, :specification def self.exists?(specification:, track:, filename:) File.exist?(location(specification: specification, track: track, filename: filename)) end private_class_method :exists? def initialize(specification:, track:, filename:) self.specification = specification self.track = track self.filename = filename self.content = File.read(self.class.location(specification: specification, track: track, filename: filename)) end private_class_method :new end class TrackFile < GuaranteedFile def self.location(specification:, track:, filename:) File.join(specification.root, 'tracks', track.id, 'exercises', specification.slug, '.meta', filename) end def url "#{track.repository}/blob/master/exercises/%s/.meta/#{filename}" % specification.slug end end class CommonFile < GuaranteedFile def self.location(specification:, filename:, **_track) File.join(specification.root, 'problem-specifications', 'exercises', specification.slug, filename) end def url "https://github.com/exercism/problem-specifications/blob/master/exercises/%s/#{filename}" % specification.slug end end class NullFile < GuaranteedFile def method_missing(*) # NOOP end def respond_to?(*) true end def inspect "<null>" end def exists? false end def content "" end def initialize(*) self end klass = self define_method(:class) { klass } end end
Version data entries
193 entries across 193 versions & 1 rubygems