poro-rails 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e61370f0517e5bc901163403d8df618537c45902a27cc8e0b1719d5f2319901e
4
+ data.tar.gz: 7d03959dda8e873142976982cb710e159df8d5bcdf64b18aa41837c2047efa64
5
+ SHA512:
6
+ metadata.gz: db1d20a36a95b987d56ca16b016f369f0e172f1f8c34f0ca2e3d660e42c711406fe6eb2872d166f189e5a8850fc2cd4a9de712f66d8337e9bfa3acc71bfdfb9c
7
+ data.tar.gz: 4e7b01940f411c2e530127d3735f1c041f74f3877c242afc4ecde8966fdf82377f2c29905a460bb98f9a2576feadc37f00484193571be526a6f1b5a18f7321f3
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /tmp/
8
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in poro-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yoshiyuki Hirano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ # poro-rails
2
+
3
+ This gem provides generators of **Plain Old Ruby Object** (PORO), **Form Object** and **Service Object** for Ruby on Rails.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'poro-rails', group: :development
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install poro-rails
18
+
19
+ ## Usage
20
+
21
+ ### Plain Old Ruby Object
22
+
23
+ Generate poro via command line:
24
+
25
+ $ rails g poro Person
26
+ create app/models/person.rb
27
+ invoke test_unit
28
+ create test/models/person_test.rb
29
+
30
+ These files are created (if it use RSpec in your project, it creates a spec file):
31
+
32
+ ```ruby
33
+ # app/models/person.rb
34
+ class Person
35
+ # include ActiveModel::Model
36
+ end
37
+
38
+ # test/models/person_test.rb
39
+ require 'test_helper'
40
+
41
+ class PersonTest < ActiveSupport::TestCase
42
+ # test "the truth" do
43
+ # assert true
44
+ # end
45
+ end
46
+ ```
47
+
48
+ ### Form Object
49
+
50
+ Generate poro via command line:
51
+
52
+ $ rails g poro:form create_user
53
+ create app/forms/create_user_form.rb
54
+ invoke test_unit
55
+ create test/forms/create_user_form_test.rb
56
+
57
+ These files are created (if it use RSpec in your project, it creates a spec file):
58
+
59
+ ```ruby
60
+ # app/forms/create_user_form.rb
61
+ class CreateUserForm
62
+ # include ActiveModel::Model
63
+ end
64
+
65
+ # test/forms/create_user_form_test.rb
66
+ require 'test_helper'
67
+
68
+ class CreateUserFormTest < ActiveSupport::TestCase
69
+ # test "the truth" do
70
+ # assert true
71
+ # end
72
+ end
73
+ ```
74
+
75
+ ### Service Object
76
+
77
+ Generate poro via command line:
78
+
79
+ $ bin/rails g poro:service create_payment
80
+ create app/services/create_payment_service.rb
81
+ invoke test_unit
82
+ create test/services/create_payment_service_test.rb
83
+
84
+ These files are created (if it use RSpec in your project, it creates a spec file):
85
+
86
+ ```ruby
87
+ # app/services/create_payment_service.rb
88
+ class CreatePaymentService
89
+ # include ActiveModel::Model
90
+ end
91
+
92
+ # test/services/create_payment_service_test.rb
93
+ require 'test_helper'
94
+
95
+ class CreatePaymentServiceTest < ActiveSupport::TestCase
96
+ # test "the truth" do
97
+ # assert true
98
+ # end
99
+ end
100
+ ```
101
+
102
+ ## License
103
+
104
+ [MIT](https://opensource.org/licenses/MIT)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a form object with the given name.
3
+
4
+ Example:
5
+ rails generate poro:form create_article
6
+
7
+ This will create:
8
+ app/forms/create_article_form.rb
@@ -0,0 +1,22 @@
1
+ module Poro
2
+ class FormGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path("templates", __dir__)
4
+ check_class_collision suffix: "Form"
5
+
6
+ def create_form
7
+ template "form.rb.tt", File.join("app/forms", class_path, "#{file_name}_form.rb")
8
+ end
9
+
10
+ hook_for :test_framework
11
+
12
+ private
13
+
14
+ def file_name
15
+ @_file_name ||= remove_possible_suffix(super)
16
+ end
17
+
18
+ def remove_possible_suffix(name)
19
+ name.sub(/_?form$/i, "")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Form
3
+ # include ActiveModel::Model
4
+ end
5
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a service object with the given name.
3
+
4
+ Example:
5
+ rails generate poro:service create_article
6
+
7
+ This will create:
8
+ app/forms/create_article_service.rb
@@ -0,0 +1,22 @@
1
+ module Poro
2
+ class ServiceGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path("templates", __dir__)
4
+ check_class_collision suffix: "Service"
5
+
6
+ def create_service
7
+ template "service.rb.tt", File.join("app/services", class_path, "#{file_name}_service.rb")
8
+ end
9
+
10
+ hook_for :test_framework
11
+
12
+ private
13
+
14
+ def file_name
15
+ @_file_name ||= remove_possible_suffix(super)
16
+ end
17
+
18
+ def remove_possible_suffix(name)
19
+ name.sub(/_?service$/i, "")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Service
3
+ # include ActiveModel::Model
4
+ end
5
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a plain old ruby object with the given name.
3
+
4
+ Example:
5
+ rails generate poro employee
6
+
7
+ This will create:
8
+ app/models/employee.rb
@@ -0,0 +1,13 @@
1
+ module Rails
2
+ module Generators
3
+ class PoroGenerator < NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def create_model
7
+ template "model.rb.tt", File.join("app/models", class_path, "#{file_name}.rb")
8
+ end
9
+
10
+ hook_for :test_framework
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>
3
+ # include ActiveModel::Model
4
+ end
5
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ module Rspec
2
+ module Generators
3
+ class FormGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def create_test_file
7
+ template 'form_spec.rb.tt', File.join('spec/forms', class_path, "#{file_name}_form_spec.rb")
8
+ end
9
+
10
+ private
11
+
12
+ def file_name
13
+ @_file_name ||= remove_possible_suffix(super)
14
+ end
15
+
16
+ def remove_possible_suffix(name)
17
+ name.sub(/_?form$/i, "")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Rspec
2
+ module Generators
3
+ class PoroGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def create_test_file
7
+ template 'model_spec.rb.tt', File.join('spec/models', class_path, "#{file_name}_spec.rb")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Rspec
2
+ module Generators
3
+ class ServiceGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def create_test_file
7
+ template 'service_spec.rb.tt', File.join('spec/services', class_path, "#{file_name}_service_spec.rb")
8
+ end
9
+
10
+ private
11
+
12
+ def file_name
13
+ @_file_name ||= remove_possible_suffix(super)
14
+ end
15
+
16
+ def remove_possible_suffix(name)
17
+ name.sub(/_?service$/i, "")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe <%= class_name %>Form, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe <%= class_name %>, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe <%= class_name %>Service, type: :model do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,22 @@
1
+ module TestUnit
2
+ module Generators
3
+ class FormGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+ check_class_collision suffix: "FormTest"
6
+
7
+ def create_test_file
8
+ template 'form_test.rb.tt', File.join('test/forms', class_path, "#{file_name}_form_test.rb")
9
+ end
10
+
11
+ private
12
+
13
+ def file_name
14
+ @_file_name ||= remove_possible_suffix(super)
15
+ end
16
+
17
+ def remove_possible_suffix(name)
18
+ name.sub(/_?form$/i, "")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module TestUnit
2
+ module Generators
3
+ class PoroGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+ check_class_collision suffix: "Test"
6
+
7
+ def create_test_file
8
+ template 'model_test.rb.tt', File.join('test/models', class_path, "#{file_name}_test.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ module TestUnit
2
+ module Generators
3
+ class ServiceGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+ check_class_collision suffix: "ServiceTest"
6
+
7
+ def create_test_file
8
+ template 'service_test.rb.tt', File.join('test/services', class_path, "#{file_name}_service_test.rb")
9
+ end
10
+
11
+ private
12
+
13
+ def file_name
14
+ @_file_name ||= remove_possible_suffix(super)
15
+ end
16
+
17
+ def remove_possible_suffix(name)
18
+ name.sub(/_?service$/i, "")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>FormTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>Test < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>ServiceTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("./lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'poro-rails'
8
+ s.version = '0.1.0'
9
+ s.authors = ['Yoshiyuki Hirano']
10
+ s.email = ['yhirano@me.com']
11
+ s.homepage = 'https://github.com/yhirano55/poro-rails'
12
+ s.summary = %(Simple Rails Generators for Plain Old Ruby Object, Form Object, and Service Object)
13
+ s.description = %(This gem provides generators of Plain Old Ruby Object, Form Object, and Service Object for Ruby on Rails.)
14
+ s.license = 'MIT'
15
+ s.files = Dir.chdir(File.expand_path('.', __dir__)) do
16
+ `git ls-files -z`.split("\x0")
17
+ end
18
+ s.require_paths = ['lib']
19
+
20
+ s.required_ruby_version = '>= 2.2.2'
21
+ s.required_rubygems_version = '>= 1.8.11'
22
+
23
+ s.add_development_dependency 'bundler', '~> 2.0'
24
+ s.add_development_dependency 'rake', '~> 10.0'
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poro-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiyuki Hirano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This gem provides generators of Plain Old Ruby Object, Form Object, and
42
+ Service Object for Ruby on Rails.
43
+ email:
44
+ - yhirano@me.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/generators/poro/form/USAGE
55
+ - lib/generators/poro/form/form_generator.rb
56
+ - lib/generators/poro/form/templates/form.rb.tt
57
+ - lib/generators/poro/service/USAGE
58
+ - lib/generators/poro/service/service_generator.rb
59
+ - lib/generators/poro/service/templates/service.rb.tt
60
+ - lib/generators/rails/USAGE
61
+ - lib/generators/rails/poro_generator.rb
62
+ - lib/generators/rails/templates/model.rb.tt
63
+ - lib/generators/rspec/form_generator.rb
64
+ - lib/generators/rspec/poro_generator.rb
65
+ - lib/generators/rspec/service_generator.rb
66
+ - lib/generators/rspec/templates/form_spec.rb.tt
67
+ - lib/generators/rspec/templates/model_spec.rb.tt
68
+ - lib/generators/rspec/templates/service_spec.rb.tt
69
+ - lib/generators/test_unit/form_generator.rb
70
+ - lib/generators/test_unit/poro_generator.rb
71
+ - lib/generators/test_unit/service_generator.rb
72
+ - lib/generators/test_unit/templates/form_test.rb.tt
73
+ - lib/generators/test_unit/templates/model_test.rb.tt
74
+ - lib/generators/test_unit/templates/service_test.rb.tt
75
+ - poro-rails.gemspec
76
+ homepage: https://github.com/yhirano55/poro-rails
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.2.2
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.11
94
+ requirements: []
95
+ rubygems_version: 3.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simple Rails Generators for Plain Old Ruby Object, Form Object, and Service
99
+ Object
100
+ test_files: []