cnc 0.1.11 → 0.1.13

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: 68b3021b58286ffed2d5602400cb57f187ceab1dfa94b259574a4acda209693f
4
- data.tar.gz: f4aa34da62d922d7ccb48bbf60ff2b6e7bd0ae3080a53cb06b8d18ca678ef617
3
+ metadata.gz: 4e0bea2a8dd51512b1b5d04bbe9b2abdf221434e2368bf74c57a9d2b6dd66dfa
4
+ data.tar.gz: 6ad2d888e5cdecf188de135370aac6f7d161b3340863d763d80ef87bd06b7d11
5
5
  SHA512:
6
- metadata.gz: 49a7f7da1b3f23793aa0a225efe0c6a1671598042fedbd2f4004150f27cc36eb8a21fd414e3c66db32027376b175bfe1e16f8fff33e59a9762df6c9dbb416f87
7
- data.tar.gz: 51bfcb41d67fe31eab66a52f75f281c4870a42282984ab8178dc525ec9a2ce0c673b28bfc229c7b74e92c880b14bf0cd92f61086bf6d705b9898730e6244e657
6
+ metadata.gz: 5a941af03c847f1348f9f39d80e4bac430e80e2abf3b19b4059334e8e7086aab093182d62c7f5324c1fb14a7485aea77b5cad80c89933759feb19bb2d8275815
7
+ data.tar.gz: c7083fa8f025dc7120e55d00ef431bae66e88cfd6a3202e7e4e6af0bbdf2750527558387329e9f82023651256a7c995d67e983656f2647f9163ce6414c2b26d3
@@ -0,0 +1,47 @@
1
+ module CNC
2
+ module CLI
3
+ class Add < Command
4
+ namespace "cnc:add"
5
+
6
+ desc "search", "Add pg_search"
7
+ options skip_migrate: false, skip_multi: false
8
+ def search
9
+ raise "Can only add search when using postgres" unless pg?
10
+ template "pg_search"
11
+ end
12
+
13
+ desc "slugs", "Add friendly_id"
14
+ options skip_migrate: true
15
+ def slugs
16
+ template "friendly_id"
17
+ end
18
+
19
+ desc "versions", "Add paper_trail version tracking"
20
+ options skip_migrate: true
21
+ def versions
22
+ template "paper_trail"
23
+ end
24
+
25
+ def method_missing(name, ...)
26
+ puts "Not found. Falling back to running the template..."
27
+ template name
28
+ end
29
+
30
+ private
31
+
32
+ def template(path)
33
+ template = CNC.root("templates", path).sub_ext(".rb").to_s
34
+ run "rails app:template LOCATION='#{template}' OPTIONS='#{options.to_json}'"
35
+
36
+ # TODO: Run app:template in process:
37
+ # require File.expand_path("config/application", Dir.pwd)
38
+ # require "cnc/rails/app_generator"
39
+
40
+ # $options = options
41
+ #
42
+ # puts template
43
+ # CNC::Rails::AppGenerator.apply_rails_template(template, Dir.pwd)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ module CNC
2
+ module CLI
3
+ class Command < Thor
4
+ include Thor::Actions
5
+
6
+ namespace "cnc"
7
+
8
+ private
9
+
10
+ def self.exit_on_failure? = true
11
+
12
+ # TODO
13
+ def pg? = adapter.pg?
14
+ alias postgres? pg?
15
+
16
+ def adapter
17
+ @adapter ||= ActiveSupport::StringInquirer.new("pg")
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/cnc/cli.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  require "thor"
2
2
 
3
3
  module CNC
4
- class CLI < Thor
5
- desc "version", "Print version"
6
- def version
7
- puts VERSION
4
+ module CLI
5
+ def self.start(...) = Root.start(...)
6
+
7
+ class Root < Command
8
+ namespace :cnc
9
+
10
+ desc "version", "Print version"
11
+ def version = puts VERSION
12
+
13
+ desc "add FEATURE", "Add a feature"
14
+ subcommand "add", Add
8
15
  end
9
16
  end
10
17
  end
@@ -0,0 +1,9 @@
1
+ require "rails/generators"
2
+ require "rails/generators/rails/app/app_generator"
3
+
4
+ module CNC
5
+ module Rails
6
+ class AppGenerator < ::Rails::Generators::AppGenerator
7
+ end
8
+ end
9
+ end
data/lib/cnc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CNC
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.13"
3
3
  end
data/lib/cnc.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "zeitwerk"
2
+ require "pathname"
2
3
  require "active_support/all"
3
4
  require "cnc/core_ext"
4
5
  require "cnc/version"
