pattern_bibz 1.1.1 → 1.2.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: 0f5369152845fdbc8e19d533e3f1e98f405d3f68be7bdd37b382e2735dbb673b
4
- data.tar.gz: e749aef193207c6b23c631fcc7b4ff953a4721dd5316641de57ff5937f38bf13
3
+ metadata.gz: 63ef2dd25ecafa1a440a5cea23aa56cc891d9d8d1bb976f52cd15f30991dde76
4
+ data.tar.gz: 19ea38ad79649ef5335c83a882ca35931b247505815e1ede3c7eff6afa6c8c7d
5
5
  SHA512:
6
- metadata.gz: e352d8e9227f4a69702fa680b13253057674120b068c648c271623b8854d3cbb21e5c48b5691f2629d6c36d6b70978c1f71457f6fa8ccbb671bb31c656ac1e49
7
- data.tar.gz: 30a166020233dbe7c379445e95ec299dc99292ad84a130c9d5eb75af91b53da84e572ae2837606817f887493e581a3741246470b31630706b517f4a146d0a7df
6
+ metadata.gz: 6feb0d2cac2758df18c2e475a7061e8ffb3a9d97fe237fe561325d4cfd34203278cdcc05f93f8c5698c5d08515c09a483898c3657b027aeede77e52d4d4c2513
7
+ data.tar.gz: 7e0c469ea4a7a345d1b33c7151ca2e2c47e9939c8cd2418b8e31910054b202f535fdf90fa282647a7bdb099490a8649d93929350fe4ed613e376d07c2c284180
data/README.md CHANGED
@@ -1,53 +1,64 @@
1
1
  # PatternBibz
2
+
2
3
  Rails Ruby Pattern Generator.
3
4
  This gem allows to generate your design pattern through the ralis generator.
4
5
 
5
6
  ## Usage
7
+
6
8
  ```bash
7
9
  rails generate pattern PATTERN_NAME
8
10
  ```
9
11
 
10
12
  ## Example
13
+
11
14
  ```bash
12
15
  rails generate pattern MyCustomDecorator
13
16
  ```
14
17
 
15
- This will create:
18
+ Files will be created:
19
+
16
20
  app/decorators/application_decorator.rb
17
21
  app/decorators/my_custom_decorator.rb
18
22
  test/decorators/application_decoratior_test.rb
19
23
  test/decorators/my_custom_decorator_test.rb
20
24
 
21
25
  ## Installation
26
+
22
27
  Add this line to your application's Gemfile:
23
28
 
24
29
  ```ruby
25
- gem 'pattern_bibz'
30
+ gem 'pattern_bibz', group: :development
26
31
  ```
27
32
 
28
33
  And then execute:
34
+
29
35
  ```bash
30
36
  $ bundle
31
37
  ```
32
38
 
33
39
  Or install it yourself as:
40
+
34
41
  ```bash
35
42
  $ gem install pattern_bibz
36
43
  ```
37
44
 
38
45
  ## Utils
39
46
  To extend your Rails model generator:
47
+
40
48
  ```bash
41
49
  rails g pattern_bibz:extend_model
42
50
  ```
43
51
 
44
52
  Then you can generate your model:
53
+
45
54
  ```bash
46
55
  rails g model MyModel title:string ...
47
56
  ```
48
57
 
49
58
  ## Contributing
59
+
50
60
  Contribution directions go here.
51
61
 
52
62
  ## License
63
+
53
64
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -3,42 +3,42 @@ class PatternGenerator < Rails::Generators::NamedBase
3
3
  source_root File.expand_path('templates', __dir__)
4
4
 
5
5
  def create_application_pattern_file
6
- @pattern_name = file_name.split('_').last
7
- application_file_name = "app/#{@pattern_name.pluralize}/application_#{@pattern_name}.rb"
6
+ @pattern_value_object = PatternValueObject.new(file_name)
7
+ application_file_name = "app/#{@pattern_value_object.directory_name}/application_#{@pattern_value_object.pattern_name}.rb"
8
8
 
9
9
  return if File.exist?(application_file_name)
10
10
 
11
11
  create_file application_file_name, <<~FILE
12
- class Application#{@pattern_name.titleize}
12
+ class Application#{@pattern_value_object.pattern_klass_name}
13
13
  end
14
14
  FILE
15
15
  end
16
16
 
17
17
  def create_app_pattern_file
18
- create_file "app/#{@pattern_name.pluralize}/#{file_name}.rb", <<~FILE
19
- class #{class_name} < Application#{@pattern_name.titleize}
18
+ create_file "app/#{@pattern_value_object.directory_name}/#{@pattern_value_object.file_name}.rb", <<~FILE
19
+ class #{@pattern_value_object.klass_name} < Application#{@pattern_value_object.pattern_klass_name}
20
20
  end
21
21
  FILE
22
22
  end
23
23
 
24
24
  def create_test_application_pattern_file
25
- application_file_name = "test/#{@pattern_name.pluralize}/application_#{@pattern_name}_test.rb"
25
+ application_file_name = "test/#{@pattern_value_object.directory_name}/application_#{@pattern_value_object.pattern_name}_test.rb"
26
26
 
27
27
  return if File.exist?(application_file_name)
28
28
 
29
29
  create_file application_file_name, <<~FILE
30
30
  require 'test_helper'
31
31
 
32
- class Application#{@pattern_name.titleize}Test < ActiveSupport::TestCase
32
+ class Application#{@pattern_value_object.pattern_klass_name}Test < ActiveSupport::TestCase
33
33
  end
34
34
  FILE
35
35
  end
36
36
 
37
37
  def create_test_pattern_file
38
- create_file "test/#{@pattern_name.pluralize}/#{file_name}_test.rb", <<~FILE
38
+ create_file "test/#{@pattern_value_object.directory_name}/#{@pattern_value_object.file_name}_test.rb", <<~FILE
39
39
  require 'test_helper'
40
40
 
41
- class #{class_name}Test < ActiveSupport::TestCase
41
+ class #{@pattern_value_object.klass_name}Test < ActiveSupport::TestCase
42
42
  end
43
43
  FILE
44
44
  end
@@ -1,3 +1,3 @@
1
1
  module PatternBibz
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -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.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas HUMMEL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-21 00:00:00.000000000 Z
11
+ date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -91,6 +91,7 @@ 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