Sha256: 628fff0dc4eeeaff1b79038fa5fc9ef062ebcca22b64e34c1d5746b51a9103c1

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

require "fileutils"
require "active_support/core_ext/hash"

Dir["#{File.dirname(__FILE__)}/rambo/**/*.rb"].each {|file| require file }

module Rambo
  class << self
    attr_reader :options, :file

    def generate_contract_tests!(file: nil, options: {})
      @options         = yaml_options.merge(options)
      @options[:rails] = true unless @options.fetch(:rails, nil) == false
      @file            = file || @options.delete(:raml) || raml_file

      DocumentGenerator.generate!(@file, @options)
    end

    private

    def yaml_options
      opts = YAML.load(File.read(File.join(FileUtils.pwd, ".rambo.yml"))).symbolize_keys

      if opts && opts.fetch(:raml, nil)
        opts[:raml] = File.join(FileUtils.pwd, opts.fetch(:raml))
      end

      opts || {}
    rescue
      { rails: true }
    end

    # TODO: Permit use of multiple RAML files, since right now this only takes
    #       the first one it finds in the "doc" directory.

    def raml_file
      return options.fetch(:raml) if options && options.fetch(:raml, nil)

      raml_path = File.join(FileUtils.pwd, "doc", "raml")
      Dir.foreach(raml_path) {|file| return File.join(raml_path, file) if file.match(/\.raml$/) }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rambo_ruby-0.5.0 lib/rambo.rb
rambo_ruby-0.4.0 lib/rambo.rb
rambo_ruby-0.3.3 lib/rambo.rb
rambo_ruby-0.3.2 lib/rambo.rb
rambo_ruby-0.3.1 lib/rambo.rb
rambo_ruby-0.3.0 lib/rambo.rb