goku 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8904c9074e9d8ced1c6a98d418c8d6903c5cce8c
4
- data.tar.gz: 1003b497bafc10713a370edf75571c7289bcaaa1
3
+ metadata.gz: 7c34932ce0351902f05dcb2d3d022919a0b961b3
4
+ data.tar.gz: 19b0e917d94ead942e9289ac026f58f81516dedf
5
5
  SHA512:
6
- metadata.gz: e4e0853efc58dda7190ca7a3456d5001a7d85e4870f3b7338d7247506ac11d6e3c1677ee35b1a4c5911e669f70a6ecd1fd96fa2d86f863d00a60a83e930961ae
7
- data.tar.gz: 6bb0f6fb4657c6a56080a5d9441a90ebf7407d8522c82a25427b54d16963fbcc546911a5f61f219b03f7fb0c8ef28499f8f3fcb58ab78e5053c464f2426ad218
6
+ metadata.gz: 73aaba8d52c105791319d9c37dfc21500fb9e04e456dcffc4bcee128a62c024cc07b1e10e9df7eecc1b7afca20eb1a0563c28c31a22c716f81da13bd8d12d645
7
+ data.tar.gz: 4e7e0d417549068ec0e8c13b245a32553b82d42d6daca407e31fc45b68850f6791252d8e2ade839fd4345345b1c524b8bf47b91efde3a177100ae17f3e8df6a0
data/lib/goku.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require "thor"
2
2
  require "active_support/all"
3
3
 
4
- require "goku/factories/base"
5
- require "goku/factories/method"
6
- require "goku/factories/class"
7
- require "goku/factories/module"
4
+ require "goku/elements/base"
5
+ require "goku/elements/method"
6
+ require "goku/elements/class"
7
+ require "goku/elements/module"
8
+ require "goku/element_factory"
8
9
 
9
10
  require "goku/path"
10
11
  require "goku/version"
data/lib/goku/cli.rb CHANGED
@@ -2,40 +2,17 @@ module Goku
2
2
  class CLI < Thor
3
3
 
4
4
  desc "c PATH", "Create a class"
5
- def c(raw_path)
6
- path = Goku::Path.new(raw_path)
7
-
8
- modules = create_modules(path)
9
-
10
- modules.last.add(Goku::Factories::Class.new(path.filename))
11
-
12
- puts modules.first.to_s
5
+ def c(path)
6
+ puts Goku::ElementFactory.new(path).create_class.to_s
13
7
  end
14
8
 
15
9
  desc "m PATH", "Create a module"
16
- def m(raw_path)
17
- path = Goku::Path.new(raw_path)
18
-
19
- modules = create_modules(path)
20
-
21
- modules.last.add(Goku::Factories::Module.new(path.filename))
22
-
23
- puts modules.first.to_s
10
+ def m(path)
11
+ puts Goku::ElementFactory.new(path).create_module.to_s
24
12
  end
25
13
 
26
14
  map "module" => "m"
27
15
  map "class" => "m"
28
16
 
29
- private
30
-
31
- def create_modules(path)
32
- modules = path.directories.drop(1).map { |m| Goku::Factories::Module.new(m) }
33
-
34
- modules.reverse.each_cons(2) do |submodule, parent_module|
35
- parent_module.add(submodule)
36
- end
37
-
38
- modules
39
- end
40
17
  end
41
18
  end
@@ -0,0 +1,35 @@
1
+ module Goku
2
+ class ElementFactory
3
+
4
+ attr_reader :path
5
+
6
+ def initialize(raw_path)
7
+ @path = Goku::Path.new(raw_path)
8
+ end
9
+
10
+ def create_class
11
+ nested(Goku::Elements::Class.new(path.filename))
12
+ end
13
+
14
+ def create_module
15
+ nested(Goku::Elements::Module.new(path.filename))
16
+ end
17
+
18
+ def ancestors
19
+ @ancestors ||= ancestor_names.map { |m| Goku::Elements::Module.new(m) }
20
+ end
21
+
22
+ def ancestor_names
23
+ @ancestor_names ||= @path.directories.drop(1).reverse
24
+ end
25
+
26
+ def nested(element)
27
+ ancestors.each_cons(2) { |sub, parent| parent.add(sub) }
28
+
29
+ ancestors.first.add(element)
30
+
31
+ ancestors.last
32
+ end
33
+
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Goku
2
- module Factories
2
+ module Elements
3
3
  class Base
4
4
 
5
5
  attr_reader :name
@@ -1,11 +1,11 @@
1
1
  module Goku
2
- module Factories
2
+ module Elements
3
3
  class Class < Base
4
4
 
5
5
  def initialize(name)
6
6
  super
7
7
 
8
- initializer = Goku::Factories::Method.new("initialize")
8
+ initializer = Goku::Elements::Method.new("initialize")
9
9
 
10
10
  add(initializer)
11
11
  end
@@ -1,5 +1,5 @@
1
1
  module Goku
2
- module Factories
2
+ module Elements
3
3
  class Method < Base
4
4
 
5
5
  def to_s
@@ -1,5 +1,5 @@
1
1
  module Goku
2
- module Factories
2
+ module Elements
3
3
  class Module < Base
4
4
 
5
5
  def to_s
data/lib/goku/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Goku
2
- VERSION = "0.4"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goku
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Šarčević
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-05 00:00:00.000000000 Z
11
+ date: 2016-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -102,7 +102,6 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".byebug_history"
106
105
  - ".gitignore"
107
106
  - ".rspec"
108
107
  - CODE_OF_CONDUCT.md
@@ -116,10 +115,11 @@ files:
116
115
  - goku.gemspec
117
116
  - lib/goku.rb
118
117
  - lib/goku/cli.rb
119
- - lib/goku/factories/base.rb
120
- - lib/goku/factories/class.rb
121
- - lib/goku/factories/method.rb
122
- - lib/goku/factories/module.rb
118
+ - lib/goku/element_factory.rb
119
+ - lib/goku/elements/base.rb
120
+ - lib/goku/elements/class.rb
121
+ - lib/goku/elements/method.rb
122
+ - lib/goku/elements/module.rb
123
123
  - lib/goku/path.rb
124
124
  - lib/goku/version.rb
125
125
  homepage: https://github.com/shiroyasha/goku