console_creep 0.1.0 → 0.3.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: a05db079b595d421b6e03b7fd4131fd42b1dc733f3b97cecb7d26fe31167ec81
4
- data.tar.gz: 1fbf079ec69f6199980a24324b5b7e1b945da2f3e8b53e1e83d2811f6a199c75
3
+ metadata.gz: d112068dfc26c9cfe1d998f0922a4ae3d5dcfa3f7c9530eb8c3ec6d78e25a66d
4
+ data.tar.gz: bc56a4e7f298817f14a391850223638f71e45261dc2cf266f72c3d04d9bc39d8
5
5
  SHA512:
6
- metadata.gz: c908718eae6906702a490514486c01c5f1e4c1cd22358e32f132384fec65884a5e13cb99fe319eb47a44c1ddd774e2d7f9656960742fb9e5a9d32c52996a25ae
7
- data.tar.gz: 78f5f1a1738a9bd3be7e2c8aacdd90293b43433caa6cc30b0ce8ce90bfb69572b9024fe728567b34157b2c8d69d78525f0a0376ec32f42a0c06cc21914a7dc8f
6
+ metadata.gz: aef5439225655d1d0b4d3fd7797ef31d4c90fecc011e5724a3363020dd19e7d31952ec550fe7a45cafbe67d6a405655cb3a79d95ec2fbb2cb0d68095be0118b3
7
+ data.tar.gz: 2357f5f55fc32f0a4c90671e3f21b6f228776785dd2a5ff95aa5f1006979c9424313f233d6e0584b1ee66acfaa94be0aeb04953519b002cf5b77da421387144c
data/README.md CHANGED
@@ -49,16 +49,24 @@ ConsoleCreep.setup do |config|
49
49
  # options are `:error`, `:result`, `:command`
50
50
  # config.store = :database, { model: 'ConsoleCreepLog', except: [:result] }
51
51
 
52
- ## Enabled for this Rails.env (default is `Rails.env.production?`)
53
- # config.enabled = true
52
+ ## Authentication
53
+ #
54
+ # Defaults to :devise but there is no other one at the moment.
55
+ # Create your own. See `lib/authenticators/devise_authenticator.rb``
56
+ #
57
+ # Use the devise authenticator and use a custom class:
58
+ # config.authenticator = :devise, { class: "AdminUser" }
59
+ #
60
+ # or use a proc:
61
+ # config.authenticator = :devise, { if: ->(user) { user.admin? } }
62
+
63
+ ## Welcome Message
64
+ #
65
+ # Change the welcome message.
66
+ # config.welcome = ->(user) { "hey user #{user}" }
54
67
 
55
68
  ## Enabled for the logged-in user (default is true)
56
69
  # config.log_for_user = ->(user) { !user.doctor? }
57
-
58
- ## Change the authentication scheme
59
- # config.authenticator = :devise
60
- # if your class name is Admin:
61
- # config.authenticator = :devise, { class: 'Admin' }
62
70
  end
63
71
  ```
64
72
 
@@ -24,8 +24,18 @@ module ConsoleCreep
24
24
  print 'Password: '
25
25
  pass = $stdin.noecho(&:gets)
26
26
  if user.valid_password?(pass.strip)
27
- set_current_user(user)
28
- ConsoleCreep.config.welcome.call(user)
27
+ if @options[:if]
28
+ if @options[:if].call(user)
29
+ set_current_user(user)
30
+ ConsoleCreep.config.welcome.call(user)
31
+ else
32
+ puts "User not admin."
33
+ die
34
+ end
35
+ else
36
+ set_current_user(user)
37
+ ConsoleCreep.config.welcome.call(user)
38
+ end
29
39
  else
30
40
  puts 'Provided password is not correct! Exiting...'
31
41
  die
@@ -18,14 +18,19 @@ module ConsoleCreep
18
18
  @enabled = Rails.env.production?
19
19
  end
20
20
 
21
- def authenticator=(*args)
22
- auth_class = args.shift
21
+ def authenticator=(args)
22
+ klass = args.first
23
23
  options = args.extract_options!
24
+ if klass == :devise
25
+ auth_class = Authenticators::DeviseAuthenticator
26
+ else
27
+ auth_class = klass.to_s.constantize
28
+ end
24
29
  @authenticator = auth_class.new(options)
25
30
  end
26
31
 
27
- def store=(*args)
28
- store_class = args.shift
32
+ def store=(args)
33
+ store_class = args.first
29
34
  options = args.extract_options!
30
35
  klass = if store_class == :database
31
36
  Stores::DatabaseStore
@@ -5,7 +5,7 @@ module Rails
5
5
  ConsoleCreep.config.authenticator.call
6
6
  return true
7
7
  end
8
- exit("Exiting console.")
8
+ exit(0)
9
9
  end
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConsoleCreep
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_creep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody