natra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +4 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +14 -0
  8. data/Gemfile.lock +167 -0
  9. data/Guardfile +75 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +60 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +6 -0
  14. data/bin/natra +7 -0
  15. data/bin/setup +6 -0
  16. data/lib/extensions/string.rb +37 -0
  17. data/lib/natra.rb +9 -0
  18. data/lib/natra/cli.rb +20 -0
  19. data/lib/natra/generators/app/app_generator.rb +150 -0
  20. data/lib/natra/generators/app/templates/Dockerfile +24 -0
  21. data/lib/natra/generators/app/templates/Gemfile +35 -0
  22. data/lib/natra/generators/app/templates/Guardfile +20 -0
  23. data/lib/natra/generators/app/templates/README.md +52 -0
  24. data/lib/natra/generators/app/templates/Rakefile +4 -0
  25. data/lib/natra/generators/app/templates/app/controllers/application_controller.rb +14 -0
  26. data/lib/natra/generators/app/templates/app/models/.gitkeep +0 -0
  27. data/lib/natra/generators/app/templates/app/views/layout.erb.tt +20 -0
  28. data/lib/natra/generators/app/templates/app/views/welcome.erb +22 -0
  29. data/lib/natra/generators/app/templates/bin/ci +6 -0
  30. data/lib/natra/generators/app/templates/bin/setup +7 -0
  31. data/lib/natra/generators/app/templates/config.ru +11 -0
  32. data/lib/natra/generators/app/templates/config/db.yml +35 -0
  33. data/lib/natra/generators/app/templates/config/environment.rb +19 -0
  34. data/lib/natra/generators/app/templates/config/initializers/database.rb +11 -0
  35. data/lib/natra/generators/app/templates/config/initializers/oj.rb +5 -0
  36. data/lib/natra/generators/app/templates/config/initializers/redis.rb +7 -0
  37. data/lib/natra/generators/app/templates/config/puma.rb +11 -0
  38. data/lib/natra/generators/app/templates/config/redis.yml +14 -0
  39. data/lib/natra/generators/app/templates/docker-compose.yml +22 -0
  40. data/lib/natra/generators/app/templates/gitignore +12 -0
  41. data/lib/natra/generators/app/templates/public/favicon.ico +0 -0
  42. data/lib/natra/generators/app/templates/public/images/.gitkeep +0 -0
  43. data/lib/natra/generators/app/templates/public/images/corneal-small.png +0 -0
  44. data/lib/natra/generators/app/templates/public/javascripts/.gitkeep +0 -0
  45. data/lib/natra/generators/app/templates/public/stylesheets/main.css +115 -0
  46. data/lib/natra/generators/app/templates/rspec +2 -0
  47. data/lib/natra/generators/app/templates/rubocop.yml +79 -0
  48. data/lib/natra/generators/app/templates/secrets.env +16 -0
  49. data/lib/natra/generators/app/templates/spec/application_controller_spec.rb +13 -0
  50. data/lib/natra/generators/app/templates/spec/spec_helper.rb +36 -0
  51. data/lib/natra/generators/controller/controller_generator.rb +37 -0
  52. data/lib/natra/generators/controller/templates/controller.rb.erb +37 -0
  53. data/lib/natra/generators/controller/templates/views/edit.html.erb +1 -0
  54. data/lib/natra/generators/controller/templates/views/index.html.erb +1 -0
  55. data/lib/natra/generators/controller/templates/views/new.html.erb +1 -0
  56. data/lib/natra/generators/controller/templates/views/show.html.erb +1 -0
  57. data/lib/natra/generators/model/migration.rb.erb +10 -0
  58. data/lib/natra/generators/model/model.rb.erb +2 -0
  59. data/lib/natra/generators/model/model_generator.rb +59 -0
  60. data/lib/natra/generators/scaffold/scaffold_generator.rb +22 -0
  61. data/lib/natra/version.rb +3 -0
  62. data/natra.gemspec +41 -0
  63. metadata +180 -0
