goku 0.5 → 1.0

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: c0d25d655bc72bc176f604e3ceae388bcd41651e
4
- data.tar.gz: bba176c04c19d67b1099c4cd9ea38f4edbbda315
3
+ metadata.gz: a6ee8f922500529f81d6cf4be309ec63bd5ad6bb
4
+ data.tar.gz: 4a6d935ec336a507dd209b4ca8f0ad209ce33d84
5
5
  SHA512:
6
- metadata.gz: ea5333b4dd4aa3382af39bc535b94b12c86cf560246a2b0b542613b62c714fd4dd269a44845f24d0bec43d1b2439d5cdf46ed4c6b58d61333b06916234287926
7
- data.tar.gz: aa4eaded1b969ad8fa0f7abaa17eb403bff15617666f6cef0db6ddc86ebb1ef497e96533a9bc983a64ef3dfe54cb146a765a27de60fb9eac2902e31e0d880c1c
6
+ metadata.gz: 919400e3de020691a36ea252da2b11b8faec6b8161b44430b2c2f36b03fe32ecc92ce15ab2b549c999f97f0f29a0f44c99891edb332488e33010376f9e6d8ecb
7
+ data.tar.gz: c6f87e36d5ad17520abc44ecc89c9eb21495c065350c8fc42d00fd6fcd001174079570d9ffee74e927b6e472a1b18f1613a3b234e440bd506f2f62b4b95de313
data/README.md CHANGED
@@ -24,14 +24,14 @@ Or install it yourself as:
24
24
  ## Usage
25
25
 
26
26
  ``` sh
27
- goku class lib/users/signup.rb
27
+ $ goku class lib/users/signup.rb
28
+ Creating lib/users/signup.rb
29
+ Creating spec/lib/users/signup_spec.rb
28
30
  ```
29
31
 
30
- Creates a class in that path:
32
+ Creates a class in `lib/users/signup.rb`:
31
33
 
32
34
  ``` ruby
33
- # lib/users/signup.rb
34
-
35
35
  module Users
36
36
  class Signup
37
37
 
@@ -42,17 +42,13 @@ module Users
42
42
  end
43
43
  ```
44
44
 
45
- And a rspec test file:
45
+ And a RSpec test file `spec/lib/users/signup_spec.rb`:
46
46
 
47
47
  ``` ruby
48
- # spec/lib/users/signup_spec.rb
49
-
50
48
  require "spec_helper"
51
49
 
52
- module Users
53
- RSpec.describe Signup do
50
+ describe Users::Signup do
54
51
 
55
- end
56
52
  end
57
53
  ```
58
54
  ## Development
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "thor", "~> 0.19"
22
22
  spec.add_dependency "activesupport", "~> 4.2"
23
+ spec.add_dependency "colorize", "~> 0.7"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.11"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,5 +1,7 @@
1
1
  require "thor"
2
2
  require "active_support/all"
3
+ require "fileutils"
4
+ require "colorize"
3
5
 
4
6
  require "goku/elements/base"
5
7
  require "goku/elements/method"
@@ -2,25 +2,50 @@ module Goku
2
2
  class CLI < Thor
3
3
 
4
4
  desc "c PATH", "Create a class"
5
- def c(path)
5
+ def c(raw_path)
6
+ path = Goku::Path.new(raw_path)
6
7
  factory = Goku::ElementFactory.new(path)
7
8
 
8
- puts factory.create_class.to_s
9
- puts "---------------------"
10
- puts factory.create_spec.to_s
9
+ implementation = factory.create_class.to_s
10
+ spec = factory.create_spec.to_s
11
+
12
+ save(path, implementation, spec)
11
13
  end
12
14
 
13
15
  desc "m PATH", "Create a module"
14
- def m(path)
16
+ def m(raw_path)
17
+ path = Goku::Path.new(raw_path)
15
18
  factory = Goku::ElementFactory.new(path)
16
19
 
17
- puts factory.create_module.to_s
18
- puts "---------------------"
19
- puts factory.create_spec.to_s
20
+ implementation = factory.create_module.to_s
21
+ spec = factory.create_spec.to_s
22
+
23
+ save(path, implementation, spec)
20
24
  end
21
25
 
22
26
  map "module" => "m"
23
27
  map "class" => "m"
24
28
 
29
+ private
30
+
31
+ def save(path, implementation, spec)
32
+ failure("File #{path.full.colorize(:red)} already exists") if path.exists?
33
+ failure("Spec #{path.to_spec.full.colorize(:red)} already exists") if path.to_spec.exists?
34
+
35
+ puts "Creating #{path.full.colorize(:green)}"
36
+ FileUtils.mkdir_p(File.dirname(path.full))
37
+ File.write(path.full, implementation)
38
+
39
+ puts "Creating #{path.to_spec.full.colorize(:green)}"
40
+ FileUtils.mkdir_p(File.dirname(path.to_spec.full))
41
+ File.write(path.to_spec.full, spec)
42
+ end
43
+
44
+ def failure(message)
45
+ puts message
46
+
47
+ exit(1)
48
+ end
49
+
25
50
  end
26
51
  end
@@ -3,8 +3,8 @@ module Goku
3
3
 
4
4
  attr_reader :path
5
5
 
6
- def initialize(raw_path)
7
- @path = Goku::Path.new(raw_path)
6
+ def initialize(path)
7
+ @path = path
8
8
  end
9
9
 
10
10
  def create_class
@@ -11,7 +11,7 @@ module Goku
11
11
  def to_s
12
12
  full_name = (@ancestor_names + [name]).map(&:camelcase).join("::")
13
13
 
14
- "describe #{full_name} do\n#{super}\nend"
14
+ "require \"spec_helper\"\n\ndescribe #{full_name} do\n#{super}\nend"
15
15
  end
16
16
 
17
17
  end
@@ -8,6 +8,10 @@ module Goku
8
8
  @full= raw_path
9
9
  end
10
10
 
11
+ def exists?
12
+ File.exists?(full)
13
+ end
14
+
11
15
  def directories
12
16
  File.dirname(full).split("/")
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module Goku
2
- VERSION = "0.5"
2
+ VERSION = "1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goku
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Šarčević
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement