rails_console_toolkit 0.1.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +32 -0
- data/README.md +37 -29
- data/lib/rails_console_toolkit.rb +8 -46
- data/lib/rails_console_toolkit/aliases.rb +1 -1
- data/lib/rails_console_toolkit/helpers.rb +56 -0
- data/lib/rails_console_toolkit/solidus.rb +3 -0
- data/lib/rails_console_toolkit/version.rb +1 -1
- data/rails_console_toolkit.gemspec +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a865af4dc1a6a3fdf9eaafa25cbba4ac02bc44b88b10bab7931e744fc4e13212
|
4
|
+
data.tar.gz: d57b3c408d1c781d3861eca231555bf8f86a8c0b6ecfa7efa56348803645cf8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01a811e7da05c9c6752d76fcd404f15855a01842571880de44d7a9131ef8a2cc5828b3cb3a380241a6a0403c1aabac3c1a50439a7ec367b8507399efefabbf89
|
7
|
+
data.tar.gz: 8eded7fe42d1c55b00297985dac767f5b80c80c29fdaf3831b5ded2502e976666d6ea5112f3a9dd173a53e43a16110e00e0e3b206da2ebcaab5351c3fc912291
|
@@ -0,0 +1,32 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.6
|
6
|
+
|
7
|
+
working_directory: ~/repo
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
|
12
|
+
- restore_cache:
|
13
|
+
keys:
|
14
|
+
- v1-dependencies-{{ checksum "Gemfile" }}
|
15
|
+
- v1-dependencies-
|
16
|
+
|
17
|
+
- run:
|
18
|
+
name: install dependencies
|
19
|
+
command: |
|
20
|
+
gem install bundler
|
21
|
+
bundle update --jobs=4 --retry=3 --path tmp/bundle || \
|
22
|
+
bundle install --jobs=4 --retry=3 --path tmp/bundle
|
23
|
+
|
24
|
+
- save_cache:
|
25
|
+
paths:
|
26
|
+
- ./tmp/bundle
|
27
|
+
key: v1-dependencies-{{ checksum "Gemfile" }}
|
28
|
+
|
29
|
+
- run:
|
30
|
+
name: run tests
|
31
|
+
command: |
|
32
|
+
bundle exec rake
|
data/README.md
CHANGED
@@ -4,6 +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)
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
@@ -12,14 +14,15 @@ Add this line to your application's Gemfile:
|
|
12
14
|
gem 'rails_console_toolkit'
|
13
15
|
```
|
14
16
|
|
15
|
-
And then
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
17
|
+
And then configure it within an initializer:
|
20
18
|
|
21
|
-
|
19
|
+
```ruby
|
20
|
+
# config/initializers/console.rb
|
22
21
|
|
22
|
+
RailsConsoleToolkit.configure do |config|
|
23
|
+
# helper definitions go here...
|
24
|
+
end
|
25
|
+
```
|
23
26
|
|
24
27
|
## Helper packs
|
25
28
|
|
@@ -28,7 +31,9 @@ Or install it yourself as:
|
|
28
31
|
```ruby
|
29
32
|
# config/initializers/console.rb
|
30
33
|
|
31
|
-
|
34
|
+
RailsConsoleToolkit.configure do |config|
|
35
|
+
config.use_pack :aliases
|
36
|
+
end
|
32
37
|
```
|
33
38
|
|
34
39
|
```
|
@@ -42,7 +47,9 @@ require 'rails_console_toolkit/aliases'
|
|
42
47
|
```ruby
|
43
48
|
# config/initializers/console.rb
|
44
49
|
|
45
|
-
|
50
|
+
RailsConsoleToolkit.configure do |config|
|
51
|
+
config.use_pack :utils
|
52
|
+
end
|
46
53
|
```
|
47
54
|
|
48
55
|
```
|
@@ -59,7 +66,9 @@ foo (3000.6ms)
|
|
59
66
|
```ruby
|
60
67
|
# config/initializers/console.rb
|
61
68
|
|
62
|
-
|
69
|
+
RailsConsoleToolkit.configure do |config|
|
70
|
+
config.use_pack :solidus
|
71
|
+
end
|
63
72
|
```
|
64
73
|
|
65
74
|
```
|
@@ -72,24 +81,17 @@ require 'rails_console_toolkit/aliases'
|
|
72
81
|
> country(...) # => will look for Spree::Country records by :id, :iso, :iso3, :iso_name, :name
|
73
82
|
```
|
74
83
|
|
75
|
-
##
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
# config/initializers/console.rb
|
79
|
-
|
80
|
-
# helper definitions go here...
|
81
|
-
|
82
|
-
RailsConsoleToolkit.install!
|
83
|
-
```
|
84
|
-
|
84
|
+
## Custom Helpers
|
85
85
|
|
86
86
|
### Generic helpers
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
# config/initializers/console.rb
|
90
90
|
|
91
|
-
RailsConsoleToolkit.
|
92
|
-
:
|
91
|
+
RailsConsoleToolkit.configure do |config|
|
92
|
+
config.helper :foo do
|
93
|
+
:bar
|
94
|
+
end
|
93
95
|
end
|
94
96
|
```
|
95
97
|
|
@@ -104,7 +106,9 @@ end
|
|
104
106
|
```ruby
|
105
107
|
# config/initializers/console.rb
|
106
108
|
|
107
|
-
RailsConsoleToolkit.
|
109
|
+
RailsConsoleToolkit.configure do |config|
|
110
|
+
config.alias :r, :reload!
|
111
|
+
end
|
108
112
|
```
|
109
113
|
|
110
114
|
```
|
@@ -118,7 +122,9 @@ RailsConsoleToolkit.alias :r, :reload!
|
|
118
122
|
```ruby
|
119
123
|
# config/initializers/console.rb
|
120
124
|
|
121
|
-
RailsConsoleToolkit.
|
125
|
+
RailsConsoleToolkit.configure do |config|
|
126
|
+
config.model_helper 'Spree::Product', as: :product, by: %i[:name, :slug]
|
127
|
+
end
|
122
128
|
```
|
123
129
|
|
124
130
|
|
@@ -136,10 +142,11 @@ RailsConsoleToolkit.model_helper 'Spree::Product', as: :product, by: %i[:name, :
|
|
136
142
|
```ruby
|
137
143
|
# config/initializers/console.rb
|
138
144
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
145
|
+
RailsConsoleToolkit.configure do |config|
|
146
|
+
# Will define an alias :x for "exit"
|
147
|
+
config.use_pack :aliases
|
148
|
+
config.remove_helper :x
|
149
|
+
end
|
143
150
|
```
|
144
151
|
|
145
152
|
```
|
@@ -171,5 +178,6 @@ This project is funded and maintained by the [Nebulab][nebulab] team.
|
|
171
178
|
We firmly believe in the power of open-source. [Contact us][contact-us] if you
|
172
179
|
like our work and you need help with your project design or development.
|
173
180
|
|
174
|
-
[nebulab]:
|
175
|
-
[nebulab-logo]:
|
181
|
+
[nebulab]: https://nebulab.it/
|
182
|
+
[nebulab-logo]: https://nebulab.it/assets/images/public/logo.svg
|
183
|
+
[contact-us]: https://nebulab.it/contact-us/
|
@@ -1,57 +1,19 @@
|
|
1
1
|
require "rails_console_toolkit/version"
|
2
|
-
require "active_support/core_ext/string/inflections"
|
3
2
|
|
4
3
|
module RailsConsoleToolkit
|
5
|
-
|
4
|
+
autoload :Helpers, "rails_console_toolkit/helpers"
|
6
5
|
|
7
6
|
class Error < StandardError; end
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
helper_methods.each do |name, block|
|
13
|
-
Rails::ConsoleMethods.define_method(name, &block)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def helper(name, &block)
|
18
|
-
helper_methods[name.to_sym] = block
|
8
|
+
def self.setup
|
9
|
+
extend Helpers
|
19
10
|
end
|
20
11
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
record = nil # use the closure as a cache
|
28
|
-
|
29
|
-
helper method_name do |key = nil|
|
30
|
-
unless cached
|
31
|
-
record = nil
|
32
|
-
raise("missing key for #{key}") unless key
|
33
|
-
end
|
34
|
-
|
35
|
-
if key
|
36
|
-
record ||= klass.find(key) if key.is_a? Numeric
|
37
|
-
attribute_names.find { |name| record ||= klass.find_by(name => key) }
|
38
|
-
end
|
39
|
-
|
40
|
-
record
|
12
|
+
def self.configure(&block)
|
13
|
+
Rails.application.console do
|
14
|
+
setup
|
15
|
+
block.call(self)
|
16
|
+
install!
|
41
17
|
end
|
42
18
|
end
|
43
|
-
|
44
|
-
def alias_helper(new_name, old_name)
|
45
|
-
helper(new_name) { send(old_name) }
|
46
|
-
end
|
47
|
-
|
48
|
-
def remove_helper(name)
|
49
|
-
helper_methods.delete(name.to_sym)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def helper_methods
|
55
|
-
@helper_methods ||= {}
|
56
|
-
end
|
57
19
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
RailsConsoleToolkit.alias_helper :x, :exit
|
2
|
-
RailsConsoleToolkit.alias_helper :r, :reload
|
2
|
+
RailsConsoleToolkit.alias_helper :r, :reload!
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
2
|
+
|
3
|
+
module RailsConsoleToolkit::Helpers
|
4
|
+
def use_pack pack_name
|
5
|
+
unless %w[aliases solidus utils].include? pack_name.to_s
|
6
|
+
raise Error, "unknown pack name: #{pack_name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
require "rails_console_toolkit/#{pack_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def install!(target_module = Rails::ConsoleMethods)
|
13
|
+
helper_methods.each do |name, block|
|
14
|
+
target_module.define_method(name, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def helper(name, &block)
|
19
|
+
helper_methods[name.to_sym] = block
|
20
|
+
end
|
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
|
+
attribute_names = by || []
|
26
|
+
|
27
|
+
record = nil # use the closure as a cache
|
28
|
+
|
29
|
+
helper method_name do |key = nil|
|
30
|
+
record = nil unless cached
|
31
|
+
|
32
|
+
if key
|
33
|
+
record = nil
|
34
|
+
record = key if klass === key
|
35
|
+
record ||= klass.find(key) if Numeric === key
|
36
|
+
attribute_names.find { |name| record ||= klass.find_by(name => key) }
|
37
|
+
end
|
38
|
+
|
39
|
+
record
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def alias_helper(new_name, old_name)
|
44
|
+
helper(new_name) { |*args, &block| send(old_name, *args, &block) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove_helper(name)
|
48
|
+
helper_methods.delete(name.to_sym)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def helper_methods
|
54
|
+
@helper_methods ||= {}
|
55
|
+
end
|
56
|
+
end
|
@@ -11,3 +11,6 @@ RailsConsoleToolkit.model_helper Spree::Taxon, as: :taxon, by: [:permalink]
|
|
11
11
|
RailsConsoleToolkit.model_helper Spree::Order, as: :order, by: [:number]
|
12
12
|
RailsConsoleToolkit.model_helper Spree::User, as: :user, by: [:email]
|
13
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 :promo, :promotion
|
@@ -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", "
|
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.1
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-03 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:
|
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:
|
54
|
+
version: 12.3.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +74,7 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".circleci/config.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- ".travis.yml"
|
79
80
|
- Gemfile
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- bin/setup
|
85
86
|
- lib/rails_console_toolkit.rb
|
86
87
|
- lib/rails_console_toolkit/aliases.rb
|
88
|
+
- lib/rails_console_toolkit/helpers.rb
|
87
89
|
- lib/rails_console_toolkit/solidus.rb
|
88
90
|
- lib/rails_console_toolkit/utils.rb
|
89
91
|
- lib/rails_console_toolkit/version.rb
|
@@ -109,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
111
|
- !ruby/object:Gem::Version
|
110
112
|
version: '0'
|
111
113
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.1.2
|
113
115
|
signing_key:
|
114
116
|
specification_version: 4
|
115
117
|
summary: Configurable Rails Console Helpers
|