clairvoyant 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6b1d12fb5093c1e52b52d28d35f0e82844cb5a8
4
- data.tar.gz: 8eb2d246196c422555d4c72f0662d566eff12779
3
+ metadata.gz: 2a318ff0f912c23bd9f489aedaf96fccdd3340f4
4
+ data.tar.gz: a87c1748b49afee8c2a829bed91590211198336d
5
5
  SHA512:
6
- metadata.gz: 2383a4985918c51e7fa7d0ac7f31e6f37ca5d8685ec126664bd2ee4eb17cd550169f21772ca24fa787830c69b1b71aa6e74a6fa3fa305c711ac879ba4f595ba9
7
- data.tar.gz: c3504330ca0dc2eafab5685604063e4db7b21d58390198126fa26a9eb397327aaf47c803def2e004942b016cf08b985b87c3ffdd3b96930a570e8243b257d9f1
6
+ metadata.gz: 7790fd8f1fe37b8dce32f487eedced7736d322993025777461c1d815434e81bc8abf4a256e99ac27bfa9af162971440d1bdc99e0a4c70783eb9d47487d213a7e
7
+ data.tar.gz: b5050a033bf01a1ce43b1f18a03547adcdd79cc63d4a8949b541dc72db35c4ebfd9d1efa177b2c625761b74095bf28dba29090cba236f33c83d08e0da20c66ed
data/README.md CHANGED
@@ -1,28 +1,72 @@
1
1
  # Clairvoyant
2
2
 
3
- TODO: Write a gem description
3
+ ## SUPER ALPHA
4
4
 
5
- ## Installation
5
+ This is not meant to be used for anything serious at this point. It will at least give you a skeleton for your
6
+ code but not much beyond that at this point. You've been warned.
6
7
 
7
- Add this line to your application's Gemfile:
8
+ ## What is it? (Theoretical)
8
9
 
9
- gem 'clairvoyant'
10
+ Divine what code should be written to make a suite of tests pass.
10
11
 
11
- And then execute:
12
+ Test code is extremely close to actual code, and a lot of inferences can be made about the nature of the code that would be generated in order to fulfil the tests.
12
13
 
13
- $ bundle
14
+ By parsing RSPEC with a secondary DSL, we can formulate an Abstract Syntax Tree from the tests that can be reasonably mapped to working Ruby code.
14
15
 
15
- Or install it yourself as:
16
+ ## Abstract
16
17
 
17
- $ gem install clairvoyant
18
+ ```
19
+ describe Person do
20
+ let(:person) { Person.new('brandon', 23) }
21
+
22
+ describe '#name' do
23
+ expect(person.name).to eq('brandon')
24
+ end
25
+
26
+ describe '#age' do
27
+ expect(person.age).to eq(23)
28
+ end
29
+ end
30
+ ```
31
+
32
+ ...would map to the AST:
33
+ ```ruby
34
+ {
35
+ person: {
36
+ name: string,
37
+ age: integer
38
+ }
39
+ }
40
+ ```
41
+
42
+ ...and can be converted to:
43
+ ```ruby
44
+ class Person
45
+ attr_accessor :name, :age
46
+
47
+ def initialize(name, age)
48
+ @name = name
49
+ @age = age
50
+ end
51
+ end
52
+ ```
53
+
54
+ This is merely an abstract and requires a lot of work though.
18
55
 
19
56
  ## Usage
20
57
 
21
- TODO: Write usage instructions here
58
+ Currently it will only work with very basic RSPEC files. This will be tested against later.
59
+
60
+ ```ruby
61
+ builder = Clairvoyant.grok('path/to/rspec/file.rb')
62
+
63
+ # And there's your class!
64
+ puts builder
65
+ ```
22
66
 
23
67
  ## Contributing
24
68
 
