simple_crowd 1.0.5 → 1.1.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.
- data/.document +5 -0
- data/Gemfile +7 -0
- data/Rakefile +1 -1
- data/lib/simple_crowd/cache/null_store.rb +86 -0
- data/lib/simple_crowd/client.rb +334 -298
- data/lib/simple_crowd/crowd_entity.rb +199 -199
- data/lib/simple_crowd/crowd_error.rb +24 -15
- data/lib/simple_crowd/group.rb +11 -11
- data/lib/simple_crowd/mappers/soap_attributes.rb +13 -13
- data/lib/simple_crowd/mock_client.rb +3 -2
- data/lib/simple_crowd/user.rb +17 -17
- data/lib/simple_crowd/version.rb +1 -1
- data/lib/simple_crowd.rb +53 -51
- data/simple_crowd.gemspec +19 -50
- data/test/crowd_config.yml.example +6 -6
- data/test/factories.rb +11 -9
- data/test/helper.rb +32 -28
- data/test/test_client.rb +329 -331
- data/test/test_simple_crowd.rb +22 -22
- data/test/test_user.rb +69 -69
- metadata +75 -158
@@ -1,199 +1,199 @@
|
|
1
|
-
module SimpleCrowd
|
2
|
-
class ExtendedProperty < Hashie::Dash
|
3
|
-
property :name
|
4
|
-
property :default
|
5
|
-
property :attribute
|
6
|
-
property :immutable
|
7
|
-
property :maps, :default => {}
|
8
|
-
property :mappers, :default => {}
|
9
|
-
def immutable?; @immutable; end
|
10
|
-
def is_attribute?; @attribute end
|
11
|
-
end
|
12
|
-
class CrowdEntity < Hashie::Mash
|
13
|
-
def initialize(data = {}, notused = nil)
|
14
|
-
self.class.properties.each do |prop|
|
15
|
-
self.send("#{prop.name}=", self.class.defaults[prop.name.to_sym])
|
16
|
-
end
|
17
|
-
attrs = data[:attributes].nil? ? [] : data[:attributes].keys
|
18
|
-
data.merge! data[:attributes] unless attrs.empty?
|
19
|
-
data.delete :attributes
|
20
|
-
data.each_pair do |att, value|
|
21
|
-
#ruby_att = att_to_ruby att
|
22
|
-
ruby_att = att
|
23
|
-
real_att = real_key_for ruby_att
|
24
|
-
(@attributes ||= []) << real_att if attrs.include?(att)
|
25
|
-
prop = self.class.property_by_name(real_att)
|
26
|
-
self.send("#{real_att}=", value) unless prop.nil?
|
27
|
-
self[real_att] = value if prop.nil?
|
28
|
-
end
|
29
|
-
# We just initialized the attributes so clear the dirty status
|
30
|
-
dirty_properties.clear
|
31
|
-
end
|
32
|
-
def self.property(property_name, options = {})
|
33
|
-
property_name = property_name.to_sym
|
34
|
-
|
35
|
-
maps = options.inject({}) {|map, (key, value)| map[$1.to_sym] = value.to_sym if key.to_s =~ /^map_(.*)$/; map }
|
36
|
-
mappers = options.inject({}) {|map, (key, value)| map[$1.to_sym] = value if key.to_s =~ /^mapper_(.*)$/; map }
|
37
|
-
options.reject! {|key, val| key.to_s =~ /^map_(.*)$/ || key.to_s =~ /^mapper_(.*)$/ }
|
38
|
-
(@properties ||= []) << ExtendedProperty.new({:name => property_name, :maps => maps, :mappers => mappers}.merge(options))
|
39
|
-
(@attributes ||= []) << property_name if options[:attribute]
|
40
|
-
|
41
|
-
class_eval <<-RUBY
|
42
|
-
def #{property_name}
|
43
|
-
self[:#{property_name}]
|
44
|
-
end
|
45
|
-
def #{property_name}=(val)
|
46
|
-
(dirty_properties << :#{property_name}).uniq! unless val == self[:#{property_name}]
|
47
|
-
self[:#{property_name}] = val
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
|
51
|
-
maps.each_value do |v|
|
52
|
-
alias_method v, property_name
|
53
|
-
alias_method :"#{v}=", :"#{property_name}="
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.properties
|
58
|
-
properties = []
|
59
|
-
ancestors.each do |elder|
|
60
|
-
if elder.instance_variable_defined?("@properties")
|
61
|
-
properties << elder.instance_variable_get("@properties")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
properties.reverse.flatten
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.property_by_name(property_name)
|
69
|
-
property_name = property_name.to_sym
|
70
|
-
properties.detect {|p| p.name == property_name || p.maps.value?(property_name)}
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.properties_by_name(property_name)
|
74
|
-
property_name = property_name.to_sym
|
75
|
-
properties.select {|p| p.name == property_name || p.maps.value?(property_name)}
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.property?(prop)
|
79
|
-
!property_by_name(prop.to_sym).nil?
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.defaults
|
83
|
-
properties.inject({}) {|hash, prop| hash[prop.name] = prop['default'] unless prop['default'].nil?; hash }
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.attribute_mappers hash = nil
|
87
|
-
@attribute_mappers ||= {:soap => SimpleCrowd::Mappers::SoapAttributes}
|
88
|
-
unless hash.nil?
|
89
|
-
@attribute_mappers.merge! hash if hash.is_a? Hash
|
90
|
-
end
|
91
|
-
@attribute_mappers
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.map_for type
|
95
|
-
type = type.to_sym
|
96
|
-
properties.inject({}) {|hash, prop| hash[prop.name] = prop.maps[type] unless prop.maps[type].nil?; hash }
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.map_to type, entity
|
100
|
-
map = map_for type
|
101
|
-
attrs = {}
|
102
|
-
out = entity.inject({}) do |hash, (key, val)|
|
103
|
-
key = key.to_sym
|
104
|
-
catch(:skip_prop) do
|
105
|
-
unless val.nil?
|
106
|
-
mapped_key = map[key].nil? ? key : map[key]
|
107
|
-
prop = property_by_name key
|
108
|
-
if prop.nil?
|
109
|
-
attrs[mapped_key] = val
|
110
|
-
throw :skip_prop
|
111
|
-
end
|
112
|
-
mapper = prop.mappers[type]
|
113
|
-
#val = val.inject({}) {|attrs, (k, v)| attrs[property_by_name(k).maps[type]]= v unless v.nil?; attrs} if key == :attributes
|
114
|
-
val = mapper.produce val unless mapper.nil?
|
115
|
-
if prop.attribute || entity.attributes_keys.include?(key)
|
116
|
-
attrs[mapped_key] = val
|
117
|
-
else
|
118
|
-
hash[mapped_key] = val
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
hash
|
123
|
-
end
|
124
|
-
out[:attributes] = attribute_mappers[type].produce attrs
|
125
|
-
out
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.parse_from type, entity
|
129
|
-
entity[:attributes] = attribute_mappers[type].parse entity[:attributes]
|
130
|
-
parsed_entity = entity.inject({}) do |hash, (key, val)|
|
131
|
-
prop = property_by_name key
|
132
|
-
unless prop.nil?
|
133
|
-
mapper = prop.mappers[type]
|
134
|
-
val = mapper.parse val unless mapper.nil?
|
135
|
-
end
|
136
|
-
hash[key] = val
|
137
|
-
hash
|
138
|
-
end
|
139
|
-
self.new(parsed_entity)
|
140
|
-
end
|
141
|
-
|
142
|
-
def map_to type
|
143
|
-
self.class.map_to type, self
|
144
|
-
end
|
145
|
-
|
146
|
-
def attributes_keys
|
147
|
-
keys = []
|
148
|
-
self.class.ancestors.each do |elder|
|
149
|
-
if elder.instance_variable_defined?("@attributes")
|
150
|
-
keys << elder.instance_variable_get("@attributes")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
keys << @attributes unless @attributes.nil?
|
154
|
-
keys.flatten.uniq
|
155
|
-
end
|
156
|
-
|
157
|
-
def attributes
|
158
|
-
self.inject({}) {|hash, (k, v)| hash[k] = v if attributes_keys.include?(k.to_sym); hash}
|
159
|
-
end
|
160
|
-
|
161
|
-
def dirty_properties
|
162
|
-
@dirty_properties ||= Array.new
|
163
|
-
end
|
164
|
-
|
165
|
-
def dirty_attributes
|
166
|
-
dirty_properties & attributes_keys
|
167
|
-
end
|
168
|
-
|
169
|
-
def dirty? prop = nil
|
170
|
-
prop.nil? ? !@dirty_properties.empty? : @dirty_properties.include?(prop)
|
171
|
-
end
|
172
|
-
|
173
|
-
def clean
|
174
|
-
@dirty_properties = Array.new
|
175
|
-
end
|
176
|
-
|
177
|
-
def update_with attrs
|
178
|
-
current_keys = attributes_keys
|
179
|
-
attrs.each_pair {|k, v| self.send(:"#{k}=", v) if current_keys.include?(k.to_sym) && v != self.send(k.to_sym)}
|
180
|
-
end
|
181
|
-
|
182
|
-
def []= key, val
|
183
|
-
prop = self.class.property_by_name key
|
184
|
-
(@attributes ||= []) << key if prop.nil?
|
185
|
-
super
|
186
|
-
end
|
187
|
-
|
188
|
-
private
|
189
|
-
def self.real_key_for att
|
190
|
-
p = property_by_name att
|
191
|
-
p.nil? ? att : p.name
|
192
|
-
end
|
193
|
-
def self.att_to_ruby att
|
194
|
-
att.to_s =~ /^[a-z]*([A-Z][^A-Z]*)*$/ ? att.to_s.underscore.to_sym : att.to_sym
|
195
|
-
end
|
196
|
-
def real_key_for att; self.class.real_key_for att; end
|
197
|
-
def att_to_ruby att; self.class.att_to_ruby att; end
|
198
|
-
end
|
199
|
-
end
|
1
|
+
module SimpleCrowd
|
2
|
+
class ExtendedProperty < Hashie::Dash
|
3
|
+
property :name
|
4
|
+
property :default
|
5
|
+
property :attribute
|
6
|
+
property :immutable
|
7
|
+
property :maps, :default => {}
|
8
|
+
property :mappers, :default => {}
|
9
|
+
def immutable?; @immutable; end
|
10
|
+
def is_attribute?; @attribute end
|
11
|
+
end
|
12
|
+
class CrowdEntity < Hashie::Mash
|
13
|
+
def initialize(data = {}, notused = nil)
|
14
|
+
self.class.properties.each do |prop|
|
15
|
+
self.send("#{prop.name}=", self.class.defaults[prop.name.to_sym])
|
16
|
+
end
|
17
|
+
attrs = data[:attributes].nil? ? [] : data[:attributes].keys
|
18
|
+
data.merge! data[:attributes] unless attrs.empty?
|
19
|
+
data.delete :attributes
|
20
|
+
data.each_pair do |att, value|
|
21
|
+
#ruby_att = att_to_ruby att
|
22
|
+
ruby_att = att
|
23
|
+
real_att = real_key_for ruby_att
|
24
|
+
(@attributes ||= []) << real_att if attrs.include?(att)
|
25
|
+
prop = self.class.property_by_name(real_att)
|
26
|
+
self.send("#{real_att}=", value) unless prop.nil?
|
27
|
+
self[real_att] = value if prop.nil?
|
28
|
+
end
|
29
|
+
# We just initialized the attributes so clear the dirty status
|
30
|
+
dirty_properties.clear
|
31
|
+
end
|
32
|
+
def self.property(property_name, options = {})
|
33
|
+
property_name = property_name.to_sym
|
34
|
+
|
35
|
+
maps = options.inject({}) {|map, (key, value)| map[$1.to_sym] = value.to_sym if key.to_s =~ /^map_(.*)$/; map }
|
36
|
+
mappers = options.inject({}) {|map, (key, value)| map[$1.to_sym] = value if key.to_s =~ /^mapper_(.*)$/; map }
|
37
|
+
options.reject! {|key, val| key.to_s =~ /^map_(.*)$/ || key.to_s =~ /^mapper_(.*)$/ }
|
38
|
+
(@properties ||= []) << ExtendedProperty.new({:name => property_name, :maps => maps, :mappers => mappers}.merge(options))
|
39
|
+
(@attributes ||= []) << property_name if options[:attribute]
|
40
|
+
|
41
|
+
class_eval <<-RUBY
|
42
|
+
def #{property_name}
|
43
|
+
self[:#{property_name}]
|
44
|
+
end
|
45
|
+
def #{property_name}=(val)
|
46
|
+
(dirty_properties << :#{property_name}).uniq! unless val == self[:#{property_name}]
|
47
|
+
self[:#{property_name}] = val
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
|
51
|
+
maps.each_value do |v|
|
52
|
+
alias_method v, property_name
|
53
|
+
alias_method :"#{v}=", :"#{property_name}="
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.properties
|
58
|
+
properties = []
|
59
|
+
ancestors.each do |elder|
|
60
|
+
if elder.instance_variable_defined?("@properties")
|
61
|
+
properties << elder.instance_variable_get("@properties")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
properties.reverse.flatten
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.property_by_name(property_name)
|
69
|
+
property_name = property_name.to_sym
|
70
|
+
properties.detect {|p| p.name == property_name || p.maps.value?(property_name)}
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.properties_by_name(property_name)
|
74
|
+
property_name = property_name.to_sym
|
75
|
+
properties.select {|p| p.name == property_name || p.maps.value?(property_name)}
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.property?(prop)
|
79
|
+
!property_by_name(prop.to_sym).nil?
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.defaults
|
83
|
+
properties.inject({}) {|hash, prop| hash[prop.name] = prop['default'] unless prop['default'].nil?; hash }
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.attribute_mappers hash = nil
|
87
|
+
@attribute_mappers ||= {:soap => SimpleCrowd::Mappers::SoapAttributes}
|
88
|
+
unless hash.nil?
|
89
|
+
@attribute_mappers.merge! hash if hash.is_a? Hash
|
90
|
+
end
|
91
|
+
@attribute_mappers
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.map_for type
|
95
|
+
type = type.to_sym
|
96
|
+
properties.inject({}) {|hash, prop| hash[prop.name] = prop.maps[type] unless prop.maps[type].nil?; hash }
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.map_to type, entity
|
100
|
+
map = map_for type
|
101
|
+
attrs = {}
|
102
|
+
out = entity.inject({}) do |hash, (key, val)|
|
103
|
+
key = key.to_sym
|
104
|
+
catch(:skip_prop) do
|
105
|
+
unless val.nil?
|
106
|
+
mapped_key = map[key].nil? ? key : map[key]
|
107
|
+
prop = property_by_name key
|
108
|
+
if prop.nil?
|
109
|
+
attrs[mapped_key] = val
|
110
|
+
throw :skip_prop
|
111
|
+
end
|
112
|
+
mapper = prop.mappers[type]
|
113
|
+
#val = val.inject({}) {|attrs, (k, v)| attrs[property_by_name(k).maps[type]]= v unless v.nil?; attrs} if key == :attributes
|
114
|
+
val = mapper.produce val unless mapper.nil?
|
115
|
+
if prop.attribute || entity.attributes_keys.include?(key)
|
116
|
+
attrs[mapped_key] = val
|
117
|
+
else
|
118
|
+
hash[mapped_key] = val
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
hash
|
123
|
+
end
|
124
|
+
out[:attributes] = attribute_mappers[type].produce attrs
|
125
|
+
out
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.parse_from type, entity
|
129
|
+
entity[:attributes] = attribute_mappers[type].parse entity[:attributes]
|
130
|
+
parsed_entity = entity.inject({}) do |hash, (key, val)|
|
131
|
+
prop = property_by_name key
|
132
|
+
unless prop.nil?
|
133
|
+
mapper = prop.mappers[type]
|
134
|
+
val = mapper.parse val unless mapper.nil?
|
135
|
+
end
|
136
|
+
hash[key] = val
|
137
|
+
hash
|
138
|
+
end
|
139
|
+
self.new(parsed_entity)
|
140
|
+
end
|
141
|
+
|
142
|
+
def map_to type
|
143
|
+
self.class.map_to type, self
|
144
|
+
end
|
145
|
+
|
146
|
+
def attributes_keys
|
147
|
+
keys = []
|
148
|
+
self.class.ancestors.each do |elder|
|
149
|
+
if elder.instance_variable_defined?("@attributes")
|
150
|
+
keys << elder.instance_variable_get("@attributes")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
keys << @attributes unless @attributes.nil?
|
154
|
+
keys.flatten.uniq
|
155
|
+
end
|
156
|
+
|
157
|
+
def attributes
|
158
|
+
self.inject({}) {|hash, (k, v)| hash[k] = v if attributes_keys.include?(k.to_sym); hash}
|
159
|
+
end
|
160
|
+
|
161
|
+
def dirty_properties
|
162
|
+
@dirty_properties ||= Array.new
|
163
|
+
end
|
164
|
+
|
165
|
+
def dirty_attributes
|
166
|
+
dirty_properties & attributes_keys
|
167
|
+
end
|
168
|
+
|
169
|
+
def dirty? prop = nil
|
170
|
+
prop.nil? ? !@dirty_properties.empty? : @dirty_properties.include?(prop)
|
171
|
+
end
|
172
|
+
|
173
|
+
def clean
|
174
|
+
@dirty_properties = Array.new
|
175
|
+
end
|
176
|
+
|
177
|
+
def update_with attrs
|
178
|
+
current_keys = attributes_keys
|
179
|
+
attrs.each_pair {|k, v| self.send(:"#{k}=", v) if current_keys.include?(k.to_sym) && v != self.send(k.to_sym)}
|
180
|
+
end
|
181
|
+
|
182
|
+
def []= key, val
|
183
|
+
prop = self.class.property_by_name key
|
184
|
+
(@attributes ||= []) << key if prop.nil?
|
185
|
+
super
|
186
|
+
end
|
187
|
+
|
188
|
+
private
|
189
|
+
def self.real_key_for att
|
190
|
+
p = property_by_name att
|
191
|
+
p.nil? ? att : p.name
|
192
|
+
end
|
193
|
+
def self.att_to_ruby att
|
194
|
+
att.to_s =~ /^[a-z]*([A-Z][^A-Z]*)*$/ ? att.to_s.underscore.to_sym : att.to_sym
|
195
|
+
end
|
196
|
+
def real_key_for att; self.class.real_key_for att; end
|
197
|
+
def att_to_ruby att; self.class.att_to_ruby att; end
|
198
|
+
end
|
199
|
+
end
|
@@ -1,15 +1,24 @@
|
|
1
|
-
module SimpleCrowd
|
2
|
-
class CrowdError < StandardError
|
3
|
-
|
4
|
-
attr_reader :type
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
module SimpleCrowd
|
2
|
+
class CrowdError < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
attr_reader :type
|
5
|
+
attr_reader :original
|
6
|
+
|
7
|
+
def initialize(string, original)
|
8
|
+
super string
|
9
|
+
@original = original
|
10
|
+
|
11
|
+
if original.is_a?(Savon::SOAP::Fault)
|
12
|
+
@response = original.http
|
13
|
+
@type = original.to_hash[:fault][:detail].keys.first rescue nil
|
14
|
+
elsif original.is_a?(Savon::HTTP::Error)
|
15
|
+
@response = original.http
|
16
|
+
@type = :http
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def type? type
|
21
|
+
@type == type.to_sym
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/simple_crowd/group.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
module SimpleCrowd
|
2
|
-
class Group < CrowdEntity
|
3
|
-
property :id
|
4
|
-
property :name
|
5
|
-
property :active, :default => true
|
6
|
-
property :description
|
7
|
-
property :directory_id
|
8
|
-
|
9
|
-
property :members
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module SimpleCrowd
|
2
|
+
class Group < CrowdEntity
|
3
|
+
property :id
|
4
|
+
property :name
|
5
|
+
property :active, :default => true
|
6
|
+
property :description
|
7
|
+
property :directory_id
|
8
|
+
|
9
|
+
property :members
|
10
|
+
end
|
11
|
+
end
|