flame_generate_toys 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f70b8d15c44275615c33976ad441a5117b9b9fea37ce3a6bdd2bb832fc8cb41a
4
+ data.tar.gz: 935726d89f4e59c6d9460b0b37ec40f7f030f82e555ed4106f2bd39ebfdfcaf0
5
+ SHA512:
6
+ metadata.gz: dbaed3aa00b925353c1f67baaacb0fd433389c1983cba38e06b726f723dee376a5d963423d4aa98a685d5ad24cf73ab539e80ba2ebbc46ab3f78e0133860dd54
7
+ data.tar.gz: 65be66674932e319a94df940c233e9efe3f1c5830cf797463915485adcdd61def8bb29d4f5872cc32c420376556c508dac187610b2c9c3f4c86f908f2d99395a
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 0.5.0 (2020-09-25)
6
+
7
+ ## 0.4.0 (2020-09-24)
8
+
9
+ * Update `formalism-model_forms` to another fixed version.
10
+
11
+ ## 0.3.0 (2020-09-22)
12
+
13
+ * Update `formalism-model_forms` to fixed version.
14
+
15
+ ## 0.2.0 (2020-08-23)
16
+
17
+ * Update `toys`.
18
+
19
+ ## 0.1.0 (2020-07-13)
20
+
21
+ * Initial release.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alexander Popov
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,60 @@
1
+ # Flame Generate Toys
2
+
3
+ [![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/flame_generate_toys?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/flame_generate_toys)
4
+ [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/flame_generate_toys/master.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/flame_generate_toys)
5
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/flame_generate_toys.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/flame_generate_toys)
6
+ [![Depfu](https://img.shields.io/depfu/AlexWayfer/benchmark_toys?style=flat-square)](https://depfu.com/repos/github/AlexWayfer/flame_generate_toys)
7
+ [![Inline docs](https://inch-ci.org/github/AlexWayfer/flame_generate_toys.svg?branch=master)](https://inch-ci.org/github/AlexWayfer/flame_generate_toys)
8
+ [![license](https://img.shields.io/github/license/AlexWayfer/flame_generate_toys.svg?style=flat-square)](https://github.com/AlexWayfer/flame_generate_toys/blob/master/LICENSE.txt)
9
+ [![Gem](https://img.shields.io/gem/v/flame_generate_toys.svg?style=flat-square)](https://rubygems.org/gems/flame_generate_toys)
10
+
11
+ Toys template to generate [Flame](https://github.com/AlexWayfer/flame)
12
+ application entities.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'flame_generate_toys'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```shell
25
+ bundle install
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```shell
31
+ gem install flame_generate_toys
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```ruby
37
+ # `:namespace` is using for `module MyProject` in files
38
+ require 'flame_generate_toys'
39
+ expand FlameGenerateToys::Template, namespace: MyProject
40
+ ```
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bundle install` to install dependencies.
45
+
46
+ Then, run `toys rspec` to run the tests.
47
+
48
+ To install this gem onto your local machine, run `toys gem install`.
49
+
50
+ To release a new version, run `toys gem release %version%`.
51
+ See how it works [here](https://github.com/AlexWayfer/gem_toys#release).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/flame_generate_toys).
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the
60
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'flame_generate_toys/template'
4
+ require_relative 'flame_generate_toys/version'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'toys-core'
4
+
5
+ module FlameGenerateToys
6
+ ## Define toys for generation entities
7
+ class Template
8
+ include Toys::Template
9
+
10
+ attr_reader :namespace
11
+
12
+ def initialize(namespace:)
13
+ @namespace = namespace
14
+ end
15
+
16
+ on_expand do |template|
17
+ tool :generate do
18
+ require_relative 'template/_base'
19
+
20
+ require_relative 'template/form'
21
+ expand Template::Form, namespace: template.namespace
22
+
23
+ require_relative 'template/model'
24
+ expand Template::Model, namespace: template.namespace
25
+ end
26
+
27
+ alias_tool :gen, :generate
28
+ alias_tool :g, :generate
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlameGenerateToys
4
+ class Template
5
+ ## Base template for entities generation
6
+ class Base
7
+ include Toys::Template
8
+
9
+ attr_reader :namespace
10
+
11
+ def initialize(namespace:)
12
+ @namespace = namespace
13
+ end
14
+
15
+ # private
16
+
17
+ ## Common code for generators
18
+ module CommonGeneratorsCode
19
+ def initialize_generator(type, namespace)
20
+ require_relative 'generator'
21
+
22
+ Generator.new(type, name, namespace, context_directory)
23
+ end
24
+ end
25
+
26
+ private_constant :CommonGeneratorsCode
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlameGenerateToys
4
+ class Template
5
+ ## Define toys for form generation
6
+ class Form < Base
7
+ on_expand do |template|
8
+ tool :form do
9
+ desc 'Generate form'
10
+
11
+ include CommonGeneratorsCode
12
+
13
+ required_arg :name
14
+
15
+ to_run do
16
+ generator = initialize_generator :form, template.namespace
17
+
18
+ *modules, class_name = generator.camelized_name.split('::')
19
+
20
+ generator.write(
21
+ modules: modules,
22
+ class_name: class_name,
23
+ class_indentation: "\t" * modules.size,
24
+ parent_form: parent_form(class_name)
25
+ )
26
+ end
27
+
28
+ private
29
+
30
+ def parent_form(class_name)
31
+ require 'formalism/model_forms'
32
+
33
+ Formalism::ModelForms.const_defined?(class_name, false) ? class_name : 'Base'
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= namespace %>
4
+ module Forms<%
5
+ modules.map.with_index do |module_name, index|
6
+ %>
7
+ <%= "\t" * index %>module <%= module_name
8
+ %><%
9
+ end
10
+ %>
11
+ <%=
12
+ class_indentation
13
+ %>class <%= class_name %> < Forms::Model::<%= parent_form %>
14
+ <%=
15
+ class_indentation
16
+ %>end<%
17
+ modules.map.with_index do |_module_name, index|
18
+ reverse_index = modules.size - index.next
19
+ %>
20
+ <%= "\t" * reverse_index %>end<%
21
+ end
22
+ %>
23
+ end
24
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'gorilla_patch/inflections'
5
+
6
+ module FlameGenerateToys
7
+ class Template
8
+ ## Class for code generation
9
+ class Generator
10
+ class << self
11
+ def template(type)
12
+ (@templates ||= {})[type] ||=
13
+ ERB.new File.read "#{__dir__}/#{type}/template.rb.erb"
14
+ end
15
+ end
16
+
17
+ attr_reader :camelized_name
18
+
19
+ using GorillaPatch::Inflections.from_dry_inflector
20
+
21
+ def initialize(type, name, namespace, context_directory)
22
+ @template = self.class.template(type)
23
+
24
+ @camelized_name = name.camelize
25
+
26
+ @namespace = namespace
27
+
28
+ @relative_file_path = "#{type.to_s.pluralize}/#{name}.rb"
29
+
30
+ @file_path = "#{context_directory}/#{@relative_file_path}"
31
+ return unless File.exist?(@file_path)
32
+
33
+ raise ArgumentError, "File #{name} already exists"
34
+ end
35
+
36
+ def write(**locals)
37
+ FileUtils.mkdir_p File.dirname @file_path
38
+ File.write @file_path, @template.result_with_hash(
39
+ camelized_name: camelized_name,
40
+ namespace: @namespace,
41
+ **locals
42
+ )
43
+
44
+ puts "#{@relative_file_path} created"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlameGenerateToys
4
+ class Template
5
+ ## Define toys for form generation
6
+ class Model < Base
7
+ on_expand do |template|
8
+ tool :model do
9
+ desc 'Generate model'
10
+
11
+ include CommonGeneratorsCode
12
+
13
+ required_arg :name
14
+
15
+ to_run do
16
+ initialize_generator(:model, template.namespace).write
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= namespace %>
4
+ module Models
5
+ class <%= camelized_name %> < Sequel::Model
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlameGenerateToys
4
+ VERSION = '0.5.0'
5
+ end
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flame_generate_toys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Popov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-inflector
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: formalism-model_forms
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: toys-core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.11.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gem_toys
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: toys
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.11.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.11.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: codecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.2.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.2.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.19.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.19.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.91.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.91.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-performance
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-rspec
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.0'
195
+ description: 'Toys template to generate Flame application entities.
196
+
197
+ '
198
+ email:
199
+ - alex.wayfer@gmail.com
200
+ executables: []
201
+ extensions: []
202
+ extra_rdoc_files: []
203
+ files:
204
+ - CHANGELOG.md
205
+ - LICENSE.txt
206
+ - README.md
207
+ - lib/flame_generate_toys.rb
208
+ - lib/flame_generate_toys/template.rb
209
+ - lib/flame_generate_toys/template/_base.rb
210
+ - lib/flame_generate_toys/template/form.rb
211
+ - lib/flame_generate_toys/template/form/template.rb.erb
212
+ - lib/flame_generate_toys/template/generator.rb
213
+ - lib/flame_generate_toys/template/model.rb
214
+ - lib/flame_generate_toys/template/model/template.rb.erb
215
+ - lib/flame_generate_toys/version.rb
216
+ homepage: https://github.com/AlexWayfer/flame_generate_toys
217
+ licenses:
218
+ - MIT
219
+ metadata:
220
+ source_code_uri: https://github.com/AlexWayfer/flame_generate_toys
221
+ homepage_uri: https://github.com/AlexWayfer/flame_generate_toys
222
+ changelog_uri: https://github.com/AlexWayfer/flame_generate_toys/blob/master/CHANGELOG.md
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '2.5'
232
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ requirements: []
238
+ rubygems_version: 3.1.2
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: Toys template to generate Flame application entities.
242
+ test_files: []