Sha256: 61d5defbf58cb7439a13099f79ef98071a2b81200a4d4d34404a3022639af38e

Contents?: true

Size: 1.4 KB

Versions: 17

Compression:

Stored size: 1.4 KB

Contents

require 'json'

module Generator
  # Contains methods accessible to the ERB template
  class TemplateValues
    attr_reader :abbreviated_commit_hash, :version, :exercise_name, :test_cases, :canonical_data_version

    def initialize(abbreviated_commit_hash:, version:, exercise_name:, test_cases:, canonical_data_version: nil)
      @abbreviated_commit_hash = abbreviated_commit_hash
      @version = version
      @exercise_name = exercise_name
      @test_cases = test_cases
      @canonical_data_version = canonical_data_version
    end

    def get_binding
      binding
    end

    def exercise_name_camel
      exercise_name.split('_').map(&:capitalize).join
    end
  end

  module TemplateValuesFactory
    def template_values
      TemplateValues.new(
        abbreviated_commit_hash: canonical_data.abbreviated_commit_hash,
        canonical_data_version: canonical_data.version,
        version: version,
        exercise_name: slug_underscore,
        test_cases: extract
      )
    end

    private

    def slug_underscore
      slug ? slug.tr('-_', '_') : ''
    end

    def extract
      load cases_load_name
      extractor.cases(canonical_data.to_s)
    end

    def extractor
        CaseValues::Extractor.new(
          case_class: Object.const_get(Files::GeneratorCases.class_name(slug))
        )
    end

    def cases_load_name
      Files::GeneratorCases.source_filepath(paths.track, slug)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
trackler-2.1.0.36 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.34 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.33 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.32 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.31 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.30 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.29 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.28 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.27 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.26 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.25 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.24 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.23 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.22 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.21 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.20 tracks/ruby/lib/generator/template_values.rb
trackler-2.1.0.19 tracks/ruby/lib/generator/template_values.rb