usecasing-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in usecasing-rails.gemspec
4
+ gemspec
5
+
6
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thiago Dantas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Usecasing::Rails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'usecasing-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install usecasing-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:test)
5
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate usecase finalize_invoice
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> <%= "< UseCase::Base" %>
2
+ <%- if depends.any? -%>
3
+ depends <%= depends.map(&:classify).join(", ") %>
4
+ <%- end -%>
5
+ end
@@ -0,0 +1,11 @@
1
+ class UsecasingGenerator < Rails::Generators::NamedBase
2
+
3
+ argument :depends, type: :array, default: [], banner: "depends USECASE"
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def generate
8
+ template "usecase.erb", "app/usecases/#{name.underscore.downcase}.rb"
9
+ end
10
+
11
+ end
@@ -0,0 +1 @@
1
+ require 'usecasing'
@@ -0,0 +1,56 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require 'rails'
4
+ require "rails/generators/test_case"
5
+ require "aruba/api"
6
+ require 'generators/usecasing/usecasing_generator'
7
+
8
+ module RailsAppHelper
9
+ include Aruba::Api
10
+
11
+ def provisioning(app_name = 'usecasing_app')
12
+ rails_new app_name
13
+
14
+ cd "#{app_name}"
15
+
16
+ write_file "Gemfile", <<-GEMFILE
17
+ gem "rails"
18
+ gem "usecasing-rails", path: "#{File.expand_path('../..', __FILE__)}"
19
+ GEMFILE
20
+
21
+ run_simple "bundle install"
22
+ end
23
+
24
+ def rails_generate_usecase(*params)
25
+ run_simple "bundle exec rails generate usecasing #{params.join(" ")}"
26
+ end
27
+
28
+ def rails_new(app_name)
29
+ cmd = "bundle exec rails new #{app_name} --skip-gemfile --skip-bundle --skip-git --skip-keeps --skip-active-record --skip-sprockets --skip-javascript --skip-test-unit --quiet"
30
+ run_simple cmd
31
+ end
32
+
33
+ end
34
+
35
+
36
+ class String
37
+ def heredoc_strip
38
+ new_indent = ( self.empty? ? 0 : ( scan(/^[ \t]*(?=\S)/).min.size ) )
39
+ gsub(/^[ \t]{#{new_indent}}/, '').strip
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.treat_symbols_as_metadata_keys_with_true_values = true
45
+ config.run_all_when_everything_filtered = true
46
+ config.filter_run :focus
47
+ config.order = 'random'
48
+
49
+ config.include(RailsAppHelper)
50
+
51
+ config.before do
52
+ @aruba_timeout_seconds = 60
53
+ FileUtils.rm_rf(current_dir)
54
+ end
55
+
56
+ end
@@ -0,0 +1,77 @@
1
+ require "spec_helper"
2
+
3
+ describe UsecasingGenerator do
4
+
5
+ before do
6
+ provisioning('usecase_app')
7
+ end
8
+
9
+ context "rails generate" do
10
+
11
+ let(:file_path) { "app/usecases/finalize.rb" }
12
+
13
+ context "usecasing without dependencies" do
14
+
15
+ it "generates file" do
16
+ rails_generate_usecase "finalize"
17
+ check_file_presence([file_path], true)
18
+ end
19
+
20
+ it "generates file properly" do
21
+ rails_generate_usecase "finalize"
22
+ check_exact_file_content file_path, <<-EOF.heredoc_strip
23
+ class Finalize < UseCase::Base
24
+ end
25
+ EOF
26
+ end
27
+
28
+ end
29
+
30
+
31
+ context "usecasing with dependencies" do
32
+
33
+ it "generates usecase class with one depends chain" do
34
+
35
+ rails_generate_usecase "finalize validate"
36
+ check_exact_file_content file_path, <<-EOF.heredoc_strip
37
+ class Finalize < UseCase::Base
38
+ depends Validate
39
+ end
40
+ EOF
41
+ end
42
+
43
+ it "generates usecase class with multiple depends chain" do
44
+ rails_generate_usecase "finalize validate send_email"
45
+ check_exact_file_content file_path, <<-EOF.heredoc_strip
46
+ class Finalize < UseCase::Base
47
+ depends Validate, SendEmail
48
+ end
49
+ EOF
50
+ end
51
+
52
+ end
53
+
54
+ context "namespacing" do
55
+
56
+ let(:file_path) { "app/usecases/namespace/finalize.rb" }
57
+
58
+ it "generates namespaced usecase" do
59
+ rails_generate_usecase "namespace::finalize"
60
+ check_file_presence([file_path], true)
61
+ end
62
+
63
+
64
+ it "generates directory in downcase" do
65
+ rails_generate_usecase "NAMESPACE::finalize"
66
+ check_file_presence([file_path], true)
67
+ end
68
+
69
+
70
+ it "generates multiple level" do
71
+ rails_generate_usecase "NAMESPACE::SECOND::finalize"
72
+ check_file_presence(['app/usecases/namespace/second/finalize.rb'], true)
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "usecasing-rails"
7
+ gem.version = '0.1.0'
8
+ gem.authors = ["Thiago Dantas"]
9
+ gem.email = ["thiago.teixeira.dantas@gmail.com"]
10
+ gem.description = %q{Usecase Rails Generator}
11
+ gem.summary = %q{UseCase Rails Generator}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency 'rake', '10.1.0'
20
+ gem.add_development_dependency 'rails', '3.2.16'
21
+ gem.add_development_dependency 'rspec', '2.14.1'
22
+ gem.add_development_dependency 'aruba', '0.5.3'
23
+ gem.add_development_dependency "bundler", '1.2.3'
24
+
25
+
26
+ gem.add_runtime_dependency 'usecasing', '0.1.0'
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usecasing-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thiago Dantas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 10.1.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 10.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.16
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.16
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.14.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: aruba
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.5.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.5.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.2.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.3
94
+ - !ruby/object:Gem::Dependency
95
+ name: usecasing
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - '='
100
+ - !ruby/object:Gem::Version
101
+ version: 0.1.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.1.0
110
+ description: Usecase Rails Generator
111
+ email:
112
+ - thiago.teixeira.dantas@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/generators/usecasing/USAGE
124
+ - lib/generators/usecasing/templates/usecase.erb
125
+ - lib/generators/usecasing/usecasing_generator.rb
126
+ - lib/usecasing/rails.rb
127
+ - spec/spec_helper.rb
128
+ - spec/usecasing_generator_spec.rb
129
+ - usecasing-rails.gemspec
130
+ homepage: ''
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.24
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: UseCase Rails Generator
154
+ test_files:
155
+ - spec/spec_helper.rb
156
+ - spec/usecasing_generator_spec.rb