hexx 8.0.0 → 9.0.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 +4 -4
- data/.travis.yml +5 -2
- data/Gemfile +4 -0
- data/Guardfile +2 -0
- data/README.md +2 -6
- data/Rakefile +1 -1
- data/bin/hexx +18 -0
- data/hexx.gemspec +20 -18
- data/lib/hexx.rb +1 -6
- data/lib/hexx/version.rb +3 -1
- data/spec/spec_helper.rb +4 -2
- data/spec/tests/bin/hexx_spec.rb +34 -0
- metadata +25 -34
- data/config/initializer.rb +0 -5
- data/config/initializers/capture.rb +0 -19
- data/config/initializers/sandbox.rb +0 -16
- data/config/initializers/sandbox/helpers.rb +0 -38
- data/config/initializers/sandbox/matchers.rb +0 -19
- data/lib/hexx/generator.rb +0 -71
- data/lib/hexx/generator/file.rb +0 -83
- data/lib/hexx/generator/folder.rb +0 -68
- data/lib/hexx/name.rb +0 -148
- data/spec/fixtures/root/_.beta +0 -1
- data/spec/fixtures/root/__omega +0 -0
- data/spec/fixtures/root/delta.erb.erb +0 -0
- data/spec/fixtures/root/gamma.rb.erb +0 -1
- data/spec/fixtures/root/subfolder/alfa.yml +0 -0
- data/spec/tests/lib/generator_spec.rb +0 -126
- data/spec/tests/lib/name_spec.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6effd087aa74f0b83ab630d79d8ad663812ccda
|
4
|
+
data.tar.gz: b4c361973cfebceef13007a03945035c2d78f09c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e306203efb7c87867328c55dc7555dd3ce5108ffbe67ade6e20393202a1d834fb17163906488aef4dd321f81285ccba2bc2854735ebfc67a57e65e453bcd6ade
|
7
|
+
data.tar.gz: 830600f094e9b9e69d1ad5fd1df3768f6a0addae0e4241b9304d7ebd19341c2d7201128fd06169b3fea952d50a8370effefc6be23b649aac29c8ab386fe57adf
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -5,9 +5,7 @@
|
|
5
5
|
[][gemnasium]
|
6
6
|
[][codeclimate]
|
7
7
|
[][coveralls]
|
8
|
-
[][MIT LICENSE]
|
9
8
|
|
10
|
-
[MIT LICENSE]: file:./LICENSE
|
11
9
|
[codeclimate]: https://codeclimate.com/github/nepalez/hexx
|
12
10
|
[coveralls]: https://coveralls.io/r/nepalez/hexx
|
13
11
|
[gem]: https://rubygems.org/gems/hexx
|
@@ -122,7 +120,7 @@ Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
|
|
122
120
|
## Contributing
|
123
121
|
|
124
122
|
* Fork the project.
|
125
|
-
* Read the [STYLEGUIDE].
|
123
|
+
* Read the [STYLEGUIDE](config/metrics/STYLEGUIDE).
|
126
124
|
* Make your feature addition or bug fix.
|
127
125
|
* Add tests for it. This is important so I don't break it in a
|
128
126
|
future version unintentionally.
|
@@ -131,8 +129,6 @@ Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
|
|
131
129
|
in a commit by itself I can ignore when I pull)
|
132
130
|
* Send me a pull request. Bonus points for topic branches.
|
133
131
|
|
134
|
-
[STYLEGUIDE]: file:./config/metrics/STYLEGUIDE
|
135
|
-
|
136
132
|
## License
|
137
133
|
|
138
|
-
See [MIT LICENSE].
|
134
|
+
See the [MIT LICENSE](LICENSE).
|
data/Rakefile
CHANGED
data/bin/hexx
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Loads the development dependencies
|
4
|
+
require "hexx-validators"
|
5
|
+
|
6
|
+
# Command line runner
|
7
|
+
class CLI < Thor
|
8
|
+
|
9
|
+
register(
|
10
|
+
Hexx::Validators::Generator,
|
11
|
+
"validator",
|
12
|
+
"validator NAME[ -e error[ error]][ -o option[ option]]",
|
13
|
+
"Scaffolds a custom validator. Run `hexx validator -h` for help."
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Starts cli with arguments taken from a command line
|
18
|
+
CLI.start ARGV
|
data/hexx.gemspec
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
2
|
require "hexx/version"
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
s.name = "hexx"
|
6
|
-
s.version = Hexx::VERSION.dup
|
7
|
-
s.author = "Andrew Kozin"
|
8
|
-
s.email = "andrew.kozin@gmail.com"
|
9
|
-
s.homepage = "https://github.com/nepalez/hexx"
|
10
|
-
s.description = "Collection of scaffolders."
|
11
|
-
s.summary = "Collection of scaffolders for projects that follow " \
|
12
|
-
"the hexagonal architecture."
|
13
|
-
s.license = "MIT"
|
14
|
-
s.platform = Gem::Platform::RUBY
|
15
|
-
s.required_ruby_version = ">= 2.1"
|
4
|
+
Gem::Specification.new do |gem|
|
16
5
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
gem.name = "hexx"
|
7
|
+
gem.version = Hexx::VERSION.dup
|
8
|
+
gem.author = "Andrew Kozin"
|
9
|
+
gem.email = "andrew.kozin@gmail.com"
|
10
|
+
gem.homepage = "https://github.com/nepalez/hexx"
|
11
|
+
gem.description = "A collection of scaffolders."
|
12
|
+
gem.summary = "A collection of scaffolders for projects that follow " \
|
13
|
+
"the Hexagonal Architecture."
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
|
+
gem.executables = ["hexx"]
|
19
|
+
gem.test_files = Dir["spec/**/*.rb"]
|
20
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE"]
|
21
|
+
|
22
|
+
gem.required_ruby_version = "~> 2.0"
|
23
|
+
gem.add_runtime_dependency "hexx-validators", "~> 0.0", ">= 0.0.2"
|
24
|
+
gem.add_development_dependency "hexx-rspec", "~> 0.3"
|
21
25
|
|
22
|
-
s.add_runtime_dependency "extlib", "~> 0.9"
|
23
|
-
s.add_runtime_dependency "hexx-suit", "~> 0.0"
|
24
26
|
end
|
data/lib/hexx.rb
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
#
|
2
|
-
require "hexx-suit"
|
3
|
-
|
4
|
-
require_relative "../config/initializer"
|
5
|
-
require_relative "hexx/generator"
|
6
|
-
require_relative "hexx/name"
|
1
|
+
# encoding: utf-8
|
7
2
|
|
8
3
|
# Collection of scaffolders for projects that follows the Hexagonal architecture
|
9
4
|
module Hexx
|
data/lib/hexx/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "hexx-validators"
|
3
|
+
|
4
|
+
describe "$ hexx", :sandbox do
|
5
|
+
|
6
|
+
shared_examples "specific scaffolder" do
|
7
|
+
# subject command, its arguments and generator should be defined in context
|
8
|
+
|
9
|
+
let!(:expected_output) do
|
10
|
+
capture_stdout { try_in_sandbox { generator.start(arguments) } }
|
11
|
+
end
|
12
|
+
|
13
|
+
let!(:actual_output) do
|
14
|
+
prepare_sandbox
|
15
|
+
try_in_sandbox { return `#{ [:hexx, subject, arguments].join(" ") }` }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "[starts the generator]" do
|
19
|
+
expect(actual_output).to eq expected_output
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "validator" do
|
24
|
+
|
25
|
+
subject { :validator }
|
26
|
+
|
27
|
+
it_behaves_like "specific scaffolder" do
|
28
|
+
let(:arguments) { %w(in_future -e not_in_future -o allow_nil) }
|
29
|
+
let(:generator) { Hexx::Validators::Generator }
|
30
|
+
end
|
31
|
+
|
32
|
+
end # validator
|
33
|
+
|
34
|
+
end # describe $ hexx
|
metadata
CHANGED
@@ -1,51 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: hexx-validators
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.2
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
29
|
+
version: '0.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.2
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: hexx-
|
34
|
+
name: hexx-rspec
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
34
|
-
type: :
|
39
|
+
version: '0.3'
|
40
|
+
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
41
|
-
description:
|
46
|
+
version: '0.3'
|
47
|
+
description: A collection of scaffolders.
|
42
48
|
email: andrew.kozin@gmail.com
|
43
|
-
executables:
|
49
|
+
executables:
|
50
|
+
- hexx
|
44
51
|
extensions: []
|
45
52
|
extra_rdoc_files:
|
46
53
|
- README.md
|
47
54
|
- LICENSE
|
48
|
-
- config/metrics/STYLEGUIDE
|
49
55
|
files:
|
50
56
|
- ".coveralls.yml"
|
51
57
|
- ".gitignore"
|
@@ -59,11 +65,7 @@ files:
|
|
59
65
|
- LICENSE
|
60
66
|
- README.md
|
61
67
|
- Rakefile
|
62
|
-
-
|
63
|
-
- config/initializers/capture.rb
|
64
|
-
- config/initializers/sandbox.rb
|
65
|
-
- config/initializers/sandbox/helpers.rb
|
66
|
-
- config/initializers/sandbox/matchers.rb
|
68
|
+
- bin/hexx
|
67
69
|
- config/metrics/STYLEGUIDE
|
68
70
|
- config/metrics/cane.yml
|
69
71
|
- config/metrics/churn.yml
|
@@ -78,19 +80,9 @@ files:
|
|
78
80
|
- config/metrics/yardstick.yml
|
79
81
|
- hexx.gemspec
|
80
82
|
- lib/hexx.rb
|
81
|
-
- lib/hexx/generator.rb
|
82
|
-
- lib/hexx/generator/file.rb
|
83
|
-
- lib/hexx/generator/folder.rb
|
84
|
-
- lib/hexx/name.rb
|
85
83
|
- lib/hexx/version.rb
|
86
|
-
- spec/fixtures/root/_.beta
|
87
|
-
- spec/fixtures/root/__omega
|
88
|
-
- spec/fixtures/root/delta.erb.erb
|
89
|
-
- spec/fixtures/root/gamma.rb.erb
|
90
|
-
- spec/fixtures/root/subfolder/alfa.yml
|
91
84
|
- spec/spec_helper.rb
|
92
|
-
- spec/tests/
|
93
|
-
- spec/tests/lib/name_spec.rb
|
85
|
+
- spec/tests/bin/hexx_spec.rb
|
94
86
|
homepage: https://github.com/nepalez/hexx
|
95
87
|
licenses:
|
96
88
|
- MIT
|
@@ -101,9 +93,9 @@ require_paths:
|
|
101
93
|
- lib
|
102
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
95
|
requirements:
|
104
|
-
- - "
|
96
|
+
- - "~>"
|
105
97
|
- !ruby/object:Gem::Version
|
106
|
-
version: '2.
|
98
|
+
version: '2.0'
|
107
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
100
|
requirements:
|
109
101
|
- - ">="
|
@@ -111,12 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
103
|
version: '0'
|
112
104
|
requirements: []
|
113
105
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.6
|
115
107
|
signing_key:
|
116
108
|
specification_version: 4
|
117
|
-
summary:
|
109
|
+
summary: A collection of scaffolders for projects that follow the Hexagonal Architecture.
|
118
110
|
test_files:
|
119
111
|
- spec/spec_helper.rb
|
120
|
-
- spec/tests/
|
121
|
-
- spec/tests/lib/name_spec.rb
|
112
|
+
- spec/tests/bin/hexx_spec.rb
|
122
113
|
has_rdoc:
|
data/config/initializer.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Captures and returns the results of capturing $stdout
|
4
|
-
def capture_stdout
|
5
|
-
begin
|
6
|
-
$stdout = StringIO.new
|
7
|
-
yield
|
8
|
-
ensure
|
9
|
-
result, $stdout = $stdout.string, STDOUT
|
10
|
-
end
|
11
|
-
result
|
12
|
-
end
|
13
|
-
|
14
|
-
# Captures stdout of specifications with :capture tag
|
15
|
-
RSpec.configure do |config|
|
16
|
-
config.around :each, :capture do |example|
|
17
|
-
capture_stdout { example.run }
|
18
|
-
end
|
19
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Re-creates tmp/sandbox before specs with :sandbox tag
|
4
|
-
# Defines specific helpers and matchers for the specifications
|
5
|
-
RSpec.configure do |config|
|
6
|
-
|
7
|
-
config.before :each, :sandbox do
|
8
|
-
require_relative "sandbox/helpers"
|
9
|
-
require_relative "sandbox/matchers"
|
10
|
-
prepare_sandbox
|
11
|
-
end
|
12
|
-
|
13
|
-
config.after :each, :sandbox do
|
14
|
-
clear_sandbox
|
15
|
-
end
|
16
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# Path to the temporary `tmp/sandbox` folder
|
2
|
-
#
|
3
|
-
# @return [String]
|
4
|
-
def sandbox
|
5
|
-
@sandbox ||= File.expand_path "tmp/sandbox"
|
6
|
-
end
|
7
|
-
|
8
|
-
# Clears the sandbox
|
9
|
-
#
|
10
|
-
# @return [undefined]
|
11
|
-
def clear_sandbox
|
12
|
-
FileUtils.rm_rf sandbox
|
13
|
-
end
|
14
|
-
|
15
|
-
# Re-creates the sandbox
|
16
|
-
#
|
17
|
-
# @return [undefined]
|
18
|
-
def prepare_sandbox
|
19
|
-
clear_sandbox
|
20
|
-
FileUtils.mkdir_p sandbox
|
21
|
-
end
|
22
|
-
|
23
|
-
# Runs code in a sandbox
|
24
|
-
#
|
25
|
-
# @return [undefined]
|
26
|
-
def try_in_sandbox
|
27
|
-
FileUtils.cd(sandbox) { yield }
|
28
|
-
end
|
29
|
-
|
30
|
-
# Reads file in sandbox and returns its content
|
31
|
-
#
|
32
|
-
# @return [String]
|
33
|
-
# @return [""]
|
34
|
-
# when the file is absent
|
35
|
-
def read_in_sandbox(filename)
|
36
|
-
file = Dir[File.join(sandbox, filename)].first
|
37
|
-
file ? File.read(file) : ""
|
38
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# Checks if a file with given name is present in sandbox.
|
2
|
-
#
|
3
|
-
# @example
|
4
|
-
# expect("some_file.rb").to be_present_in_sandbox
|
5
|
-
RSpec::Matchers.define :be_present_in_sandbox do
|
6
|
-
match do |filename|
|
7
|
-
files = Dir[File.join(sandbox, filename)]
|
8
|
-
expect(files).to be_any
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# Checks if a file with given name is absent in sandbox.
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# expect("some_file.rb").to be_absent_in_sandbox
|
16
|
-
RSpec::Matchers.define_negated_matcher(
|
17
|
-
:be_absent_in_sandbox,
|
18
|
-
:be_present_in_sandbox
|
19
|
-
)
|
data/lib/hexx/generator.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "generator/file"
|
3
|
-
require_relative "generator/folder"
|
4
|
-
|
5
|
-
module Hexx
|
6
|
-
|
7
|
-
# Base class for scaffolders
|
8
|
-
#
|
9
|
-
# Adds actions to the generator
|
10
|
-
#
|
11
|
-
# @example (see #from_template)
|
12
|
-
# @example (see #copy_folder)
|
13
|
-
class Generator < Thor::Group
|
14
|
-
include Thor::Actions
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
# Returns source root defined for the class
|
19
|
-
#
|
20
|
-
# @return [String, Array<String>]
|
21
|
-
def source_root
|
22
|
-
self.class.send :source_root
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns content of source (relative to source root), preprocessed by ERB
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
# # source_root/file.erb
|
29
|
-
# <%= 2 * 2 %>
|
30
|
-
#
|
31
|
-
# scaffolder = Hexx::Generator.new
|
32
|
-
# scaffolder.send :from_template, "file.erb"
|
33
|
-
# # => "4"
|
34
|
-
#
|
35
|
-
# @return [#to_s] source
|
36
|
-
#
|
37
|
-
# @api public
|
38
|
-
def from_template(source)
|
39
|
-
path = find_in_source_paths(source)
|
40
|
-
content = ::File.read(path)
|
41
|
-
ERB.new(content, nil, "-").result
|
42
|
-
end
|
43
|
-
|
44
|
-
# Copies files from source folder into the destination one
|
45
|
-
#
|
46
|
-
# Wherein:
|
47
|
-
#
|
48
|
-
# * Files with a '.erb' extension are treated as templates and preprocessed
|
49
|
-
# by ERB. They saved under initial names without '.erb' extension.
|
50
|
-
#
|
51
|
-
# * The underscore symbol "_" in the beginning of filename is removed.
|
52
|
-
# You can copy dotfiles by underscoring them.
|
53
|
-
#
|
54
|
-
# @example
|
55
|
-
# scaffolder = Hexx::Generator.new
|
56
|
-
#
|
57
|
-
# scaffolder.copy_folder "root", "spec", skip: true
|
58
|
-
# # root/_.settings --> spec/.settings
|
59
|
-
# # root/spec_helper.rb.erb --> spec/spec_helper.rb
|
60
|
-
# # root/tests/test_spec.rb --> spec/tests/test_spec.rb
|
61
|
-
#
|
62
|
-
# @return [undefined]
|
63
|
-
#
|
64
|
-
# @api public
|
65
|
-
def copy_folder(source, target = source, options = {})
|
66
|
-
Folder.new(self).copy(source, target, options)
|
67
|
-
end
|
68
|
-
|
69
|
-
end # class Generator
|
70
|
-
|
71
|
-
end # module Hexx
|
data/lib/hexx/generator/file.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "pathname"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
|
6
|
-
# Utilities to copy files and folders in a scaffolder context
|
7
|
-
class Generator < Thor::Group
|
8
|
-
|
9
|
-
# Copies a file from a source path to the target folder
|
10
|
-
#
|
11
|
-
# * Files, that have '.erb' extension, are pre-processed as erb templates.
|
12
|
-
# * The starting "_" symbol is removed from a file name.
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
class File
|
16
|
-
|
17
|
-
# @!scope class
|
18
|
-
# @!method new(scaffolder, source, target, options = {})
|
19
|
-
# Constructs the processor for given scaffolder, source and target paths
|
20
|
-
#
|
21
|
-
# @param [Thor::Actions] scaffolder
|
22
|
-
# the decorated scaffolder
|
23
|
-
# @param [Pathname] source
|
24
|
-
# the source folder path to take file from
|
25
|
-
# @param [Pathname] target
|
26
|
-
# the target folder path to copy file to
|
27
|
-
# @param [Hash] options
|
28
|
-
# the list of options to copy file
|
29
|
-
#
|
30
|
-
# @return [Hexx::Processors::File]
|
31
|
-
def initialize(scaffolder, source, target, options = {})
|
32
|
-
@__scaffolder__ = scaffolder
|
33
|
-
@source = source
|
34
|
-
@target = target
|
35
|
-
@options = options
|
36
|
-
end
|
37
|
-
|
38
|
-
# Makes a copy of given source file
|
39
|
-
#
|
40
|
-
# @param [Pathname] source_file
|
41
|
-
#
|
42
|
-
# @return [self] itself
|
43
|
-
def copy(source_file)
|
44
|
-
@source_file = source_file
|
45
|
-
__scaffolder__.send(copy_method, source_path, target_path, options)
|
46
|
-
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
attr_reader :__scaffolder__, :source, :target, :options, :source_file
|
53
|
-
|
54
|
-
def source_root
|
55
|
-
@source_root ||= Pathname.new __scaffolder__.send(:source_root)
|
56
|
-
end
|
57
|
-
|
58
|
-
def copy_method
|
59
|
-
(source_file.extname == ".erb") ? :template : :copy_file
|
60
|
-
end
|
61
|
-
|
62
|
-
def source_path
|
63
|
-
source_file.relative_path_from(source_root).to_s
|
64
|
-
end
|
65
|
-
|
66
|
-
def target_path
|
67
|
-
(target_dirname + target_filename).to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
def target_dirname
|
71
|
-
target + source_file.relative_path_from(source).dirname
|
72
|
-
end
|
73
|
-
|
74
|
-
def target_filename
|
75
|
-
basename = source_file.basename(".erb").to_s
|
76
|
-
basename[0] == "_" ? basename[1..-1].to_s : basename
|
77
|
-
end
|
78
|
-
|
79
|
-
end # class File
|
80
|
-
|
81
|
-
end # class Generator
|
82
|
-
|
83
|
-
end # module Hexx
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Hexx
|
2
|
-
|
3
|
-
class Generator < Thor::Group
|
4
|
-
|
5
|
-
# Copies all files from a source folder to the target one
|
6
|
-
#
|
7
|
-
# * Files, that have '.erb' extension, are pre-processed as erb templates.
|
8
|
-
# * The starting "_" symbol is removed from a file name.
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
class Folder
|
12
|
-
|
13
|
-
# @!scope class
|
14
|
-
# @!method new(scaffolder)
|
15
|
-
# Constructs the processor for given scaffolder
|
16
|
-
#
|
17
|
-
# @param [Thor::Actions] scaffolder
|
18
|
-
#
|
19
|
-
# @return [Hexx::Processors::Folder]
|
20
|
-
def initialize(scaffolder)
|
21
|
-
@__scaffolder__ = scaffolder
|
22
|
-
end
|
23
|
-
|
24
|
-
# Copies a source folder content to the target folder
|
25
|
-
#
|
26
|
-
# @param [String] source
|
27
|
-
# The source folder path relative to the scaffolder's source_root
|
28
|
-
# @param [String] target
|
29
|
-
# The target folder path relative to the scaffolder's destination_root
|
30
|
-
# @param [Hash] options
|
31
|
-
#
|
32
|
-
# @return [self] itself
|
33
|
-
def copy(source, target, options = {})
|
34
|
-
@source, @target, @options = source, target, options
|
35
|
-
source_files.each { |file| file_processor.copy(file) }
|
36
|
-
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
attr_reader :__scaffolder__, :source, :target, :options
|
43
|
-
|
44
|
-
def source_files
|
45
|
-
source_paths.map(&Pathname.method(:new)).select(&:file?)
|
46
|
-
end
|
47
|
-
|
48
|
-
def file_processor
|
49
|
-
File.new __scaffolder__, source_folder, target_folder, options
|
50
|
-
end
|
51
|
-
|
52
|
-
def source_paths
|
53
|
-
::Dir[source_folder + "**/*"]
|
54
|
-
end
|
55
|
-
|
56
|
-
def source_folder
|
57
|
-
Pathname.new(__scaffolder__.send :source_root).join(source)
|
58
|
-
end
|
59
|
-
|
60
|
-
def target_folder
|
61
|
-
Pathname.new(__scaffolder__.send :destination_root).join(target)
|
62
|
-
end
|
63
|
-
|
64
|
-
end # class Folder
|
65
|
-
|
66
|
-
end # class Generator
|
67
|
-
|
68
|
-
end # module Hexx
|
data/lib/hexx/name.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "extlib"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
|
6
|
-
# Decorates a string with conventional names
|
7
|
-
class Name
|
8
|
-
|
9
|
-
# @!scope class
|
10
|
-
# @!method new(string)
|
11
|
-
# Constructs the parser object
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# Hexx::Name.new "MyGem::MyClass.methods.chain"
|
15
|
-
#
|
16
|
-
# @param [#to_s] string
|
17
|
-
# The string to be parsed
|
18
|
-
#
|
19
|
-
# @return [Hexx::Name]
|
20
|
-
def initialize(string)
|
21
|
-
@list = string.to_s.snake_case.gsub(/\:{2}|-/, "/").split(".")
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns the last part of the singular name
|
25
|
-
#
|
26
|
-
# @example
|
27
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
28
|
-
# name = Hexx::Name.new(source)
|
29
|
-
# name.item
|
30
|
-
# # => "panther_tiger"
|
31
|
-
#
|
32
|
-
# @return [String]
|
33
|
-
def item
|
34
|
-
@item ||= snakes.last.to_s.singular
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns the last part of the plural name
|
38
|
-
#
|
39
|
-
# @example
|
40
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
41
|
-
# name = Hexx::Name.new(source)
|
42
|
-
# name.items
|
43
|
-
# # => "panther_tigers"
|
44
|
-
#
|
45
|
-
# @return [String]
|
46
|
-
def items
|
47
|
-
@items ||= item.plural
|
48
|
-
end
|
49
|
-
|
50
|
-
# Returns the dashes-delimited name
|
51
|
-
#
|
52
|
-
# @example
|
53
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
54
|
-
# name = Hexx::Name.new(source)
|
55
|
-
# name.file
|
56
|
-
# # => "cats-wildcats-jaguars-panther_tiger.bite"
|
57
|
-
#
|
58
|
-
# @return [String]
|
59
|
-
def file
|
60
|
-
@file ||= [snakes.join("-"), method].compact.join(".")
|
61
|
-
end
|
62
|
-
|
63
|
-
# Returns the slash-delimited name
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
67
|
-
# name = Hexx::Name.new(source)
|
68
|
-
# name.path
|
69
|
-
# # => "cats/wildcats/jaguars/panther_tiger/bite"
|
70
|
-
#
|
71
|
-
# @return [String]
|
72
|
-
def path
|
73
|
-
@path ||= [snakes.join("/"), method].compact.join(".")
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns the name as a full constant
|
77
|
-
#
|
78
|
-
# @example
|
79
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
80
|
-
# name = Hexx::Name.new(source)
|
81
|
-
# name.type
|
82
|
-
# # => "Cats::Wildcats::Jaguars::PantherTiger.bite"
|
83
|
-
#
|
84
|
-
# @return [String]
|
85
|
-
def type
|
86
|
-
@type ||= [camels.join("::"), method].compact.join(".")
|
87
|
-
end
|
88
|
-
|
89
|
-
# Returns the name as a last part of constant
|
90
|
-
#
|
91
|
-
# @example
|
92
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
93
|
-
# name = Hexx::Name.new(source)
|
94
|
-
# name.const
|
95
|
-
# # => "PantherTiger.bite"
|
96
|
-
#
|
97
|
-
# @return [String]
|
98
|
-
def const
|
99
|
-
@const ||= [camels.last, method].compact.join(".")
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns the array of namespaces (module names) for the constant
|
103
|
-
#
|
104
|
-
# @example
|
105
|
-
# source = "cats-wildcats/jaguars::PantherTiger.bite"
|
106
|
-
# name = Hexx::Name.new(source)
|
107
|
-
# name.namespaces
|
108
|
-
# # => ["Cats", "Wildcats", "Jaguars"]
|
109
|
-
#
|
110
|
-
# @return [Array<String>]
|
111
|
-
def namespaces
|
112
|
-
@namespaces ||= camels[0..-2]
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
# String of chained methods
|
118
|
-
#
|
119
|
-
# @return [String]
|
120
|
-
# @return [nil]
|
121
|
-
# if source has no methods
|
122
|
-
#
|
123
|
-
# @api private
|
124
|
-
def method
|
125
|
-
@method ||= @list[1..-1] if @list.count > 1
|
126
|
-
end
|
127
|
-
|
128
|
-
# List of snake-cased parts of the constant
|
129
|
-
#
|
130
|
-
# @return [Array<String>]
|
131
|
-
#
|
132
|
-
# @api private
|
133
|
-
def snakes
|
134
|
-
@snakes ||= @list.first.to_s.split("/")
|
135
|
-
end
|
136
|
-
|
137
|
-
# List of camel-cased parts of the constant
|
138
|
-
#
|
139
|
-
# @return [Array<String>]
|
140
|
-
#
|
141
|
-
# @api private
|
142
|
-
def camels
|
143
|
-
@camels ||= snakes.map(&:camel_case)
|
144
|
-
end
|
145
|
-
|
146
|
-
end # class Name
|
147
|
-
|
148
|
-
end # module Hexx
|
data/spec/fixtures/root/_.beta
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= 2 * 2 -%>
|
data/spec/fixtures/root/__omega
DELETED
File without changes
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= 2 * 2 -%>
|
File without changes
|
@@ -1,126 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# See settings for :sandbox and :capture tags in `config/initializers` folder
|
4
|
-
describe Hexx::Generator do
|
5
|
-
|
6
|
-
# source path is set to spec/fixtures
|
7
|
-
let(:fixtures) { ::File.expand_path "../../../fixtures", __FILE__ }
|
8
|
-
before { allow(described_class).to receive(:source_root).and_return fixtures }
|
9
|
-
|
10
|
-
describe ".new" do
|
11
|
-
|
12
|
-
it "constructs Thor::Group instance" do
|
13
|
-
expect(subject).to be_kind_of Thor::Group
|
14
|
-
end
|
15
|
-
|
16
|
-
it "constructs Thor::Actions instance" do
|
17
|
-
expect(subject).to be_kind_of Thor::Actions
|
18
|
-
end
|
19
|
-
|
20
|
-
end # describe .new
|
21
|
-
|
22
|
-
describe "##source_root" do
|
23
|
-
|
24
|
-
it "returns a source root" do
|
25
|
-
expect(subject.send :source_root)
|
26
|
-
.to eq described_class.send(:source_root)
|
27
|
-
end
|
28
|
-
|
29
|
-
end # describe ##source_root
|
30
|
-
|
31
|
-
describe "#copy_folder", :sandbox, :capture do
|
32
|
-
|
33
|
-
shared_examples "copying files" do
|
34
|
-
|
35
|
-
# target should be described in context
|
36
|
-
|
37
|
-
it "[copy file as is]" do
|
38
|
-
expect("#{ target }/subfolder/alfa.yml").to be_present_in_sandbox
|
39
|
-
end
|
40
|
-
|
41
|
-
end # examples
|
42
|
-
|
43
|
-
shared_examples "removing last .erb only" do
|
44
|
-
|
45
|
-
# target should be described in context
|
46
|
-
|
47
|
-
it "[removes last .erb]" do
|
48
|
-
expect("#{ target }/gamma.rb").to be_present_in_sandbox
|
49
|
-
end
|
50
|
-
|
51
|
-
it "[leaves previous .erb]" do
|
52
|
-
expect("#{ target }/delta.erb").to be_present_in_sandbox
|
53
|
-
end
|
54
|
-
|
55
|
-
end # examples
|
56
|
-
|
57
|
-
shared_examples "removing first underscores only" do
|
58
|
-
|
59
|
-
it "[removes first _]" do
|
60
|
-
expect("#{ target }/.beta").to be_present_in_sandbox
|
61
|
-
end
|
62
|
-
|
63
|
-
it "[leaves later _]" do
|
64
|
-
expect("#{ target }/_omega").to be_present_in_sandbox
|
65
|
-
end
|
66
|
-
|
67
|
-
end # examples
|
68
|
-
|
69
|
-
shared_examples "preprocessing ERB only" do
|
70
|
-
|
71
|
-
# target should be described in context
|
72
|
-
|
73
|
-
it "[preprocesses erb]" do
|
74
|
-
content = read_in_sandbox("#{ target }/gamma.rb")
|
75
|
-
expect(content).not_to include "<%= 2 * 2 -%>"
|
76
|
-
expect(content).to include "4"
|
77
|
-
end
|
78
|
-
|
79
|
-
it "[leaves non-erb]" do
|
80
|
-
content = read_in_sandbox("#{ target }/.beta")
|
81
|
-
expect(content).to include "<%= 2 * 2 -%>"
|
82
|
-
expect(content).not_to include "4"
|
83
|
-
end
|
84
|
-
|
85
|
-
end # examples
|
86
|
-
|
87
|
-
context "when the target isn't set" do
|
88
|
-
|
89
|
-
let(:target) { "root" }
|
90
|
-
|
91
|
-
before { try_in_sandbox { subject.send :copy_folder, "root" } }
|
92
|
-
|
93
|
-
it_behaves_like "copying files"
|
94
|
-
it_behaves_like "removing last .erb only"
|
95
|
-
it_behaves_like "removing first underscores only"
|
96
|
-
it_behaves_like "preprocessing ERB only"
|
97
|
-
|
98
|
-
end # context
|
99
|
-
|
100
|
-
context "with the target is set" do
|
101
|
-
|
102
|
-
let(:target) { "spec" }
|
103
|
-
|
104
|
-
before { try_in_sandbox { subject.send :copy_folder, "root", target } }
|
105
|
-
|
106
|
-
it_behaves_like "copying files"
|
107
|
-
it_behaves_like "removing last .erb only"
|
108
|
-
it_behaves_like "removing first underscores only"
|
109
|
-
it_behaves_like "preprocessing ERB only"
|
110
|
-
|
111
|
-
end # context
|
112
|
-
|
113
|
-
end # describe ##copy_folder
|
114
|
-
|
115
|
-
describe "#from_template", :sandbox, :capture do
|
116
|
-
|
117
|
-
let(:content) { subject.send :from_template, "root/_.beta" }
|
118
|
-
|
119
|
-
it "returns the ERB-preprocessed content of the template" do
|
120
|
-
expect(content).not_to include "<%= 2 * 2 -%>"
|
121
|
-
expect(content).to include "4"
|
122
|
-
end
|
123
|
-
|
124
|
-
end # describe ##from_template
|
125
|
-
|
126
|
-
end # describe Hexx::Generator
|
data/spec/tests/lib/name_spec.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe Hexx::Name do
|
4
|
-
|
5
|
-
describe ".new" do
|
6
|
-
|
7
|
-
it "requires an argument" do
|
8
|
-
expect { described_class.new }.to raise_error
|
9
|
-
expect { described_class.new "" }.not_to raise_error
|
10
|
-
expect { described_class.new "", "" }.to raise_error
|
11
|
-
end
|
12
|
-
|
13
|
-
end # describe .new
|
14
|
-
|
15
|
-
let(:a) { described_class.new nil }
|
16
|
-
let(:b) { described_class.new "cats" }
|
17
|
-
let(:c) { described_class.new "cats.names" }
|
18
|
-
let(:d) { described_class.new "cats-wildcats/jaguars::PantherTiger" }
|
19
|
-
let(:e) { described_class.new "cats-wildcats/jaguars::PantherTigers" }
|
20
|
-
let(:f) { described_class.new "cats-wildcats/jaguars::PantherTiger.a.B.c" }
|
21
|
-
|
22
|
-
describe "#item" do
|
23
|
-
|
24
|
-
it "returns a proper value" do
|
25
|
-
expect(a.item).to eq ""
|
26
|
-
expect(b.item).to eq "cat"
|
27
|
-
expect(c.item).to eq "cat"
|
28
|
-
expect(d.item).to eq "panther_tiger"
|
29
|
-
expect(e.item).to eq "panther_tiger"
|
30
|
-
expect(f.item).to eq "panther_tiger"
|
31
|
-
end
|
32
|
-
|
33
|
-
end # describe #item
|
34
|
-
|
35
|
-
describe "#items" do
|
36
|
-
|
37
|
-
it "returns a proper value" do
|
38
|
-
expect(a.items).to eq ""
|
39
|
-
expect(b.items).to eq "cats"
|
40
|
-
expect(c.items).to eq "cats"
|
41
|
-
expect(d.items).to eq "panther_tigers"
|
42
|
-
expect(e.items).to eq "panther_tigers"
|
43
|
-
expect(f.items).to eq "panther_tigers"
|
44
|
-
end
|
45
|
-
|
46
|
-
end # describe #items
|
47
|
-
|
48
|
-
describe "#file" do
|
49
|
-
|
50
|
-
it "returns a proper value" do
|
51
|
-
expect(a.file).to eq ""
|
52
|
-
expect(b.file).to eq "cats"
|
53
|
-
expect(c.file).to eq "cats.names"
|
54
|
-
expect(d.file).to eq "cats-wildcats-jaguars-panther_tiger"
|
55
|
-
expect(e.file).to eq "cats-wildcats-jaguars-panther_tigers"
|
56
|
-
expect(f.file).to eq "cats-wildcats-jaguars-panther_tiger.a.b.c"
|
57
|
-
end
|
58
|
-
|
59
|
-
end # describe #file
|
60
|
-
|
61
|
-
describe "#path" do
|
62
|
-
|
63
|
-
it "returns a proper value" do
|
64
|
-
expect(a.path).to eq ""
|
65
|
-
expect(b.path).to eq "cats"
|
66
|
-
expect(c.path).to eq "cats.names"
|
67
|
-
expect(d.path).to eq "cats/wildcats/jaguars/panther_tiger"
|
68
|
-
expect(e.path).to eq "cats/wildcats/jaguars/panther_tigers"
|
69
|
-
expect(f.path).to eq "cats/wildcats/jaguars/panther_tiger.a.b.c"
|
70
|
-
end
|
71
|
-
|
72
|
-
end # describe #path
|
73
|
-
|
74
|
-
describe "#type" do
|
75
|
-
|
76
|
-
it "returns a proper value" do
|
77
|
-
expect(a.type).to eq ""
|
78
|
-
expect(b.type).to eq "Cats"
|
79
|
-
expect(c.type).to eq "Cats.names"
|
80
|
-
expect(d.type).to eq "Cats::Wildcats::Jaguars::PantherTiger"
|
81
|
-
expect(e.type).to eq "Cats::Wildcats::Jaguars::PantherTigers"
|
82
|
-
expect(f.type).to eq "Cats::Wildcats::Jaguars::PantherTiger.a.b.c"
|
83
|
-
end
|
84
|
-
|
85
|
-
end # describe #type
|
86
|
-
|
87
|
-
describe "#const" do
|
88
|
-
|
89
|
-
it "returns a proper value" do
|
90
|
-
expect(a.const).to eq ""
|
91
|
-
expect(b.const).to eq "Cats"
|
92
|
-
expect(c.const).to eq "Cats.names"
|
93
|
-
expect(d.const).to eq "PantherTiger"
|
94
|
-
expect(e.const).to eq "PantherTigers"
|
95
|
-
expect(f.const).to eq "PantherTiger.a.b.c"
|
96
|
-
end
|
97
|
-
|
98
|
-
end # describe #const
|
99
|
-
|
100
|
-
describe "#namespaces" do
|
101
|
-
|
102
|
-
it "returns a proper value" do
|
103
|
-
expect(a.namespaces).to eq %w()
|
104
|
-
expect(b.namespaces).to eq %w()
|
105
|
-
expect(c.namespaces).to eq %w()
|
106
|
-
expect(d.namespaces).to eq %w(Cats Wildcats Jaguars)
|
107
|
-
expect(e.namespaces).to eq %w(Cats Wildcats Jaguars)
|
108
|
-
expect(f.namespaces).to eq %w(Cats Wildcats Jaguars)
|
109
|
-
end
|
110
|
-
|
111
|
-
end # describe #namespaces
|
112
|
-
|
113
|
-
end # describe Hexx::Name
|