rails_console_toolkit 0.2.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -27
- data/lib/rails_console_toolkit.rb +8 -44
- 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 +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 815b4d4c110fd99045c1ed9f83f8b4628525d4ea276b834cc91ddaa0a1e16c57
|
4
|
+
data.tar.gz: 91a672c19d578427780773cf85b62f9826132fc830c4348985c1e9568a3833f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54995255818f0891f50c155522c3b9f8a8799b017521dc994987ddc0747f08af817c6def93fba16307b067425cc7419a1b73df5c48a9f2ffa371c644063b3b13
|
7
|
+
data.tar.gz: 28f48d10562cc11eb1b352de71dbe9c1984be82ec9f7e9b3a4ee4c2a9e638c15ffeb54c2fabe4ae68795103076924415670cd84f9d916dae9389db68fe879aee
|
data/README.md
CHANGED
@@ -14,14 +14,15 @@ Add this line to your application's Gemfile:
|
|
14
14
|
gem 'rails_console_toolkit'
|
15
15
|
```
|
16
16
|
|
17
|
-
And then
|
17
|
+
And then configure it within an initializer:
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install rails_console_toolkit
|
19
|
+
```ruby
|
20
|
+
# config/initializers/console.rb
|
24
21
|
|
22
|
+
RailsConsoleToolkit.configure do |config|
|
23
|
+
# helper definitions go here...
|
24
|
+
end
|
25
|
+
```
|
25
26
|
|
26
27
|
## Helper packs
|
27
28
|
|
@@ -30,7 +31,9 @@ Or install it yourself as:
|
|
30
31
|
```ruby
|
31
32
|
# config/initializers/console.rb
|
32
33
|
|
33
|
-
|
34
|
+
RailsConsoleToolkit.configure do |config|
|
35
|
+
config.use_pack :aliases
|
36
|
+
end
|
34
37
|
```
|
35
38
|
|
36
39
|
```
|
@@ -44,7 +47,9 @@ require 'rails_console_toolkit/aliases'
|
|
44
47
|
```ruby
|
45
48
|
# config/initializers/console.rb
|
46
49
|
|
47
|
-
|
50
|
+
RailsConsoleToolkit.configure do |config|
|
51
|
+
config.use_pack :utils
|
52
|
+
end
|
48
53
|
```
|
49
54
|
|
50
55
|
```
|
@@ -61,7 +66,9 @@ foo (3000.6ms)
|
|
61
66
|
```ruby
|
62
67
|
# config/initializers/console.rb
|
63
68
|
|
64
|
-
|
69
|
+
RailsConsoleToolkit.configure do |config|
|
70
|
+
config.use_pack :solidus
|
71
|
+
end
|
65
72
|
```
|
66
73
|
|
67
74
|
```
|
@@ -74,24 +81,17 @@ require 'rails_console_toolkit/solidus'
|
|
74
81
|
> country(...) # => will look for Spree::Country records by :id, :iso, :iso3, :iso_name, :name
|
75
82
|
```
|
76
83
|
|
77
|
-
##
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
# config/initializers/console.rb
|
81
|
-
|
82
|
-
# helper definitions go here...
|
83
|
-
|
84
|
-
RailsConsoleToolkit.install!
|
85
|
-
```
|
86
|
-
|
84
|
+
## Custom Helpers
|
87
85
|
|
88
86
|
### Generic helpers
|
89
87
|
|
90
88
|
```ruby
|
91
89
|
# config/initializers/console.rb
|
92
90
|
|
93
|
-
RailsConsoleToolkit.
|
94
|
-
:
|
91
|
+
RailsConsoleToolkit.configure do |config|
|
92
|
+
config.helper :foo do
|
93
|
+
:bar
|
94
|
+
end
|
95
95
|
end
|
96
96
|
```
|
97
97
|
|
@@ -106,7 +106,9 @@ end
|
|
106
106
|
```ruby
|
107
107
|
# config/initializers/console.rb
|
108
108
|
|
109
|
-
RailsConsoleToolkit.
|
109
|
+
RailsConsoleToolkit.configure do |config|
|
110
|
+
config.alias :r, :reload!
|
111
|
+
end
|
110
112
|
```
|
111
113
|
|
112
114
|
```
|
@@ -120,7 +122,9 @@ RailsConsoleToolkit.alias :r, :reload!
|
|
120
122
|
```ruby
|
121
123
|
# config/initializers/console.rb
|
122
124
|
|
123
|
-
RailsConsoleToolkit.
|
125
|
+
RailsConsoleToolkit.configure do |config|
|
126
|
+
config.model_helper 'Spree::Product', as: :product, by: %i[:name, :slug]
|
127
|
+
end
|
124
128
|
```
|
125
129
|
|
126
130
|
|
@@ -138,10 +142,11 @@ RailsConsoleToolkit.model_helper 'Spree::Product', as: :product, by: %i[:name, :
|
|
138
142
|
```ruby
|
139
143
|
# config/initializers/console.rb
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
145
150
|
```
|
146
151
|
|
147
152
|
```
|
@@ -1,55 +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
|
-
target_module.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
|
-
record = nil unless cached
|
31
|
-
|
32
|
-
if key
|
33
|
-
record = nil
|
34
|
-
record ||= klass.find(key) if Numeric === key
|
35
|
-
attribute_names.find { |name| record ||= klass.find_by(name => key) }
|
36
|
-
end
|
37
|
-
|
38
|
-
record
|
12
|
+
def self.configure(&block)
|
13
|
+
Rails.application.console do
|
14
|
+
setup
|
15
|
+
block.call(self)
|
16
|
+
install!
|
39
17
|
end
|
40
18
|
end
|
41
|
-
|
42
|
-
def alias_helper(new_name, old_name)
|
43
|
-
helper(new_name) { send(old_name) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def remove_helper(name)
|
47
|
-
helper_methods.delete(name.to_sym)
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def helper_methods
|
53
|
-
@helper_methods ||= {}
|
54
|
-
end
|
55
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_helper :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.2
|
4
|
+
version: 0.5.2
|
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:
|
11
|
+
date: 2020-07-23 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
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- bin/setup
|
86
86
|
- lib/rails_console_toolkit.rb
|
87
87
|
- lib/rails_console_toolkit/aliases.rb
|
88
|
+
- lib/rails_console_toolkit/helpers.rb
|
88
89
|
- lib/rails_console_toolkit/solidus.rb
|
89
90
|
- lib/rails_console_toolkit/utils.rb
|
90
91
|
- lib/rails_console_toolkit/version.rb
|
@@ -95,7 +96,7 @@ licenses:
|
|
95
96
|
metadata:
|
96
97
|
homepage_uri: https://github.com/nebulab/rails_console_toolkit#readme
|
97
98
|
source_code_uri: https://github.com/nebulab/rails_console_toolkit
|
98
|
-
post_install_message:
|
99
|
+
post_install_message:
|
99
100
|
rdoc_options: []
|
100
101
|
require_paths:
|
101
102
|
- lib
|
@@ -110,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
114
|
-
signing_key:
|
114
|
+
rubygems_version: 3.1.4
|
115
|
+
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: Configurable Rails Console Helpers
|
117
118
|
test_files: []
|