25
- 1. Fork it ( http://github.com/<my-github-username>/clairvoyant/fork )
69
+ 1. Fork it ( http://github.com/baweaver/clairvoyant/fork )
26
70
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
71
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
72
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,5 +1,49 @@
1
1
  require "clairvoyant/version"
2
2
 
3
+ require 'clairvoyant/indentable'
4
+
5
+ require 'clairvoyant/builder'
6
+ require 'clairvoyant/method'
7
+
3
8
  module Clairvoyant
4
- # Your code goes here...
9
+ class << self
10
+ # RSPEC describe parser
11
+ #
12
+ # @param description [String] - What we're describing
13
+ #
14
+ # @return [type] [description]
15
+ def describe(description, &block)
16
+ @builder.klass_name ||= description if description.is_a?(Symbol)
17
+ @builder.add_method(description) if description[0] == '#'
18
+ block.call rescue nil
19
+ end
20
+
21
+ # Catch missing constants so we don't hav obscure rescues throughout the
22
+ # code
23
+ #
24
+ # @param name [Symbol] - Name of the undefined constant that was caught
25
+ #
26
+ # @return [Symbol]
27
+ def const_missing(name)
28
+ name
29
+ end
30
+
31
+ # Parses a file into a builder
32
+ #
33
+ # @param file_name [String] - Path to the file
34
+ #
35
+ # @return [Clairvoyant::Builder]
36
+ def grok(file_name)
37
+ cleaned_lines =
38
+ File
39
+ .open(file_name, 'r')
40
+ .drop_while { |line| !line.include?('describe') }.join("\n")
41
+
42
+ @builder = Clairvoyant::Builder.new
43
+
44
+ self.class_eval cleaned_lines
45
+
46
+ @builder
47
+ end
48
+ end
5
49
  end
@@ -0,0 +1,61 @@
1
+ module Clairvoyant
2
+ # Used to build up Clairvoyant generated classes
3
+ #
4
+ # @author [lemur]
5
+ class Builder
6
+ include Indentable
7
+
8
+ attr_accessor :klass_name
9
+
10
+ def initialize(klass_name: nil, indent_size: 2)
11
+ @klass_name = klass_name
12
+ @indent_size = indent_size
13
+ @klass_methods = []
14
+ end
15
+
16
+ # Used to format the klass.
17
+ #
18
+ # @note I don't like the way this is written, clean later
19
+ #
20
+ # @return [Proc]
21
+ def klass
22
+ -> method_string {
23
+ "class #{@klass_name}\n" << method_string.rstrip << "\nend"
24
+ }
25
+ end
26
+
27
+ # Adds a method to the builder
28
+ #
29
+ # @param name [String] - Name of the method
30
+ #
31
+ # @return [Array[Clairvoyant::Method]] - Current methods
32
+ def add_method(name)
33
+ @klass_methods << Method.new(name: name[1..-1])
34
+ end
35
+
36
+ # Composes a Ruby Class from the builder
37
+ #
38
+ # @return [String] - Saveable and Runnable Ruby Class
39
+ def compose_klass
40
+ klass.call @klass_methods.reduce('') { |method_string, method|
41
+ method_string << "#{method}\n\n"
42
+ }
43
+ end
44
+
45
+ # Alias for compose_klass
46
+ #
47
+ # @return [String]
48
+ def to_s
49
+ compose_klass
50
+ end
51
+
52
+ # Saves the generated class as a file
53
+ #
54
+ # @param path [String] - Where to save
55
+ #
56
+ # @return [Unit]
57
+ def save_as(path)
58
+ File.open(path, 'w') { |file| file << compose_klass }
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ module Clairvoyant
2
+ module Indentable
3
+ # Generates spacing for indentation
4
+ #
5
+ # @param times = 1 [Integer] - Number of indents to render
6
+ #
7
+ # @return [String]
8
+ def indent(times = 1)
9
+ ' ' * (@indentation * times)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module Clairvoyant
2
+ class Method
3
+ include Indentable
4
+
5
+ attr_reader :name
6
+
7
+ def initialize(name:, indentation: 2)
8
+ @name = name
9
+ @indentation = indentation
10
+ end
11
+
12
+ # Formats a method as a ruby method
13
+ #
14
+ # @return [String]
15
+ def to_s
16
+ "#{indent(1)}def #{name}\n" <<
17
+ "#{indent(2)}# Code here later\n" <<
18
+ "#{indent(1)}end"
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Clairvoyant
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -0,0 +1,9 @@
1
+ describe Foo do
2
+ describe '#bar' do
3
+ 1
4
+ end
5
+
6
+ describe '#baz' do
7
+ 5
8
+ end
9
+ end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clairvoyant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-11 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Attempts to divine what code will make tests pass
@@ -45,14 +45,18 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
51
51
  - README.md
52
52
  - Rakefile
53
53
  - clairvoyant.gemspec
54
54
  - lib/clairvoyant.rb
55
+ - lib/clairvoyant/builder.rb
56
+ - lib/clairvoyant/indentable.rb
57
+ - lib/clairvoyant/method.rb
55
58
  - lib/clairvoyant/version.rb
59
+ - spec/fixtures/basic_rspec.rb
56
60
  homepage: https://www.github.com/baweaver/clairvoyant
57
61
  licenses:
58
62
  - MIT
@@ -63,19 +67,19 @@ require_paths:
63
67
  - lib
64
68
  required_ruby_version: !ruby/object:Gem::Requirement
65
69
  requirements:
66
- - - '>='
70
+ - - ">="
67
71
  - !ruby/object:Gem::Version
68
72
  version: '0'
69
73
  required_rubygems_version: !ruby/object:Gem::Requirement
70
74
  requirements:
71
- - - '>='
75
+ - - ">="
72
76
  - !ruby/object:Gem::Version
73
77
  version: '0'
74
78
  requirements: []
75
79
  rubyforge_project:
76
- rubygems_version: 2.2.1
80
+ rubygems_version: 2.4.5
77
81
  signing_key:
78
82
  specification_version: 4
79
83
  summary: Predict code to be written from RSPEC
80
- test_files: []
81
- has_rdoc:
84
+ test_files:
85
+ - spec/fixtures/basic_rspec.rb