rails_console_toolkit 0.4.0 → 0.6.0

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: d50673e1deb8963c98f22292c95446f83baa29b18bdb7e06199a80f9e5b1388f
4
- data.tar.gz: 5834816fa5f8fc3136576ad21d6f1d95c9dfb6bbc35cd2210882bb81d18701ce
3
+ metadata.gz: 7923cd1b5ca7ce01c1a58372c4d568c348c88f0d351aa4d784eef148328c8700
4
+ data.tar.gz: ea1aaa9db79ced4baee7b73bb9e7652c059f8ca81a585758628bc2087f2e9afc
5
5
  SHA512:
6
- metadata.gz: a44ae00ec2915af4452cb40ade632c50142a0661db9fc7b1212189db25740b55ebc3c51df3b4737212d5c8c387ff2f21c703c4940ae793b24fd208085c9c9e89
7
- data.tar.gz: 32f281e091aba5e871699efdf40c744723ba0ef205bb1ece9f7aac2c8e1bb22cc66596a773c714a50135eb53bd3a777fe3ef31a9f2c34b6c210051fc940ec854
6
+ metadata.gz: 9f64a1c43c9571509e3280e8eee86bccf571046e8a426b6b464d8f4f5eedfd2a643e2d96702f3ccc52182f4c4278b9d39b596f55ce0b9999394c281502f4ef53
7
+ data.tar.gz: 8c1b5186da25dea915ce02f1f3be6e58c32c115d617bd86f934d193245cdf20027928826e74504cc70bc2a6862cc181448bd6fa3dbd0f9b881faa1bae6602fd3
File without changes
@@ -0,0 +1,47 @@
1
+ name: build
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ - "*/ci-check"
8
+ pull_request:
9
+ branches:
10
+ - master
11
+
12
+ jobs:
13
+ rake:
14
+ name: ${{ matrix.combo.name }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ combo:
19
+ - name: current-ruby
20
+ ruby: 3.0
21
+ - name: previous-ruby
22
+ ruby: 2.7
23
+ - name: older-ruby
24
+ ruby: 2.6
25
+
26
+ runs-on: 'ubuntu-latest'
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.combo.ruby }}
32
+ bundler-cache: false
33
+ - run: bundle lock
34
+ - uses: actions/cache@v2
35
+ with:
36
+ path: ./vendor/bundle
37
+ key: ${{ runner.os }}-${{ matrix.combo.ruby }}-gems-${{ github.ref }}-${{ hashFiles('**/Gemfile.lock') }}
38
+ restore-keys: |
39
+ ${{ runner.os }}-${{ matrix.combo.ruby }}-gems-${{ github.ref }}
40
+ ${{ runner.os }}-${{ matrix.combo.ruby }}-gems-master
41
+ ${{ runner.os }}-${{ matrix.combo.ruby }}-gems-
42
+ - name: bundle install
43
+ run: |
44
+ bundle config path $PWD/vendor/bundle
45
+ bundle install --jobs 4 --retry 3
46
+ bundle clean
47
+ - run: bundle exec rake
data/README.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  Find records faster, add custom helpers, improve your console life by 100%.
6
6
 
