pattern_bibz 1.0.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fe8d6514ef5de5b312c58f18a744eb8eaef8fbd0647f3fb3109816d4a30396e
4
- data.tar.gz: 021efc4f47bc1b8134c668c261092661abbecd38b44e2c9c0900691a0efb9b86
3
+ metadata.gz: 9f27df1aa1b5024ff5eadf58880c66c6bd622da57ff330e9303b6af0c9ab85b9
4
+ data.tar.gz: ffe72e70df624fe6a7394c4f67fbaa8f9ac7ecc8b4f260b6067938fc3c52ebc6
5
5
  SHA512:
6
- metadata.gz: ad8fc41cbd8aeab76cf96740fd80b620aca8aa5dc7ed9882b519581015b7e4757677b54aefa358f67334739970d3bc614e6763b8ac9b332f936b90da87ab1264
7
- data.tar.gz: 6a4c5ed8ef6869723bd944418e946dc97df9e5134cda9a4762b3e5f54c039919ec77a37c7dcfe0109f9efd2152eb6857463014cae42734ffd462f29de3da2798
6
+ metadata.gz: 5e5bb75f0b49e7efa7151560644da03639b05cef240cc77c5f2d1affc32d5a30af4db8c8b33e743664c5992e748351a43b42c6bf8886092ae989c34e949d071e
7
+ data.tar.gz: 77206e97d3e4ef2866a934ea58f2e4fca2fce1d41ff2ddb93d3a1f90af215045e9399c8e4187f2260aac10072923271599a8ac1f685c743fc6729aba4c6d9bb8
data/README.md CHANGED
@@ -1,42 +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
 
45
+ ## Utils
46
+ To extend your Rails model generator:
47
+
48
+ ```bash
49
+ rails g pattern_bibz:extend_model
50
+ ```
51
+
52
+ Then you can generate your model:
53
+
54
+ ```bash
55
+ rails g model MyModel title:string ...
56
+ ```
57
+
38
58
  ## Contributing
59
+
39
60
  Contribution directions go here.
40
61
 
41
62
  ## License
63
+
42
64
  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
- @pattern_name = file_name.split('_').last
7
- application_file_name = "app/#{@pattern_name.pluralize}/application_#{@pattern_name}.rb"
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#{@pattern_name.titleize}
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/#{@pattern_name.pluralize}/#{file_name}.rb", <<~FILE
19
- class #{class_name} < Application#{@pattern_name.titleize}
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/#{@pattern_name.pluralize}/application_#{@pattern_name}_test.rb"
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#{@pattern_name.titleize}Test < ActiveSupport::TestCase
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/#{@pattern_name.pluralize}/#{file_name}_test.rb", <<~FILE
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 #{class_name}Test < ActiveSupport::TestCase
43
+ class #{@pattern_value_object.klass_name}Test < ActiveSupport::TestCase
42
44
  end
43
45
  FILE
44
46
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ module PatternBibz
5
+ module Generators
6
+ # Extend the Rails model generator
7
+ class ExtendModelGenerator < ::Rails::Generators::Base
8
+ source_root File.expand_path('templates', __dir__)
9
+ desc 'Extend Rails Model generator'
10
+
11
+ def copy_initializer
12
+ directory File.join(File.dirname(__dir__), 'pattern_bibz/templates'),
13
+ Rails.root.join('lib/templates/active_record/model'), mode: :preserve
14
+
15
+ puts 'Install complete in lib/templates/active_record/model.rb'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %> < <%= parent_class_name.classify %>
3
+ # Scopes
4
+
5
+ # Constants
6
+
7
+ # Callbacks
8
+
9
+ # Attr_accessors
10
+
11
+ # Associations
12
+ <% attributes.select(&:reference?).each do |attribute| -%>
13
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
14
+ <% end -%>
15
+ <% attributes.select(&:rich_text?).each do |attribute| -%>
16
+ has_rich_text :<%= attribute.name %>
17
+ <% end -%>
18
+ <% attributes.select(&:attachment?).each do |attribute| -%>
19
+ has_one_attached :<%= attribute.name %>
20
+ <% end -%>
21
+ <% attributes.select(&:attachments?).each do |attribute| -%>
22
+ has_many_attached :<%= attribute.name %>
23
+ <% end -%>
24
+
25
+ # Enums
26
+
27
+ # Validations
28
+
29
+ # Delegations
30
+
31
+ # Methods
32
+ <% attributes.select(&:token?).each do |attribute| -%>
33
+ has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
34
+ <% end -%>
35
+ <% if attributes.any?(&:password_digest?) -%>
36
+ has_secure_password
37
+ <% end -%>
38
+ end
39
+ <% end -%>
@@ -1,5 +1,3 @@
1
1
  require "pattern_bibz/railtie"
2
2
 
3
- module PatternBibz
4
- # Your code goes here...
5
- end
3
+ module PatternBibz; end
@@ -1,3 +1,3 @@
1
1
  module PatternBibz
2
- VERSION = '1.0.0'
2
+ VERSION = '1.2.2'
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.0.0
4
+ version: 1.2.2
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-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -85,10 +85,13 @@ files:
85
85
  - Rakefile
86
86
  - lib/generators/pattern/USAGE
87
87
  - lib/generators/pattern/pattern_generator.rb
88
+ - lib/generators/pattern_bibz/extend_model_generator.rb
89
+ - lib/generators/pattern_bibz/templates/model.rb
88
90
  - lib/pattern_bibz.rb
89
91
  - lib/pattern_bibz/railtie.rb
90
92
  - lib/pattern_bibz/version.rb
91
93
  - lib/tasks/pattern_bibz_tasks.rake
94
+ - lib/value_objects/pattern_value_object.rb
92
95
  homepage: http://thooams.github.io/pattern_bibz
93
96
  licenses:
94
97
  - MIT