pebblebed 0.0.50 → 0.0.51

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.
@@ -24,14 +24,6 @@ module Pebblebed
24
24
  }
25
25
  end
26
26
 
27
- def missing_requirements_for_role(role)
28
- roles = self.class.roles
29
- current_role = roles.select {|r| r[:name] == @role[:name] }.first
30
- for_role = roles.select {|r| role.to_sym == r[:name] }.first
31
- raise UndefinedRole, "The role :#{role} is not defined." unless for_role
32
- roles[roles.index(current_role)..roles.index(for_role)].map{|r| r[:requirements]}.flatten.uniq.compact
33
- end
34
-
35
27
  def self.requirements_for_role(role)
36
28
  the_role = @roles.select {|r| r[:name] == role.to_sym }.first
37
29
  raise UndefinedRole, "The role :#{role} is not defined." unless the_role
@@ -51,20 +43,20 @@ module Pebblebed
51
43
  def find_current_role
52
44
  the_role = begin
53
45
  collected_roles = []
46
+ collected_requirements = []
54
47
  self.class.roles.each do |role|
55
- collected_capabilities = []
56
48
  if role[:requirements].any?
57
49
  role[:requirements].each do |requirement|
58
50
  # Check based on implemented check-methods in the subclass.
59
51
  begin
60
52
  if __send__("check_#{requirement}".to_sym)
61
- collected_capabilities << requirement
53
+ collected_requirements << requirement
62
54
  end
63
55
  rescue NoMethodError
64
56
  raise NoMethodError, "You must implement method named :check_#{requirement} that returns true or false"
65
57
  end
66
58
  end
67
- if (role[:requirements] & collected_capabilities) == role[:requirements]
59
+ if (role[:requirements] & collected_requirements) == role[:requirements]
68
60
  the_role = role
69
61
  collected_roles << role
70
62
  end
@@ -74,7 +66,6 @@ module Pebblebed
74
66
  end
75
67
  end
76
68
  owned_capabilities = collected_roles.map{|c| c[:capabilities]}.flatten.compact.uniq
77
- owned_requirements = collected_roles.map{|c| c[:requirements]}.flatten.compact.uniq
78
69
  all_capabilities = self.class.roles.map{|r| r[:capabilities]}.flatten.compact.uniq
79
70
  the_role.merge!(:upgrades => begin
80
71
  upgraders = {}
@@ -82,7 +73,7 @@ module Pebblebed
82
73
  next if owned_capabilities.include?(c)
83
74
  self.class.roles.select{|r| r[:capabilities].include?(c)}.each do |r|
84
75
  upgraders[c] ||= []
85
- upgraders[c] << r[:requirements] - owned_requirements
76
+ upgraders[c] << r[:requirements] - collected_requirements
86
77
  upgraders[c].flatten!.uniq!
87
78
  end
88
79
  end
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.50"
2
+ VERSION = "0.0.51"
3
3
  end
@@ -83,11 +83,6 @@ describe Pebblebed::Security::RoleSchema do
83
83
  }.to raise_error(Pebblebed::Security::RoleSchema::UndefinedRole)
84
84
  end
85
85
 
86
- it "gives the missing requirements for current role compared to a role" do
87
- schema.missing_requirements_for_role(:identified).should == [:logged_in]
88
- schema.missing_requirements_for_role(:contributor).should == [:logged_in, :verified_mobile]
89
- end
90
-
91
86
  end
92
87
 
93
88
  context "as guest" do
@@ -110,7 +105,7 @@ describe Pebblebed::Security::RoleSchema do
110
105
  CustomRoleSchema.new(connector, contributor)
111
106
  }
112
107
 
113
- it "returns the idenitified role" do
108
+ it "returns the idenitified role with an upgrade for :verified_mobile only" do
114
109
  schema.role.should == {:current=>:identified, :capabilities=>[:kudo], :upgrades=>{:comment=>[:verified_mobile]}}
115
110
  end
116
111
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.50
4
+ version: 0.0.51
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: