ez-permissions 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dc0e6f33ade1b7263f4804869691932b40412a7be67252e079aa9e85e8a2e69
4
- data.tar.gz: ca833df2913ce7d842f125d07bc685b28b74f349c1016b5169a3946ab1e8d0ee
3
+ metadata.gz: 6145e511809044ca7673cfd275fa009fbfad5a5dfccd9457469116bf6039a0ad
4
+ data.tar.gz: aaac5b48a4fa790de8df4f97ee86b4b42c52c5d130a24289c1876a298f7d1691
5
5
  SHA512:
6
- metadata.gz: 7c4aed6394c86da052b307eccc2dc76c9fa89e53a66661a557ee8e5f01b36c2a273c990fdbfc2adea2bd7d39457a34f74b27ada0861edd52cb8ea805963137b0
7
- data.tar.gz: d2edf56f4dcfbf2f7dabf9b6bf65ca9b535c3655e6cd9e1638e5e7f84916c08153baca23a3751d2d848fef348069acd30083edf586a2f026e93a47f9ce389525
6
+ metadata.gz: 90d8bc79ec20592692ca6c4a62096c8a6d166dec53e3514f53da77271cf80c83292e3fd8dfc3bec25dd11771abe70b632e365b7a646aa597b1fc8f3e18a54b96
7
+ data.tar.gz: bd6f64a211c6b233c673a74ef2992531794045a56025d7fa6dbec8326290caeb3b1647109105408300a8a960f33f094fd5492cb79b8c324b5132cebce8b9408d
@@ -26,33 +26,31 @@ module Ez
26
26
  end
27
27
 
28
28
  def add(name, options = {})
29
- if self.class.resource(name)
30
- return message("[WARN] Ez::Permissions resource [#{name}] has been already defined!")
31
- end
29
+ return message("Resource [#{name}] has been already defined!") if self.class.resource(name)
32
30
 
33
31
  resource = Ez::Permissions::Resource.new(name, options)
34
32
 
33
+ @resources << resource
34
+
35
+ return unless seed_to_db(resource)
36
+
35
37
  message(
36
- "[SUCCESS] Ez::Permissions resource [#{name}] has been successfully registred with actions: \
37
- [#{resource.actions.join(', ')}]"
38
+ "Resource [#{name}] has been successfully registred with actions: [#{resource.actions.join(', ')}]",
39
+ 'SUCCESS'
38
40
  )
39
-
40
- @resources << resource
41
- seed_to_db resource
42
41
  end
43
42
 
44
43
  private
45
44
 
46
- def message(txt)
47
- STDOUT.puts(txt)
45
+ def message(txt, level = 'WARN')
46
+ return if Ez::Permissions.config.mute_stdout
47
+
48
+ STDOUT.puts("[#{level}] Ez::Permissions: #{txt}")
48
49
  end
49
50
 
50
51
  def seed_to_db(resource)
51
52
  return unless try_db_connection
52
-
53
- return unless ActiveRecord::Base.connection.data_source_exists?(Ez::Permissions.config.permissions_table_name)
54
-
55
- return unless resource.actions
53
+ return unless check_permissions_table
56
54
 
57
55
  resource.actions.each do |action|
58
56
  Ez::Permissions::Permission.where(
@@ -65,7 +63,15 @@ module Ez
65
63
  def try_db_connection
66
64
  ActiveRecord::Base.connection
67
65
  rescue ActiveRecord::NoDatabaseError
68
- STDOUT.puts 'Database does not exist'
66
+ message('Database does not exist')
67
+ false
68
+ end
69
+
70
+ def check_permissions_table
71
+ permissions_table = Ez::Permissions.config.permissions_table_name
72
+ return true if ActiveRecord::Base.connection.data_source_exists?(permissions_table)
73
+
74
+ message("Table #{permissions_table} does not exists. Please, check migrations")
69
75
  false
70
76
  end
71
77
  end
@@ -10,7 +10,7 @@ module Ez
10
10
  def initialize(name, options = {})
11
11
  @name = name
12
12
  @model = options.fetch(:model, nil)
13
- @actions = process_actions(options.fetch(:actions, nil))
13
+ @actions = process_actions(options.fetch(:actions, []))
14
14
  end
15
15
 
16
16
  def <=>(other)
@@ -20,7 +20,7 @@ module Ez
20
20
  private
21
21
 
22
22
  def process_actions(actions)
23
- return ACTIONS unless actions
23
+ return ACTIONS if actions.empty?
24
24
 
25
25
  actions.map { |action| action == :crud ? ACTIONS : action }.flatten
26
26
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ez
4
4
  module Permissions
5
- VERSION = '0.2.1'
5
+ VERSION = '0.2.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez-permissions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Sveredyuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ez-core