pattern_bibz 1.1.0 → 1.3.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c6cfc8859a8197a40c42f3f1161b11589b6992f809059dfea8f1e567ecb9306
|
4
|
+
data.tar.gz: 3e4763211f6fb1f60515dd7e283810c91592eaa3a4c0c26cb168e068b6933686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93fcbe366c8c9e64e556f83869bc5fdf334d9ec3c791b75207e206ee5ff0879785cd1f6cb1811540b9030e3d92d3bf2856295d8484d088cb89cfea7aadb32d0d
|
7
|
+
data.tar.gz: 63e2938de292423c38f52485621dc5be84a092dd8b4069108d7cbd342d152b2f92e866d2fd955ed31ae4045344981011019b28ba109255a7190f76886da04336
|
data/README.md
CHANGED
@@ -1,53 +1,90 @@
|
|
1
|
-
|
1
|
+

|
2
|
+
|
3
|
+
# Pattern Bibz
|
4
|
+
|
2
5
|
Rails Ruby Pattern Generator.
|
3
|
-
This gem allows to generate your design pattern through the
|
6
|
+
This gem allows to generate your design pattern through the rails generator.
|
7
|
+
|
8
|
+

|
4
9
|
|
5
10
|
## Usage
|
11
|
+
|
6
12
|
```bash
|
7
13
|
rails generate pattern PATTERN_NAME
|
8
14
|
```
|
9
15
|
|
10
16
|
## Example
|
17
|
+
|
11
18
|
```bash
|
12
19
|
rails generate pattern MyCustomDecorator
|
13
20
|
```
|
14
21
|
|
15
|
-
|
22
|
+
Files generated:
|
23
|
+
|
16
24
|
app/decorators/application_decorator.rb
|
17
25
|
app/decorators/my_custom_decorator.rb
|
18
26
|
test/decorators/application_decoratior_test.rb
|
19
27
|
test/decorators/my_custom_decorator_test.rb
|
20
28
|
|
21
29
|
## Installation
|
30
|
+
|
22
31
|
Add this line to your application's Gemfile:
|
23
32
|
|
24
33
|
```ruby
|
25
|
-
gem 'pattern_bibz'
|
34
|
+
gem 'pattern_bibz', group: :development
|
26
35
|
```
|
27
36
|
|
28
37
|
And then execute:
|
38
|
+
|
29
39
|
```bash
|
30
40
|
$ bundle
|
31
41
|
```
|
32
42
|
|
33
43
|
Or install it yourself as:
|
44
|
+
|
34
45
|
```bash
|
35
46
|
$ gem install pattern_bibz
|
36
47
|
```
|
37
48
|
|
38
49
|
## Utils
|
39
50
|
To extend your Rails model generator:
|
51
|
+
|
40
52
|
```bash
|
41
|
-
rails g pattern_bibz:extend_model
|
53
|
+
$ rails g pattern_bibz:extend_model
|
42
54
|
```
|
43
55
|
|
44
56
|
Then you can generate your model:
|
57
|
+
|
45
58
|
```bash
|
46
|
-
rails g model MyModel title:string ...
|
59
|
+
$ rails g model MyModel title:string ...
|
47
60
|
```
|
48
61
|
|
49
|
-
|
50
|
-
|
62
|
+
Your generated model will look like this:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# frozen_string_literal: true
|
66
|
+
|
67
|
+
class MyModel < ApplicationRecord
|
68
|
+
# Scopes
|
69
|
+
|
70
|
+
# Constants
|
71
|
+
|
72
|
+
# Callbacks
|
73
|
+
|
74
|
+
# Attr_accessors
|
75
|
+
|
76
|
+
# Associations
|
77
|
+
|
78
|
+
# Enums
|
79
|
+
|
80
|
+
# Validations
|
81
|
+
|
82
|
+
# Delegations
|
83
|
+
|
84
|
+
# Methods
|
85
|
+
end
|
86
|
+
```
|
51
87
|
|
52
88
|
## License
|
89
|
+
|
53
90
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,44 +1,46 @@
|
|
1
|
+
require 'value_objects/pattern_value_object'
|
2
|
+
|
1
3
|
# Generate template files and tests with a patten name
|
2
4
|
class PatternGenerator < Rails::Generators::NamedBase
|
3
5
|
source_root File.expand_path('templates', __dir__)
|
4
6
|
|
5
7
|
def create_application_pattern_file
|
6
|
-
@
|
7
|
-
application_file_name = "app/#{@
|
8
|
+
@pattern_value_object = PatternValueObject.new(file_name)
|
9
|
+
application_file_name = "app/#{@pattern_value_object.directory_name}/application_#{@pattern_value_object.pattern_name}.rb"
|
8
10
|
|
9
11
|
return if File.exist?(application_file_name)
|
10
12
|
|
11
13
|
create_file application_file_name, <<~FILE
|
12
|
-
class Application#{@
|
14
|
+
class Application#{@pattern_value_object.pattern_klass_name}
|
13
15
|
end
|
14
16
|
FILE
|
15
17
|
end
|
16
18
|
|
17
19
|
def create_app_pattern_file
|
18
|
-
create_file "app/#{@
|
19
|
-
class #{
|
20
|
+
create_file "app/#{@pattern_value_object.directory_name}/#{@pattern_value_object.file_name}.rb", <<~FILE
|
21
|
+
class #{@pattern_value_object.klass_name} < Application#{@pattern_value_object.pattern_klass_name}
|
20
22
|
end
|
21
23
|
FILE
|
22
24
|
end
|
23
25
|
|
24
26
|
def create_test_application_pattern_file
|
25
|
-
application_file_name = "test/#{@
|
27
|
+
application_file_name = "test/#{@pattern_value_object.directory_name}/application_#{@pattern_value_object.pattern_name}_test.rb"
|
26
28
|
|
27
29
|
return if File.exist?(application_file_name)
|
28
30
|
|
29
31
|
create_file application_file_name, <<~FILE
|
30
32
|
require 'test_helper'
|
31
33
|
|
32
|
-
class Application#{@
|
34
|
+
class Application#{@pattern_value_object.pattern_klass_name}Test < ActiveSupport::TestCase
|
33
35
|
end
|
34
36
|
FILE
|
35
37
|
end
|
36
38
|
|
37
39
|
def create_test_pattern_file
|
38
|
-
create_file "test/#{@
|
40
|
+
create_file "test/#{@pattern_value_object.directory_name}/#{@pattern_value_object.file_name}_test.rb", <<~FILE
|
39
41
|
require 'test_helper'
|
40
42
|
|
41
|
-
class #{
|
43
|
+
class #{@pattern_value_object.klass_name}Test < ActiveSupport::TestCase
|
42
44
|
end
|
43
45
|
FILE
|
44
46
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
class <%= class_name %> < <%= parent_class_name.classify %>
|
3
5
|
# Scopes
|
4
6
|
|
@@ -9,9 +11,9 @@ class <%= class_name %> < <%= parent_class_name.classify %>
|
|
9
11
|
# Attr_accessors
|
10
12
|
|
11
13
|
# Associations
|
12
|
-
<% attributes.select(&:reference?).each do |attribute
|
13
|
-
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic?
|
14
|
-
<% end
|
14
|
+
<% attributes.select(&:reference?).each do |attribute| -%>
|
15
|
+
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
|
16
|
+
<% end -%>
|
15
17
|
<% attributes.select(&:rich_text?).each do |attribute| -%>
|
16
18
|
has_rich_text :<%= attribute.name %>
|
17
19
|
<% end -%>
|
data/lib/pattern_bibz.rb
CHANGED
data/lib/pattern_bibz/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Fetch values from a pattern name
|
2
|
+
class PatternValueObject
|
3
|
+
COMPOUND_NAMES = %w[view_object value_object].freeze
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def pattern_name
|
10
|
+
@pattern_name ||= fetch_pattern_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def pattern_klass_name
|
14
|
+
pattern_name.classify.delete(' ')
|
15
|
+
end
|
16
|
+
|
17
|
+
def directory_name
|
18
|
+
pattern_name.pluralize
|
19
|
+
end
|
20
|
+
|
21
|
+
def file_name
|
22
|
+
@name
|
23
|
+
end
|
24
|
+
|
25
|
+
def klass_name
|
26
|
+
@name.classify.delete(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def fetch_pattern_name
|
32
|
+
if compound_name?
|
33
|
+
COMPOUND_NAMES.find { |a| @name.match?(a) }
|
34
|
+
else
|
35
|
+
@name.split('_').last
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def compound_name?
|
40
|
+
COMPOUND_NAMES.any? { |w| @name.match?(w) }
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pattern_bibz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas HUMMEL
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 6.0.2.2
|
23
|
-
type: :
|
23
|
+
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
@@ -91,12 +91,13 @@ files:
|
|
91
91
|
- lib/pattern_bibz/railtie.rb
|
92
92
|
- lib/pattern_bibz/version.rb
|
93
93
|
- lib/tasks/pattern_bibz_tasks.rake
|
94
|
+
- lib/value_objects/pattern_value_object.rb
|
94
95
|
homepage: http://thooams.github.io/pattern_bibz
|
95
96
|
licenses:
|
96
97
|
- MIT
|
97
98
|
metadata:
|
98
99
|
allowed_push_host: https://rubygems.org
|
99
|
-
post_install_message:
|
100
|
+
post_install_message:
|
100
101
|
rdoc_options: []
|
101
102
|
require_paths:
|
102
103
|
- lib
|
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
113
|
version: '0'
|
113
114
|
requirements: []
|
114
115
|
rubygems_version: 3.1.2
|
115
|
-
signing_key:
|
116
|
+
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: Rails Pattern generator
|
118
119
|
test_files: []
|