7
- [![CircleCI](https://img.shields.io/circleci/build/github/nebulab/rails_console_toolkit/master?logo=circleci)](https://circleci.com/gh/nebulab/rails_console_toolkit)
7
+ [![Build](https://github.com/nebulab/rails_console_toolkit/workflows/build/badge.svg)](https://github.com/nebulab/rails_console_toolkit/actions?query=workflow%3Abuild)
8
+
8
9
 
9
10
  ## Installation
10
11
 
@@ -14,13 +15,23 @@ Add this line to your application's Gemfile:
14
15
  gem 'rails_console_toolkit'
15
16
  ```
16
17
 
17
- And then configure it within an initializer:
18
+ And then generate the initializer:
19
+
20
+ ```
21
+ $ bin/rails generate rails_console_toolkit:install
22
+ ```
23
+
24
+ or write it manually:
18
25
 
19
26
  ```ruby
20
27
  # config/initializers/console.rb
21
28
 
22
29
  RailsConsoleToolkit.configure do |config|
23
30
  # helper definitions go here...
31
+ #
32
+ # config.use_pack :aliases
33
+ # config.use_pack :utils
34
+ # config.use_pack :solidus if defined? Spree
24
35
  end
25
36
  ```
26
37
 
@@ -123,7 +134,7 @@ end
123
134
  # config/initializers/console.rb
124
135
 
125
136
  RailsConsoleToolkit.configure do |config|
126
- config.model_helper 'Spree::Product', as: :product, by: %i[:name, :slug]
137
+ config.model_helper 'Spree::Product', as: :product, by: %i[name slug]
127
138
  end
128
139
  ```
129
140
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsConsoleToolkit
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ def copy_initializer
7
+ copy_file 'initializer.rb', 'config/initializers/console.rb'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ RailsConsoleToolkit.configure do |config|
4
+ # Uncomment to activate a pack:
5
+ #
6
+ # config.use_pack :aliases
7
+ # config.use_pack :utils
8
+ # config.use_pack :solidus if defined? Spree
9
+ #
10
+ # An example of a model-helper:
11
+ #
12
+ # config.model_helper 'Product', as: :product, by: %i[name slug]
13
+ end
@@ -19,19 +19,23 @@ module RailsConsoleToolkit::Helpers
19
19
  helper_methods[name.to_sym] = block
20
20
  end
21
21
 
22
- def model_helper(klass, as: nil, by: nil, cached: true)
23
- klass = klass.constantize if klass.respond_to? :constantize
24
- method_name = as || klass.name.gsub('::', '_').underscore
25
- cache_key = method_name
22
+ def model_helper(klass_name, as: nil, by: nil, cached: true)
23
+ unless String === klass_name
24
+ raise TypeError, "The class name is expected to be a String, got #{klass_name.inspect} (#{klass_name.class}) instead."
25
+ end
26
+
27
+ method_name = as || klass_name.gsub('::', '_').underscore
26
28
  attribute_names = by || []
27
29
 
28
30
  record = nil # use the closure as a cache
29
31
 
30
32
  helper method_name do |key = nil|
33
+ klass = klass_name.constantize
31
34
  record = nil unless cached
32
35
 
33
36
  if key
34
37
  record = nil
38
+ record = key if klass === key
35
39
  record ||= klass.find(key) if Numeric === key
36
40
  attribute_names.find { |name| record ||= klass.find_by(name => key) }
37
41
  end
@@ -5,9 +5,12 @@ RailsConsoleToolkit.helper :load_factories do
5
5
  Rails::ConsoleMethods.send :include, ::FactoryBot::Syntax::Methods
6
6
  end
7
7
 
8
- RailsConsoleToolkit.model_helper Spree::Product, as: :product, by: [:slug, :name]
9
- RailsConsoleToolkit.model_helper Spree::Variant, as: :variant, by: [:sku]
10
- RailsConsoleToolkit.model_helper Spree::Taxon, as: :taxon, by: [:permalink]
11
- RailsConsoleToolkit.model_helper Spree::Order, as: :order, by: [:number]
12
- RailsConsoleToolkit.model_helper Spree::User, as: :user, by: [:email]
13
- RailsConsoleToolkit.model_helper Spree::Country, as: :country, by: [:iso, :iso3, :iso_name, :name]
8
+ RailsConsoleToolkit.model_helper "Spree::Product", as: :product, by: [:slug, :name]
9
+ RailsConsoleToolkit.model_helper "Spree::Variant", as: :variant, by: [:sku]
10
+ RailsConsoleToolkit.model_helper "Spree::Taxon", as: :taxon, by: [:permalink]
11
+ RailsConsoleToolkit.model_helper "Spree::Order", as: :order, by: [:number]
12
+ RailsConsoleToolkit.model_helper "Spree::User", as: :user, by: [:email]
13
+ RailsConsoleToolkit.model_helper "Spree::Country", as: :country, by: [:iso, :iso3, :iso_name, :name]
14
+ RailsConsoleToolkit.model_helper "Spree::Role", as: :role, by: [:name]
15
+ RailsConsoleToolkit.model_helper "Spree::Promotion", as: :promotion, by: [:name]
16
+ RailsConsoleToolkit.alias_helper :promo, :promotion
@@ -1,3 +1,3 @@
1
1
  module RailsConsoleToolkit
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "rails", '>= 4'
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake", ">= 12.3.3"
34
34
  spec.add_development_dependency "minitest", "~> 5.0"
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_console_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2020-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -74,15 +74,17 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - ".circleci/config.yml"
77
+ - ".github/config.yml"
78
+ - ".github/workflows/build.yml"
78
79
  - ".gitignore"
79
- - ".travis.yml"
80
80
  - Gemfile
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
84
  - bin/console
85
85
  - bin/setup
86
+ - lib/generators/rails_console_toolkit/install/install_generator.rb
87
+ - lib/generators/rails_console_toolkit/install/templates/initializer.rb
86
88
  - lib/rails_console_toolkit.rb
87
89
  - lib/rails_console_toolkit/aliases.rb
88
90
  - lib/rails_console_toolkit/helpers.rb
@@ -96,7 +98,7 @@ licenses:
96
98
  metadata:
97
99
  homepage_uri: https://github.com/nebulab/rails_console_toolkit#readme
98
100
  source_code_uri: https://github.com/nebulab/rails_console_toolkit
99
- post_install_message:
101
+ post_install_message:
100
102
  rdoc_options: []
101
103
  require_paths:
102
104
  - lib
@@ -111,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
113
  - !ruby/object:Gem::Version
112
114
  version: '0'
113
115
  requirements: []
114
- rubygems_version: 3.0.3
115
- signing_key:
116
+ rubygems_version: 3.1.4
117
+ signing_key:
116
118
  specification_version: 4
117
119
  summary: Configurable Rails Console Helpers
118
120
  test_files: []
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.2
7
- before_install: gem install bundler -v 2.0.1