bali 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ require "stringio"
2
+ require "date"
3
+
4
+ # module that would allow all defined rules to be printed for check
5
+ module Bali::Printer
6
+ module_function
7
+
8
+ SEPARATOR = " " * 6
9
+ SUBTARGET_TITLE_SEPARATOR = SEPARATOR + ("-" * 80) + "\n"
10
+
11
+ def pretty_print
12
+ output = StringIO.new
13
+
14
+ # build up the string for pretty printing rules
15
+ Bali::RULE_CLASS_MAP.each do |klass, rule_class|
16
+ output << "===== #{klass.to_s} =====\n\n"
17
+
18
+ rule_class.rule_groups.each do |subtarget, rule_group|
19
+ print_rule_group(rule_group, output)
20
+ end
21
+
22
+ if rule_class.others_rule_group.rules.any?
23
+ print_rule_group(rule_class.others_rule_group, output)
24
+ end
25
+ output << "\n\n"
26
+ end
27
+
28
+ output << "\n\n"
29
+ output << DateTime.now.strftime("Printed at %d-%m-%Y %I:%M%p %Z")
30
+
31
+ output.string
32
+ end
33
+
34
+ def print_rule_group(rule_group, target_io)
35
+ target = rule_group.target.to_s
36
+ subtarget = rule_group.subtarget.to_s.capitalize
37
+ subtarget = "Others" if subtarget == "__*__"
38
+ is_zeus = rule_group.zeus?
39
+ is_plant = rule_group.plant?
40
+ counter = 0
41
+
42
+ target_io << "#{SEPARATOR}#{subtarget}, can all: #{is_zeus}, cannot all: #{is_plant}\n"
43
+ target_io << SUBTARGET_TITLE_SEPARATOR
44
+
45
+ if is_zeus
46
+ target_io << "#{SEPARATOR} #{counter+=1}. #{subtarget} can do anything except if explicitly stated otherwise\n"
47
+ elsif is_plant
48
+ target_io << "#{SEPARATOR} #{counter+=1}. #{subtarget} cannot do anything except if explicitly stated otherwise\n"
49
+ end
50
+
51
+ rule_group.rules.each do |rule|
52
+ written_rule = StringIO.new
53
+ written_rule << "#{SEPARATOR} #{counter+=1}. #{subtarget} #{rule.auth_val} #{rule.operation} #{target}"
54
+ if rule.has_decider?
55
+ written_rule << ", with condition"
56
+ end
57
+ written_rule << "\n"
58
+ target_io << written_rule.string
59
+ end
60
+
61
+ target_io << "\n"
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module Bali
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.1"
3
3
  end
metadata CHANGED
@@ -1,69 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bali
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Pahlevi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '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
54
  version: '3.3'
55
- description: "Bali (Bulwark Authorization Library) is a universal authorization library,
56
- in the sense that \n it does not assume you to use specific
57
- Ruby library/gem/framework."
55
+ description: ! "Bali (Bulwark Authorization Library) is a universal authorization
56
+ library, in the sense that \n it does not assume you to
57
+ use specific Ruby library/gem/framework."
58
58
  email:
59
59
  - adam.pahlevi@gmail.com
60
60
  executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - ".gitignore"
65
- - ".rspec"
66
- - ".travis.yml"
64
+ - .gitignore
65
+ - .rspec
66
+ - .travis.yml
67
+ - CHANGELOG.md
67
68
  - CODE_OF_CONDUCT.md
68
69
  - Gemfile
69
70
  - LICENSE.txt
@@ -86,6 +87,7 @@ files:
86
87
  - lib/bali/integrators/all_integrators.rb
87
88
  - lib/bali/integrators/rules_integrator.rb
88
89
  - lib/bali/objector.rb
90
+ - lib/bali/printer.rb
89
91
  - lib/bali/version.rb
90
92
  homepage: https://github.com/saveav/bali
91
93
  licenses:
@@ -97,20 +99,19 @@ require_paths:
97
99
  - lib
98
100
  required_ruby_version: !ruby/object:Gem::Requirement
99
101
  requirements:
100
- - - ">="
102
+ - - ! '>='
101
103
  - !ruby/object:Gem::Version
102
104
  version: '0'
103
105
  required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  requirements:
105
- - - ">="
107
+ - - ! '>='
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
111
  rubyforge_project:
110
- rubygems_version: 2.4.5
112
+ rubygems_version: 2.4.8
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Bali is a powerful, framework-agnostic, thread-safe Ruby language authorization
114
116
  library
115
117
  test_files: []
116
- has_rdoc: