strum 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rakeTasks +7 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +25 -0
  6. data/CHANGELOG.md +1 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +71 -0
  9. data/README.md +35 -0
  10. data/Rakefile +8 -0
  11. data/bin/strum +5 -0
  12. data/lib/strum/Rakefile +6 -0
  13. data/lib/strum/cli.rb +37 -0
  14. data/lib/strum/command.rb +18 -0
  15. data/lib/strum/commands/generate.rb +33 -0
  16. data/lib/strum/commands/mixin/app_check.rb +21 -0
  17. data/lib/strum/commands/mixin/fields.rb +29 -0
  18. data/lib/strum/commands/mixin/names.rb +57 -0
  19. data/lib/strum/commands/new.rb +68 -0
  20. data/lib/strum/commands/resource/migration.rb +59 -0
  21. data/lib/strum/commands/resource/model.rb +31 -0
  22. data/lib/strum/commands/resource/route.rb +47 -0
  23. data/lib/strum/commands/resource/scaffold.rb +20 -0
  24. data/lib/strum/commands/resource/serializer.rb +31 -0
  25. data/lib/strum/commands/resource/service.rb +42 -0
  26. data/lib/strum/service.rb +116 -0
  27. data/lib/strum/sub_command_base.rb +18 -0
  28. data/lib/strum/tasks/sequel.rake +87 -0
  29. data/lib/strum/templates/app/blank/.env.local.tt +6 -0
  30. data/lib/strum/templates/app/blank/.env.test.tt +4 -0
  31. data/lib/strum/templates/app/blank/.gitignore +26 -0
  32. data/lib/strum/templates/app/blank/.rubocop.yml +28 -0
  33. data/lib/strum/templates/app/blank/Dockerfile +15 -0
  34. data/lib/strum/templates/app/blank/Gemfile.tt +68 -0
  35. data/lib/strum/templates/app/blank/Rakefile +8 -0
  36. data/lib/strum/templates/app/blank/bin/console.tt +15 -0
  37. data/lib/strum/templates/app/blank/config/app.rb.tt +60 -0
  38. data/lib/strum/templates/app/blank/config/env.rb +12 -0
  39. data/lib/strum/templates/app/blank/config.ru.tt +18 -0
  40. data/lib/strum/templates/app/blank/lib/.keep +0 -0
  41. data/lib/strum/templates/app/blank/routes/.keep +0 -0
  42. data/lib/strum/templates/app/blank/services/.keep +0 -0
  43. data/lib/strum/templates/app/json/serializers/.keep +0 -0
  44. data/lib/strum/templates/app/sequel/config/models.rb +18 -0
  45. data/lib/strum/templates/app/sequel/config/sequel.rb +10 -0
  46. data/lib/strum/templates/app/sequel/db/migrations/001_setup.rb +17 -0
  47. data/lib/strum/templates/app/sequel/models/.keep +0 -0
  48. data/lib/strum/templates/migration/%migration_filename%.rb.tt +27 -0
  49. data/lib/strum/templates/model/%resource_filename%.rb.tt +12 -0
  50. data/lib/strum/templates/route/%resource_filename%.rb.tt +9 -0
  51. data/lib/strum/templates/route_crud/%resource_filename%.rb.tt +44 -0
  52. data/lib/strum/templates/serializer/%resource_name%_serializer.rb.tt +17 -0
  53. data/lib/strum/templates/service/%resource_filename%.rb.tt +22 -0
  54. data/lib/strum/templates/service_crud/%resource_name%/create.rb.tt +28 -0
  55. data/lib/strum/templates/service_crud/%resource_name%/delete.rb.tt +27 -0
  56. data/lib/strum/templates/service_crud/%resource_name%/find.rb.tt +25 -0
  57. data/lib/strum/templates/service_crud/%resource_name%/search.rb.tt +23 -0
  58. data/lib/strum/templates/service_crud/%resource_name%/update.rb.tt +28 -0
  59. data/lib/strum/version.rb +5 -0
  60. data/lib/strum.rb +9 -0
  61. data/strum.gemspec +46 -0
  62. metadata +219 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8564c1b4cee7cb9226c7beaba0dbc32a9f39b731d177a0510ef3e00a68eacb0c