@@ -7,6 +8,7 @@ loader = Zeitwerk::Loader.for_gem
7
8
  loader.inflector.inflect("cnc" => "CNC", "cli" => "CLI")
8
9
  loader.ignore("#{__dir__}/cnc/core_ext.rb")
9
10
  loader.ignore("#{__dir__}/cnc/core_ext")
11
+ loader.ignore("#{__dir__}/cnc/rails")
10
12
  loader.setup
11
13
 
12
14
  ActiveSupport::Inflector.inflections do |i|
@@ -14,4 +16,6 @@ ActiveSupport::Inflector.inflections do |i|
14
16
  end
15
17
 
16
18
  module CNC
19
+ def self.lib(*) = Pathname.new(__dir__).join(*)
20
+ def self.root(*) = lib.parent.join(*)
17
21
  end
@@ -0,0 +1,23 @@
1
+ # See: https://github.com/norman/friendly_id
2
+
3
+ $options ||= JSON.load(ENV['OPTIONS'] || '{}')
4
+
5
+ gem "friendly_id" unless match_file("Gemfile", /friendly_id/)
6
+
7
+ inject_into_class "app/models/application_record.rb", "ApplicationRecord" do
8
+ " # include FriendlyId\n"
9
+ end
10
+
11
+ migration = Dir["db/migrate/*"].none?(/friendly_id/)
12
+ initializer = Dir["config/initializers/*"].none?(/friendly_id/)
13
+
14
+ after_bundle do
15
+ generate "friendly_id", *("--skip-migration" unless migration),
16
+ *("--skip-initializer" unless initializer)
17
+
18
+ if initializer
19
+ uncomment_lines "config/initializers/friendly_id.rb", "config.use :"
20
+ end
21
+
22
+ rails_command "db:migrate" if !$options["skip_migrate"] && migration
23
+ end
@@ -0,0 +1,22 @@
1
+ # See: https://github.com/paper-trail-gem/paper_trail
2
+
3
+ $options ||= JSON.load(ENV['OPTIONS'] || '{}')
4
+
5
+ gem "paper_trail" unless match_file("Gemfile", /paper_trail['"]/)
6
+ gem "paper_trail-association_tracking" unless match_file("Gemfile", "paper_trail-association_tracking")
7
+
8
+ inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
9
+ " before_action :set_paper_trail_whodunnit\n"
10
+ end
11
+
12
+ inject_into_class "app/models/application_record.rb", "ApplicationRecord" do
13
+ " # has_paper_trail\n"
14
+ end
15
+
16
+ unless Dir["db/migrate/*"].any?(/create_versions/)
17
+ after_bundle do
18
+ generate "paper_trail:install --with-changes"
19
+ generate "paper_trail_association_tracking:install"
20
+ rails_command "db:migrate" unless $options["skip_migrate"]
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ # See: https://github.com/Casecommons/pg_search/
2
+
3
+ $options ||= JSON.load(ENV['OPTIONS'] || '{}')
4
+
5
+ gem "pg_search" unless match_file("Gemfile", /pg_search/)
6
+
7
+ inject_into_class "app/models/application_record.rb", "ApplicationRecord" do
8
+ " include PgSearch::Model\n"
9
+ end
10
+
11
+ unless $options["skip_multi"] or Dir["db/migrate/*"].any?(/pg_search/)
12
+ after_bundle do
13
+ generate "pg_search:migration:multisearch"
14
+ rails_command "db:migrate" unless $options["skip_migrate"]
15
+ end
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Peterson
@@ -135,6 +135,8 @@ files:
135
135
  - exe/cnc
136
136
  - lib/cnc.rb
137
137
  - lib/cnc/cli.rb
138
+ - lib/cnc/cli/add.rb
139
+ - lib/cnc/cli/command.rb
138
140
  - lib/cnc/core_ext.rb
139
141
  - lib/cnc/core_ext/hash.rb
140
142
  - lib/cnc/core_ext/module.rb
@@ -142,9 +144,13 @@ files:
142
144
  - lib/cnc/core_ext/symbol.rb
143
145
  - lib/cnc/core_ext/uri.rb
144
146
  - lib/cnc/migrator.rb
147
+ - lib/cnc/rails/app_generator.rb
145
148
  - lib/cnc/version.rb
146
149
  - lib/tasks/cnc_tasks.rake
147
150
  - rubocop.yml
151
+ - templates/friendly_id.rb
152
+ - templates/paper_trail.rb
153
+ - templates/pg_search.rb
148
154
  homepage: https://github.com/craft-concept/cnc
149
155
  licenses:
150
156
  - MIT