cnc 0.1.6 → 0.1.7

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: 51e3b73ab88e990cdb1fb24bf9e7ccbb06042a4e8829c4c6216d14dab350fc43
4
- data.tar.gz: 2578f0bee1b7f83f2d5604da4347f4f1ff83cbd7f0f7acf9b08921e5da2f1694
3
+ metadata.gz: c3be381add3c7cd3bad3f2b21ee24c2a006b1fbd625176cf76ad3333f1f9f8cb
4
+ data.tar.gz: d05f5f8329249b522dea60146d1cc6cfc350a2bc101ceb40d4b1d7f17c369988
5
5
  SHA512:
6
- metadata.gz: 659f625e7a2e4e1af0bb99e1f5d9476770dea0fd79a3c2ae795ba0cc3f5ba90054a46e808246155e66be873b299cd0310f2968f4bffbd293530e87c5da5a6037
7
- data.tar.gz: c076ff3abae955f61a1a042fda3a1401624237300676e075d2528222e6c846f8d2aaaac8aa603bc5259a21ba65bc98b571576e9a79443c8ce751737b32b50320
6
+ metadata.gz: ce0b72c3899ec257fa214dc513c95aff713ecf6513243c2406acf531466ba7986e5e5722939e25cfe29c8f5a466c549dcb41521880a4b5a13722c4ee1564613e
7
+ data.tar.gz: db6223759d5c533d59f7324c23d87e64fec7356a1c7b1f7554330a5105f4b43d6261a0eae7bbdfd6b3fb96f65396d17e9e84e792fa09c5bf1de5e8bacd227d92
data/README.md CHANGED
@@ -22,6 +22,10 @@ Or install it yourself as:
22
22
  $ gem install cnc