4
+ data.tar.gz: d0237c3b5aff99261d61bfabb044f01323b537b40ae0d786aa735bf903a17de4
5
+ SHA512:
6
+ metadata.gz: 68de1c7b0db5542040617f8eda848e4de15c446a9ce740225938038e9eeb58debddf88e564059ce9185201dac46f88863aae61e6dbd0d6193f0e7d991e6e0e78
7
+ data.tar.gz: fb54166c475d63f0f99e277afe9f553eced31387bcc9b895262a8d6ad4c1f232fbd301f35eed903a0d5271dff3ccf670db4a49fe6c14f1297f3da71a2575686f
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Editor directories and files
14
+ .idea
15
+ .vscode
16
+ *.suo
17
+ *.ntvs*
18
+ *.njsproj
19
+ *.sln
20
+ *.sw*
21
+
22
+ # builds
23
+ *.gem
data/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build strum-0.0.5.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install strum-0.0.5.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install strum-0.0.5.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.0.5 and build and push strum-0.0.5.gem to https://rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
5
+ Style/HashSyntax:
6
+ Enabled: true
7
+
8
+ # Method definitions after `private` or `protected` isolated calls need one
9
+ # extra level of indentation.
10
+ Layout/IndentationConsistency:
11
+ Enabled: true
12
+ EnforcedStyle: indented_internal_methods
13
+
14
+ # Two spaces, no tabs (for indentation).
15
+ Layout/IndentationWidth:
16
+ Enabled: true
17
+
18
+ # Check quotes usage according to lint rule below.
19
+ Style/StringLiterals:
20
+ Enabled: true
21
+ EnforcedStyle: double_quotes
22
+
23
+ Metrics/LineLength:
24
+ Max: 120
25
+ IgnoredPatterns: ['\A#']
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Strum
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in strum.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ strum (0.0.20)
5
+ dry-inflector (~> 0.2.0)
6
+ dry-matcher (~> 0.8.2)
7
+ thor (~> 0.20)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ coderay (1.1.2)
14
+ concurrent-ruby (1.1.5)
15
+ diff-lcs (1.3)
16
+ dry-core (0.4.9)
17
+ concurrent-ruby (~> 1.0)
18
+ dry-inflector (0.2.0)
19
+ dry-matcher (0.8.2)
20
+ dry-core (>= 0.4.8)
21
+ irb (1.1.0)
22
+ reline (>= 0.0.1)
23
+ jaro_winkler (1.5.4)
24
+ method_source (0.9.2)
25
+ parallel (1.19.0)
26
+ parser (2.6.5.0)
27
+ ast (~> 2.4.0)
28
+ pry (0.12.2)
29
+ coderay (~> 1.1.0)
30
+ method_source (~> 0.9.0)
31
+ rainbow (3.0.0)
32
+ rake (10.5.0)
33
+ reline (0.0.7)
34
+ rspec (3.9.0)
35
+ rspec-core (~> 3.9.0)
36
+ rspec-expectations (~> 3.9.0)
37
+ rspec-mocks (~> 3.9.0)
38
+ rspec-core (3.9.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-expectations (3.9.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-mocks (3.9.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-support (3.9.0)
47
+ rubocop (0.76.0)
48
+ jaro_winkler (~> 1.5.1)
49
+ parallel (~> 1.10)
50
+ parser (>= 2.6)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 1.4.0, < 1.7)
54
+ ruby-progressbar (1.10.1)
55
+ thor (0.20.3)
56
+ unicode-display_width (1.6.0)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.17)
63
+ irb
64
+ pry
65
+ rake (~> 10.0)
66
+ rspec (~> 3.0)
67
+ rubocop (~> 0.76.0)
68
+ strum!
69
+
70
+ BUNDLED WITH
71
+ 1.17.2
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Strum
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/strum`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'strum'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install strum
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/strum.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/strum ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "strum/cli"
5
+ Strum::CLI.start
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum"
4
+
5
+ path = File.expand_path(__dir__)
6
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| import f }
data/lib/strum/cli.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "strum/commands/new"
5
+ require "strum/commands/generate"
6
+
7
+ module Strum
8
+ # Command line interface
9
+ class CLI < Thor
10
+ include Thor::Actions
11
+
12
+ map "-v" => :version,
13
+ "g" => :generate,
14
+ "c" => :console,
15
+ "s" => :server
16
+ register(Strum::Commands::New, "new", "new [NAME] [options]", "Create new project skeleton")
17
+
18
+ desc "console", "Start the Strum console (short-cut alias: \"c\")"
19
+ def console
20
+ run "bundle exec rake #{File.expand_path('bin/console')}"
21
+ end
22
+
23
+ desc "server", "Start the Strum server (short-cut alias: \"s\")"
24
+ def server
25
+ run File.expand_path("bin/strum")
26
+ end
27
+
28
+ desc "generate [RESOURCE]", "Generate new Strum resource"
29
+ subcommand "generate", Commands::Generate
30
+
31
+ desc "version", "Show Strum version"
32
+ def version
33
+ require_relative "version"
34
+ say "Strum #{Strum::VERSION}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "strum/commands/version"
5
+ require "strum/commands/console"
6
+ require "strum/generators/new"
7
+ require "strum/generators/generate"
8
+ module Strum
9
+ # Strum commands
10
+ class Command < Thor
11
+ map "v" => :version, "g" => :generate, "c" => :console
12
+
13
+ register(Strum::Version, "version", "version", "Show Strum version")
14
+ register(Strum::Console, "console", "console", "Start Strum console (IRB)")
15
+ register(Strum::New, "new", "new", "Generate new Strum project skeleton")
16
+ register(Strum::Generate, "generate", "generate", "Generate new Strum resource")
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum/sub_command_base"
4
+ require "strum/commands/resource/model"
5
+ require "strum/commands/resource/migration"
6
+ require "strum/commands/resource/serializer"
7
+ require "strum/commands/resource/service"
8
+ require "strum/commands/resource/route"
9
+ require "strum/commands/resource/scaffold"
10
+
11
+ module Strum
12
+ module Commands
13
+ # Generate sub commands
14
+ class Generate < Thor
15
+ register(Strum::Commands::Resource::Route, "route", "route [NAME]", "Create route")
16
+ register(Strum::Commands::Resource::Service, "service", "service [NAME]", "Create service object")
17
+ register(Strum::Commands::Resource::Serializer, "serializer", "serializer [NAME] [fields]", "Create serializer")
18
+ register(Strum::Commands::Resource::Migration, "migration", "migration [NAME] [fields]", "Create sequel migration")
19
+ register(Strum::Commands::Resource::Model, "model", "model [NAME] [fields]", "Create sequel model")
20
+ register(Strum::Commands::Resource::Scaffold, "scaffold", "scaffold [NAME] [fields]", "Create Scaffold")
21
+
22
+ def self.banner(command, _namespace = nil, _subcommand = false)
23
+ "#{basename} #{subcommand_prefix} #{command.usage}"
24
+ end
25
+
26
+ def self.subcommand_prefix
27
+ name.gsub(/.*::/, "")
28
+ .gsub(/^[A-Z]/) { |match| match[0].downcase }
29
+ .gsub(/[A-Z]/) { |match| "-#{match[0].downcase}" }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Strum
2
+ module Commands
3
+ module Mixin
4
+ # Is it strum folder
5
+ module AppCheck
6
+ protected
7
+ class StrumGenerateError < StandardError; end
8
+
9
+ def app_class_name
10
+ File.open("config/app.rb").read.match(/class (.+) < Roda/)[1]
11
+ rescue StandardError
12
+ nil
13
+ end
14
+
15
+ def strum?
16
+ !app_class_name.nil?
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strum
4
+ module Commands
5
+ module Mixin
6
+ # Parse fields for commands
7
+ module Fields
8
+ # class FieldError < StandardError; end
9
+ # FIELD_TYPES = %w[string integer boolean date time datetime].freeze
10
+
11
+ protected
12
+
13
+ def permitted_fields
14
+ fields.map do |field|
15
+ field_parts = field.split(":")
16
+ payload = { name: field_parts[0] }
17
+ payload[:type] = field_parts[1] || "string"
18
+ payload[:index] = field_parts[2] unless field_parts[2].nil?
19
+ # raise FieldError, "Incorrect name format '#{payload[:name]}'" unless payload[:name].match(/[a-z\_\-]+/)
20
+ # raise FieldError, "Incorrect field type '#{payload[:type]}'" unless FIELD_TYPES.include?(payload[:type])
21
+ # raise FieldError, "Incorrect index format" unless payload[:index].nil? ^ payload[:index].eql?("index")
22
+
23
+ payload
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-inflector"
4
+
5
+ module Strum
6
+ module Commands
7
+ module Mixin
8
+ # Parse fields for commands
9
+ module Names
10
+ protected
11
+
12
+ def resource_class_name
13
+ resource_name.split("_").map(&:capitalize).join
14
+ end
15
+
16
+ def resources_class_name
17
+ inflector.pluralize(resource_class_name)
18
+ end
19
+
20
+ def resource_name
21
+ inflector.singularize(name_components.last)
22
+ end
23
+
24
+ def resources_name
25
+ inflector.pluralize(name_components.last)
26
+ end
27
+ alias resource_filename resources_name
28
+
29
+ def namespace_names
30
+ namespaces.map { |namespace| namespace.split("_").map(&:capitalize).join }
31
+ end
32
+
33
+ def namespace_path
34
+ File.join(*namespaces)
35
+ end
36
+
37
+ def ident
38
+ " " * namespaces.size
39
+ end
40
+
41
+ private
42
+
43
+ def name_components
44
+ @name_components ||= name.scan(/[[:alnum:]]+/).map { |s| s.split(/(?=[A-Z])|\_/).map(&:downcase).join("_") }
45
+ end
46
+
47
+ def namespaces
48
+ name_components.take(name_components.size - 1)
49
+ end
50
+
51
+ def inflector
52
+ @inflector ||= Dry::Inflector.new
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Strum
4
+ module Commands
5
+ class New < Thor::Group
6
+ include Thor::Actions
7
+
8
+ desc "Create new project skeleton"
9
+ argument :name
10
+ class_option :cors, type: :boolean
11
+ class_option :sequel, type: :boolean, aliases: ["-s"]
12
+ class_option :rabbit, type: :boolean, aliases: ["-r"]
13
+ class_option :json, type: :boolean, aliases: ["-j"]
14
+ class_option :rest, type: :boolean, aliases: ["--api"]
15
+ class_option :redis, type: :boolean
16
+
17
+ def create_app
18
+ directory("../templates/app/blank", app_name)
19
+ end
20
+
21
+ def extend_sequel
22
+ directory("../templates/app/sequel", app_name) if sequel?
23
+ end
24
+
25
+ def extend_json
26
+ directory("../templates/app/json", app_name) if json?
27
+ end
28
+
29
+ def self.banner
30
+ "#{basename} #{self_command.formatted_usage(self, false).split(':').last}"
31
+ end
32
+
33
+ def self.source_root
34
+ File.expand_path(__dir__, "../templates")
35
+ end
36
+
37
+ protected
38
+
39
+ def app_name
40
+ name.gsub(/[^0-9A-Za-z]+/, "_").split(/(?=[A-Z])|[\-\_]/).map(&:downcase).join("_")
41
+ end
42
+
43
+ def app_class_name
44
+ app_name.split("_").map(&:capitalize).join << "App"
45
+ end
46
+
47
+ def sequel?
48
+ options[:sequel] || (options[:rest] && (options[:sequel] != false))
49
+ end
50
+
51
+ def json?
52
+ options[:json] || (options[:rest] && (options[:json] != false))
53
+ end
54
+
55
+ def cors?
56
+ options[:cors]
57
+ end
58
+
59
+ def rabbit?
60
+ options[:rabbit]
61
+ end
62
+
63
+ def redis?
64
+ options[:redis]
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum/commands/mixin/app_check"
4
+ require "strum/commands/mixin/names"
5
+ require "strum/commands/mixin/fields"
6
+
7
+ module Strum::Commands::Resource
8
+ # Strum generate sub command
9
+ # `strum generate migration`
10
+ class Migration < Thor::Group
11
+ include Thor::Actions
12
+ include Strum::Commands::Mixin::AppCheck
13
+ include Strum::Commands::Mixin::Names
14
+ include Strum::Commands::Mixin::Fields
15
+
16
+ argument :name
17
+ class_option :model, type: :boolean, default: false
18
+ class_option :fields, type: :array, default: []
19
+
20
+ def self.source_root
21
+ File.expand_path("../../templates", __dir__)
22
+ end
23
+
24
+ def pre_check
25
+ raise StrumGenerateError, "This is not Strum application" unless strum?
26
+ end
27
+
28
+ def create_model_file
29
+ directory("migration", "db/migrations")
30
+ end
31
+
32
+ protected
33
+
34
+ def model?
35
+ options[:model]
36
+ end
37
+
38
+ def table_name
39
+ inflector.tableize(name_components.join("_"))
40
+ end
41
+
42
+ private
43
+
44
+ def migration_filename
45
+ if model?
46
+ "#{new_migration_number}_create_#{table_name}"
47
+ else
48
+ "#{new_migration_number}_#{name_components.join("_")}"
49
+ end
50
+ end
51
+
52
+ def new_migration_number
53
+ migration_files = (Dir.chdir("db/migrations") { Dir.glob("*").max })
54
+ last_number = migration_files && migration_files[/\d+/].to_i || 0
55
+ new_number = last_number > 9 ? last_number + 10 : 10
56
+ new_number.to_s.rjust(3, "0")
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum/commands/mixin/app_check"
4
+ require "strum/commands/mixin/names"
5
+ require "strum/commands/mixin/fields"
6
+
7
+ module Strum::Commands::Resource
8
+ class Model < Thor::Group
9
+ include Thor::Actions
10
+ include Strum::Commands::Mixin::AppCheck
11
+ include Strum::Commands::Mixin::Names
12
+ include Strum::Commands::Mixin::Fields
13
+
14
+ argument :name, required: true
15
+ argument :fields, type: :array, required: false, default: []
16
+ class_option :rspec, type: :boolean
17
+ class_option :migration, type: :boolean, default: true
18
+
19
+ def self.source_root
20
+ File.expand_path("../../templates", __dir__)
21
+ end
22
+
23
+ def pre_check
24
+ raise StrumGenerateError, "This is not Strum application" unless strum?
25
+ end
26
+
27
+ def create_model_file
28
+ directory("model", File.expand_path(namespace_path, "models"))
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum/commands/mixin/app_check"
4
+ require "strum/commands/mixin/names"
5
+ require "strum/commands/mixin/fields"
6
+
7
+ module Strum::Commands::Resource
8
+ # Strum generate sub command
9
+ # `strum generate migration`
10
+ class Route < Thor::Group
11
+ include Thor::Actions
12
+ include Strum::Commands::Mixin::AppCheck
13
+ include Strum::Commands::Mixin::Names
14
+ include Strum::Commands::Mixin::Fields
15
+
16
+ argument :name
17
+ class_option :crud, type: :boolean, aliases: ["-c"]
18
+
19
+ def self.source_root
20
+ File.expand_path("../../templates", __dir__)
21
+ end
22
+
23
+ def pre_check
24
+ raise StrumGenerateError, "This is not Strum application" unless strum?
25
+ end
26
+
27
+ def create_route_file
28
+ options[:crud] ? crud_route : basic_route
29
+ end
30
+
31
+ protected
32
+
33
+ def route_name
34
+ options[:crud] ? inflector.pluralize(name_components.join("-")) : name_components.join("-")
35
+ end
36
+
37
+ private
38
+
39
+ def basic_route
40
+ directory("route", File.expand_path(namespace_path, "routes"))
41
+ end
42
+
43
+ def crud_route
44
+ directory("route_crud", File.expand_path(namespace_path, "routes"))
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum/commands/resource/model"
4
+
5
+ module Strum::Commands::Resource
6
+ class Scaffold < Thor::Group
7
+ argument :name, required: true
8
+ argument :fields, type: :array, required: false, default: []
9
+ class_option :crud, type: :boolean, default: true
10
+ class_option :rspec, type: :boolean, default: true
11
+
12
+ def create_scaffold
13
+ invoke Strum::Commands::Resource::Model, nil, options
14
+ invoke Strum::Commands::Resource::Migration, nil, model: true
15
+ invoke Strum::Commands::Resource::Serializer, nil, options
16
+ invoke Strum::Commands::Resource::Route, nil, options.merge(crud: true)
17
+ invoke Strum::Commands::Resource::Service, nil, options.merge(crud: true)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strum/commands/mixin/app_check"
4
+ require "strum/commands/mixin/names"
5
+ require "strum/commands/mixin/fields"
6
+
7
+ module Strum::Commands::Resource
8
+ # Strum generate sub command
9
+ # `strum generate migration`
10
+ class Serializer < Thor::Group
11
+ include Thor::Actions
12
+ include Strum::Commands::Mixin::AppCheck
13
+ include Strum::Commands::Mixin::Names
14
+ include Strum::Commands::Mixin::Fields
15
+
16
+ argument :name
17
+ class_option :fields, type: :array, default: []
18
+
19
+ def self.source_root
20
+ File.expand_path("../../templates", __dir__)
21
+ end
22
+
23
+ def pre_check
24
+ raise StrumGenerateError, "This is not Strum application" unless strum?
25
+ end
26
+
27
+ def create_serializer_file
28
+ directory("serializer", File.expand_path(namespace_path, "serializers"))
29
+ end
30
+ end
31
+ end