Class: Spectro::Compiler
- Inherits:
-
Object
- Object
- Spectro::Compiler
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/spectro/compiler.rb
Overview
Spectro::Compiler is in charge of scan the projects and parse its files, updating the Spectroi’s index and dumping information about the missing implementations (specs without an associated lambda)
Instance Method Summary collapse
-
#compile ⇒ Spectro::Compiler
Filters the project files keeping those that make use of Spectro.
-
#init(options = {}) ⇒ Spectro::Compiler
Init the current folder as an Spectro project, creating all the required files and folders ‘.spectro` confg file `.spectro/index.yml` which will hold the mappings between Files/Method names and defined lambdas `.spectro/undefined.yml` which will hold the collection of spec definitions not yet fulfilled `.spectro/cache` folder that will hold the source code of the retrieved lambdas.
Instance Method Details
#compile ⇒ Spectro::Compiler
Filters the project files keeping those that make use of Spectro. It then parses them, check for missing implementations and creates an .spectro/undefined.yml with their specs.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spectro/compiler.rb', line 24 def compile if !Dir.exist?('.spectro') abort "\n" + "This folder has not been initialzed as an Spectro project. Please run ".white.on_red + " spectro init ".white.on_light_black + " before compiling.".white.on_red + "\n\n" end undefined_yaml = YAML::Store.new(".spectro/undefined.yml") undefined_yaml.transaction do targets().map do |path| missing_specs = missing_specs_from_file(path) next if missing_specs.empty? undefined_yaml[path] = missing_specs end end return self end |
#init(options = {}) ⇒ Spectro::Compiler
Init the current folder as an Spectro project, creating all the required files and folders ‘.spectro` confg file `.spectro/index.yml` which will hold the mappings between Files/Method names and defined lambdas `.spectro/undefined.yml` which will hold the collection of spec definitions not yet fulfilled `.spectro/cache` folder that will hold the source code of the retrieved lambdas
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/spectro/compiler.rb', line 50 def init ={} if File.exist?('.spectro/config') && ![:f] abort "\n" + "Project already initialized. If you want to reset the curret setup you can run ".black.on_yellow + " spectro init -f ".white.on_light_black + "\n\n" end Dir.exist?('.spectro') || Dir.mkdir('.spectro') Dir.exist?('.spectro/cache') || Dir.mkdir('.spectro/cache') File.open('.spectro/config', 'w') do |file| file.write <<-CONFIG #!/usr/bin/env ruby Spectro.configure do |config| # Sets a custom API Hostname if needed # config.api_hostname = 'localhost:9292' # # Instead of failing in case of unfulfilled functions it will try to use the local specs to get a result # config.enable_mocks! end CONFIG end File.open('.spectro/index.yml', 'w') do |file| end File.open('.spectro/undefined.yml', 'w') do |file| end puts "\n" + "The project has been successfully initialized".black.on_blue + "\n\n" return self end |