23
23
  ```
24
24
 
25
+ ## Usage & Features
26
+
27
+ ### Migration renaming
28
+
25
29
  ## Contributing
26
30
 
27
31
  Open a Pull Request or issue and we'll take a look.
data/Rakefile CHANGED
@@ -1,8 +1,12 @@
1
- require "bundler/setup"
1
+ # frozen_string_literal: true
2
2
 
3
- APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
- load "rails/tasks/engine.rake"
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
5
 
6
- load "rails/tasks/statistics.rake"
6
+ Minitest::TestTask.create
7
7
 
8
- require "bundler/gem_tasks"
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hash
4
+ # Removes and returns a hash containing the key/value pairs for which the
5
+ # block returns a true value given the key.
6
+ #
7
+ # hash = {:a => 1, "b" => 2, :c => 3}
8
+ # hash.extract_if! { _1.is_a? Symbol } #=> {a: 1, c: 3}
9
+ # hash #=> {"b" => 2 }
10
+ def extract_if!
11
+ each_with_object(self.class.new) do |(key, value), result|
12
+ result[key] = delete(key) if yield(key, value)
13
+ end
14
+ end
15
+
16
+ # Destructively converts all values at the given keys using the given block.
17
+ #
18
+ # hash = {a: 1, b: 2, c: 3}
19
+ # hash.transform!(:c, &:succ)
20
+ # hash #=> {a: 1, b: 2, c: 4}
21
+ #
22
+ def transform!(*keys)
23
+ keys.each do |k|
24
+ self[k] = yield self[k] if key?(k)
25
+ end
26
+ self
27
+ end
28
+
29
+ # Returns a new hash with all values at the given keys converted using the
30
+ # given block.
31
+ #
32
+ # hash = {a: 1, b: 2, c: 3}
33
+ # hash.transform(:a, :b, &:succ) #=> {a: 2, b: 3, c: 3}
34
+ def transform(...) = dup.transform!(...)
35
+ end
@@ -0,0 +1,16 @@
1
+ class Module
2
+ # Shorthand for `const_set(name.camelize, Class.new(parent) { ... })`.
3
+ # Useful when defining classes in macros.
4
+ def define_class(name, parent = nil, &)
5
+ name = name.to_s.camelize
6
+ raise NameError, "class exists: #{name}" if const_defined?(name, false)
7
+ const_set name, Class.new(parent, &)
8
+ end
9
+
10
+ # Defines a constant of the given name using the given block if it doesn't
11
+ # already exist.
12
+ def const_cache(name)
13
+ name = name.to_s.gsub('::', ?_)
14
+ const_defined?(name, false) ? const_get(name) : const_set(name, yield(name))
15
+ end
16
+ end
@@ -1,7 +1,19 @@
1
- Object.class_eval do
1
+ class Object
2
+ def instance_variable_values
3
+ instance_variables.map { instance_variable_get _1 }
4
+ end
5
+
6
+ def system_echo(src)
7
+ puts src
8
+ system(src)
9
+ end
10
+
2
11
  def rubymine(file, line = 0)
3
- puts "rubymine --line #{line || 0} #{file} "
4
- system("rubymine --line #{line || 0} #{file} ")
12
+ system_echo("rubymine --line #{line || 0} #{file}")
13
+ end
14
+
15
+ def vscode(file, line = 0)
16
+ system_echo("code #{file}:#{line || 0}")
5
17
  end
6
18
 
7
19
  def locate_method(name)
@@ -23,7 +35,7 @@ Object.class_eval do
23
35
 
24
36
  # return system("tmux split-window -h \"vim #{file} +#{line}\"") if file
25
37
  # return system("$VISUAL --goto #{file}:#{line || 0}") if file
26
- return rubymine(file, line || 0) if file
38
+ return vscode(file, line || 0) if file
27
39
 
28
40
  puts 'Source not available. Is this a C extension?'
29
41
  end
@@ -0,0 +1,5 @@
1
+ class Symbol
2
+ def underscore = to_s.underscore.to_sym
3
+ def camelize(...) = to_s.camelize(...).to_sym
4
+ def chomp(...) = to_s.chomp(...).to_sym
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob(File.expand_path("core_ext/*.rb", __dir__)).sort.each do |path|
4
+ require path
5
+ end
@@ -0,0 +1,53 @@
1
+ require "listen"
2
+
3
+ module CNC
4
+ # Usage:
5
+ #
6
+ # CNC::Migrator.listen if Rails.env.development?
7
+ module Migrator
8
+ module_function
9
+
10
+ def logger
11
+ @logger ||= ActiveSupport::TaggedLogging.new(Rails.logger).tagged("CNC::Migrator")
12
+ end
13
+
14
+ def log(...) = logger.info(...)
15
+
16
+ def path = Rails.root / "db"
17
+ def only = %r{(migrate/)([a-z]\w+)\.rb$}
18
+
19
+ def fresh_migration(name)
20
+ <<~RUBY
21
+ class #{name.camelize} < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]
22
+ def change
23
+ #{yield if block_given?}
24
+ end
25
+ end
26
+ RUBY
27
+ end
28
+
29
+ def process(paths)
30
+ number = Time.now.utc.strftime("%Y%m%d%H%M%S")
31
+ paths.each do |path|
32
+ body = File.read(path)
33
+ new_path = path.sub(only, "\\1#{number}_\\2.rb")
34
+ log "Moving '#{path}' to '#{new_path}'."
35
+
36
+ File.rename(path, new_path)
37
+ File.open(new_path, "w+") do |file|
38
+ file << fresh_migration($2) { body }
39
+ end
40
+ number.succ!
41
+ end
42
+ end
43
+
44
+ def listen
45
+ log "Watching for unstamped migration files in #{path}."
46
+ Listen.to(path, only:, relative: true) do |modified, added, removed|
47
+ process(added | modified)
48
+ end.start
49
+ rescue Errno::ENOENT
50
+ log "db/ directory does not exist."
51
+ end
52
+ end
53
+ end
data/lib/cnc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CNC
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/cnc.rb CHANGED
@@ -1,7 +1,14 @@
1
+ require "zeitwerk"
2
+ require "active_support/all"
3
+ require "cnc/core_ext"
1
4
  require "cnc/version"
2
- require "cnc/engine"
3
5
 
4
- require_relative "object"
6
+ loader = Zeitwerk::Loader.for_gem
7
+ loader.inflector.inflect("cnc" => "CNC")
8
+ loader.ignore("#{__dir__}/cnc/core_ext")
9
+ loader.setup
10
+
11
+ ActiveSupport::Inflector.inflections { _1.acronym "CNC" }
5
12
 
6
13
  module CNC
7
14
  end
data/rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  inherit_gem:
2
2
  rubocop-rails-omakase: rubocop.yml
3
3
 
4
+ plugins:
5
+ - rubocop-minitest
6
+
4
7
  AllCops:
5
8
  # ParserEngine: parser_prism
6
9
  TargetRubyVersion: 3.3
@@ -47,8 +50,75 @@ Layout/SpaceInsideHashLiteralBraces:
47
50
  Lint/AssignmentInCondition:
48
51
  Enabled: false
49
52
 
50
- # ensure test filenames include "test"
53
+ Minitest/AssertInDelta: # new in 0.10
54
+ Enabled: true
55
+ Minitest/AssertKindOf: # new in 0.10
56
+ Enabled: true
57
+ Minitest/AssertOperator: # new in 0.32
58
+ Enabled: true
59
+ Minitest/AssertOutput: # new in 0.10
60
+ Enabled: true
61
+ Minitest/AssertPathExists: # new in 0.10
62
+ Enabled: true
63
+ Minitest/AssertPredicate: # new in 0.18
64
+ Enabled: true
65
+ Minitest/AssertRaisesCompoundBody: # new in 0.21
66
+ Enabled: true
67
+ Minitest/AssertRaisesWithRegexpArgument: # new in 0.22
68
+ Enabled: true
69
+ Minitest/AssertSame: # new in 0.26
70
+ Enabled: true
71
+ Minitest/AssertSilent: # new in 0.10
72
+ Enabled: true
73
+ Minitest/AssertWithExpectedArgument: # new in 0.11
74
+ Enabled: true
75
+ Minitest/AssertionInLifecycleHook: # new in 0.10
76
+ Enabled: true
77
+ Minitest/DuplicateTestRun: # new in 0.19
78
+ Enabled: true
79
+ Minitest/EmptyLineBeforeAssertionMethods: # new in 0.23
80
+ Enabled: true
81
+ Minitest/Focus: # new in 0.35
82
+ Enabled: true
83
+ Minitest/LifecycleHooksOrder: # new in 0.28
84
+ Enabled: true
85
+ Minitest/LiteralAsActualArgument: # new in 0.10
86
+ Enabled: true
87
+ Minitest/MultipleAssertions: # new in 0.10
88
+ Enabled: true
89
+ Minitest/NonExecutableTestMethod: # new in 0.34
90
+ Enabled: true
91
+ Minitest/NonPublicTestMethod: # new in 0.27
92
+ Enabled: true
93
+ Minitest/RedundantMessageArgument: # new in 0.34
94
+ Enabled: true
95
+ Minitest/RefuteInDelta: # new in 0.10
96
+ Enabled: true
97
+ Minitest/RefuteKindOf: # new in 0.10
98
+ Enabled: true
99
+ Minitest/RefuteOperator: # new in 0.32
100
+ Enabled: true
101
+ Minitest/RefutePathExists: # new in 0.10
102
+ Enabled: true
103
+ Minitest/RefutePredicate: # new in 0.18
104
+ Enabled: true
105
+ Minitest/RefuteSame: # new in 0.26
106
+ Enabled: true
107
+ Minitest/ReturnInTestMethod: # new in 0.31
108
+ Enabled: true
109
+ Minitest/SkipEnsure: # new in 0.20
110
+ Enabled: true
111
+ Minitest/SkipWithoutReason: # new in 0.24
112
+ Enabled: true
51
113
  Minitest/TestFileName:
114
+ Enabled: true # ensure test filenames include "test"
115
+ Minitest/TestMethodName: # new in 0.10
116
+ Enabled: true
117
+ Minitest/UnreachableAssertion: # new in 0.14
118
+ Enabled: true
119
+ Minitest/UnspecifiedException: # new in 0.10
120
+ Enabled: true
121
+ Minitest/UselessAssertion: # new in 0.26
52
122
  Enabled: true
53
123
 
54
124
  # Prefer `refute` over `assert_not`. `assert_not_*` are rails-only.
metadata CHANGED
@@ -1,15 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Peterson
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rubocop
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rubocop-minitest
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: rubocop-rails-omakase
15
42
  requirement: !ruby/object:Gem::Requirement
@@ -25,7 +52,21 @@ dependencies:
25
52
  - !ruby/object:Gem::Version
26
53
  version: '0'
27
54
  - !ruby/object:Gem::Dependency
28
- name: rails
55
+ name: activesupport
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: listen
29
70
  requirement: !ruby/object:Gem::Requirement
30
71
  requirements:
31
72
  - - ">="
@@ -52,7 +93,21 @@ dependencies:
52
93
  - - ">="
53
94
  - !ruby/object:Gem::Version
54
95
  version: '0'
55
- description: Stop milling about and build rails apps faster with CNC.
96
+ - !ruby/object:Gem::Dependency
97
+ name: zeitwerk
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Stop milling about and build ruby apps faster with CNC.
56
111
  email:
57
112
  - jeff@concept.love
58
113
  executables:
@@ -63,21 +118,16 @@ files:
63
118
  - MIT-LICENSE
64
119
  - README.md
65
120
  - Rakefile
66
- - app/assets/config/cnc_manifest.js
67
- - app/assets/stylesheets/cnc/application.css
68
- - app/controllers/cnc/application_controller.rb
69
- - app/helpers/cnc/application_helper.rb
70
- - app/jobs/cnc/application_job.rb
71
- - app/mailers/cnc/application_mailer.rb
72
- - app/models/cnc/application_record.rb
73
- - app/views/layouts/cnc/application.html.erb
74
- - config/routes.rb
75
121
  - exe/cnc
76
122
  - lib/cnc.rb
77
123
  - lib/cnc/cli/commands.rb
78
- - lib/cnc/engine.rb
124
+ - lib/cnc/core_ext.rb
125
+ - lib/cnc/core_ext/hash.rb
126
+ - lib/cnc/core_ext/module.rb
127
+ - lib/cnc/core_ext/object.rb
128
+ - lib/cnc/core_ext/symbol.rb
129
+ - lib/cnc/migrator.rb
79
130
  - lib/cnc/version.rb
80
- - lib/object.rb
81
131
  - lib/tasks/cnc_tasks.rake
82
132
  - rubocop.yml
83
133
  homepage: https://github.com/craft-concept/cnc
@@ -87,7 +137,6 @@ metadata:
87
137
  homepage_uri: https://github.com/craft-concept/cnc
88
138
  source_code_uri: https://github.com/craft-concept/cnc
89
139
  changelog_uri: https://github.com/craft-concept/cnc
90
- post_install_message:
91
140
  rdoc_options: []
92
141
  require_paths:
93
142
  - lib
@@ -95,15 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
144
  requirements:
96
145
  - - ">="
97
146
  - !ruby/object:Gem::Version
98
- version: '0'
147
+ version: '3.3'
99
148
  required_rubygems_version: !ruby/object:Gem::Requirement
100
149
  requirements:
101
150
  - - ">="
102
151
  - !ruby/object:Gem::Version
103
152
  version: '0'
104
153
  requirements: []
105
- rubygems_version: 3.5.21
106
- signing_key:
154
+ rubygems_version: 4.0.7
107
155
  specification_version: 4
108
- summary: Rails starter kit.
156
+ summary: Ruby starter kit.
109
157
  test_files: []
@@ -1 +0,0 @@
1
- //= link_directory ../stylesheets/cnc .css
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,4 +0,0 @@
1
- module CNC
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module CNC
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module CNC
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module CNC
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: "from@example.com"
4
- layout "mailer"
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- module CNC
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>CNC</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "cnc/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
15
- </html>
data/config/routes.rb DELETED
@@ -1,2 +0,0 @@
1
- CNC::Engine.routes.draw do
2
- end
data/lib/cnc/engine.rb DELETED
@@ -1,12 +0,0 @@
1
- require "active_support"
2
-
3
- module CNC
4
- class Engine < ::Rails::Engine
5
- isolate_namespace CNC
6
- config.autoload_paths += paths["lib"].to_a
7
-
8
- initializer "cnc.inflections" do
9
- ActiveSupport::Inflector.inflections { _1.acronym "CNC" }
10
- end
11
- end
12
- end