@@ -0,0 +1,37 @@
1
+ require "thor/group"
2
+ require "active_support/inflector"
3
+
4
+ module Natra
5
+ module Generators
6
+ class ControllerGenerator < Thor::Group
7
+ include Thor::Actions
8
+ attr_reader :controller_name, :class_name, :file_name
9
+
10
+ desc "Generate an Controller with associated views"
11
+ argument :name, type: :string, desc: "Name of the controller"
12
+
13
+ # --no-views make views optional
14
+ class_option :views, type: :boolean, default: true, desc: "Generate views for controller"
15
+
16
+ def self.source_root
17
+ File.dirname(__FILE__)
18
+ end
19
+
20
+ def setup
21
+ @controller_name = name.pluralize.underscore
22
+ @class_name = "#{controller_name.camel_case}Controller"
23
+ @file_name = class_name.underscore
24
+ end
25
+
26
+ def create_controller
27
+ template "templates/controller.rb.erb", File.join("app/controllers", "#{file_name}.rb")
28
+ insert_into_file "config.ru", "use #{class_name}\n", after: "run ApplicationController\n"
29
+ end
30
+
31
+ def create_views
32
+ return unless options[:views]
33
+ directory "templates/views", File.join("app/views", "#{controller_name}")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ class <%= class_name %> < ApplicationController
2
+
3
+ # GET: /<%= controller_name %>
4
+ get "/<%= controller_name %>" do
5
+ erb :"/<%= controller_name %>/index.html"
6
+ end
7
+
8
+ # GET: /<%= controller_name %>/new
9
+ get "/<%= controller_name %>/new" do
10
+ erb :"/<%= controller_name %>/new.html"
11
+ end
12
+
13
+ # POST: /<%= controller_name %>
14
+ post "/<%= controller_name %>" do
15
+ redirect "/<%= controller_name %>"
16
+ end
17
+
18
+ # GET: /<%= controller_name %>/5
19
+ get "/<%= controller_name %>/:id" do
20
+ erb :"/<%= controller_name %>/show.html"
21
+ end
22
+
23
+ # GET: /<%= controller_name %>/5/edit
24
+ get "/<%= controller_name %>/:id/edit" do
25
+ erb :"/<%= controller_name %>/edit.html"
26
+ end
27
+
28
+ # PATCH: /<%= controller_name %>/5
29
+ patch "/<%= controller_name %>/:id" do
30
+ redirect "/<%= controller_name %>/:id"
31
+ end
32
+
33
+ # DELETE: /<%= controller_name %>/5/delete
34
+ delete "/<%= controller_name %>/:id/delete" do
35
+ redirect "/<%= controller_name %>"
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ <h1>Insert the form to edit an instance of your model here.</h1>
@@ -0,0 +1 @@
1
+ <h1>This is the Model's index page.</h1>
@@ -0,0 +1 @@
1
+ <h1>Insert the form to create a new instance of your model.</h1>
@@ -0,0 +1 @@
1
+ <h1>This is the show page for an individual instance of your model.</h1>
@@ -0,0 +1,10 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute[:type] %> :<%= attribute[:name] %>
6
+ <% end %>
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,59 @@
1
+ require "thor/group"
2
+ require "active_support/inflector"
3
+
4
+ module Natra
5
+ module Generators
6
+ class ModelGenerator < Thor::Group
7
+ include Thor::Actions
8
+ attr_reader :file_name, :class_name, :model_name, :migration_name, :migration_class_name, :table_name
9
+
10
+ desc "Generate an ActiveRecord model"
11
+ argument :name, type: :string, desc: "Name of the model"
12
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
13
+
14
+ # --no-migration make migrations optional
15
+ class_option :migration, type: :boolean, default: true, desc: "Generate migration for model"
16
+
17
+ def self.source_root
18
+ File.dirname(__FILE__)
19
+ end
20
+
21
+ def setup
22
+ @model_name = name.singularize
23
+ @class_name = model_name.camel_case
24
+ @file_name = model_name.underscore
25
+ @table_name = file_name.pluralize
26
+ @migration_name = "create_#{table_name}"
27
+ @migration_class_name = migration_name.camel_case
28
+
29
+ attributes.map! do |attribute|
30
+ field = attribute.split(":")
31
+ { name: field[0], type: field[1] || "string" }
32
+ end
33
+ end
34
+
35
+ def create_model
36
+ unless model_name == name
37
+ say "[WARNING] The model name '#{name}' was recognized as a plural, using the singular '#{model_name}' instead."
38
+ end
39
+
40
+ template "model.rb.erb", File.join("app/models", "#{file_name}.rb")
41
+ end
42
+
43
+ def create_migration
44
+ return unless options[:migration]
45
+
46
+ migration_files = Dir.entries("db/migrate").select { |path| !File.directory? path }
47
+
48
+ if duplicate = migration_files.find { |file| file.include?(migration_name) }
49
+ say_status :identical, "db/migrate/#{duplicate}", :blue
50
+ else
51
+ version = Time.now.utc.strftime("%Y%m%d%H%M%S")
52
+ migration_file_name = "#{version}_#{migration_name}.rb"
53
+
54
+ template "migration.rb.erb", File.join("db/migrate", migration_file_name)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,22 @@
1
+ require "thor/group"
2
+ require 'active_support/inflector'
3
+
4
+ module Natra
5
+ module Generators
6
+ class ScaffoldGenerator < Thor::Group
7
+ include Thor::Actions
8
+
9
+ desc "Generate an ActiveRecord model with it's associated views and controllers"
10
+ argument :name, type: :string, desc: "Name of the model"
11
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
12
+
13
+ def create_model
14
+ ModelGenerator.new([name, attributes]).invoke_all
15
+ end
16
+
17
+ def create_controller
18
+ ControllerGenerator.new([name]).invoke_all
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Natra
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'natra/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'natra'
9
+ spec.version = Natra::VERSION
10
+ spec.authors = ['Thiru Njuguna']
11
+ spec.email = ['uriht@outlook.com']
12
+
13
+ spec.summary = 'Natra generate a light weight sinatra application'
14
+ spec.description = 'Natra generate a light weight sinatra application.It is ideal for builing micro-services'
15
+ spec.homepage = 'https://github.com/thirunjuguna/natra'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/thirunjuguna/natra'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/thirunjuguna/natra'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.executables = ['natra']
35
+ spec.require_paths = ['lib']
36
+ spec.add_development_dependency 'bundler', '~> 1.16'
37
+ spec.add_development_dependency 'rake', '~> 0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_runtime_dependency('activesupport', '~> 5.0')
40
+ spec.add_runtime_dependency('thor', '~> 0.18')
41
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: natra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thiru Njuguna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-28 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.18'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.18'
83
+ description: Natra generate a light weight sinatra application.It is ideal for builing
84
+ micro-services
85
+ email:
86
+ - uriht@outlook.com
87
+ executables:
88
+ - natra
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".coveralls.yml"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - Guardfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/natra
105
+ - bin/setup
106
+ - lib/extensions/string.rb
107
+ - lib/natra.rb
108
+ - lib/natra/cli.rb
109
+ - lib/natra/generators/app/app_generator.rb
110
+ - lib/natra/generators/app/templates/Dockerfile
111
+ - lib/natra/generators/app/templates/Gemfile
112
+ - lib/natra/generators/app/templates/Guardfile
113
+ - lib/natra/generators/app/templates/README.md
114
+ - lib/natra/generators/app/templates/Rakefile
115
+ - lib/natra/generators/app/templates/app/controllers/application_controller.rb
116
+ - lib/natra/generators/app/templates/app/models/.gitkeep
117
+ - lib/natra/generators/app/templates/app/views/layout.erb.tt
118
+ - lib/natra/generators/app/templates/app/views/welcome.erb
119
+ - lib/natra/generators/app/templates/bin/ci
120
+ - lib/natra/generators/app/templates/bin/setup
121
+ - lib/natra/generators/app/templates/config.ru
122
+ - lib/natra/generators/app/templates/config/db.yml
123
+ - lib/natra/generators/app/templates/config/environment.rb
124
+ - lib/natra/generators/app/templates/config/initializers/database.rb
125
+ - lib/natra/generators/app/templates/config/initializers/oj.rb
126
+ - lib/natra/generators/app/templates/config/initializers/redis.rb
127
+ - lib/natra/generators/app/templates/config/puma.rb
128
+ - lib/natra/generators/app/templates/config/redis.yml
129
+ - lib/natra/generators/app/templates/docker-compose.yml
130
+ - lib/natra/generators/app/templates/gitignore
131
+ - lib/natra/generators/app/templates/public/favicon.ico
132
+ - lib/natra/generators/app/templates/public/images/.gitkeep
133
+ - lib/natra/generators/app/templates/public/images/corneal-small.png
134
+ - lib/natra/generators/app/templates/public/javascripts/.gitkeep
135
+ - lib/natra/generators/app/templates/public/stylesheets/main.css
136
+ - lib/natra/generators/app/templates/rspec
137
+ - lib/natra/generators/app/templates/rubocop.yml
138
+ - lib/natra/generators/app/templates/secrets.env
139
+ - lib/natra/generators/app/templates/spec/application_controller_spec.rb
140
+ - lib/natra/generators/app/templates/spec/spec_helper.rb
141
+ - lib/natra/generators/controller/controller_generator.rb
142
+ - lib/natra/generators/controller/templates/controller.rb.erb
143
+ - lib/natra/generators/controller/templates/views/edit.html.erb
144
+ - lib/natra/generators/controller/templates/views/index.html.erb
145
+ - lib/natra/generators/controller/templates/views/new.html.erb
146
+ - lib/natra/generators/controller/templates/views/show.html.erb
147
+ - lib/natra/generators/model/migration.rb.erb
148
+ - lib/natra/generators/model/model.rb.erb
149
+ - lib/natra/generators/model/model_generator.rb
150
+ - lib/natra/generators/scaffold/scaffold_generator.rb
151
+ - lib/natra/version.rb
152
+ - natra.gemspec
153
+ homepage: https://github.com/thirunjuguna/natra
154
+ licenses:
155
+ - MIT
156
+ metadata:
157
+ homepage_uri: https://github.com/thirunjuguna/natra
158
+ source_code_uri: https://github.com/thirunjuguna/natra
159
+ changelog_uri: https://github.com/thirunjuguna/natra
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.7.7
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Natra generate a light weight sinatra application
180
+ test_files: []