lib/ecoportal/api/v2/page/permission_flags.rb in ecoportal-api-v2-0.8.26 vs lib/ecoportal/api/v2/page/permission_flags.rb in ecoportal-api-v2-0.8.27
- old
+ new
@@ -34,29 +34,43 @@
# - `:admin_actions`
# - `:subscribed`
# - `:subscribed_to_tasks`
def configure(*conf)
conf.each_with_object([]) do |cnf, unused|
- case cnf
- when :restructure
- self.can_restructure = true
- when :configure
- self.can_configure = true
- when :can_permission
- self.can_permission = true
- when :create_actions
- self.can_create_actions = true
- when :admin_actions
- self.can_administrate_actions = true
- when :subscribed
- self.subscribed = true
- when :subscribed_to_tasks
- self.subscribed_to_tasks = true
+ if cnf.is_a?(Symbol)
+ set_flag(cnf, true, residual: unused)
+ elsif cnf.is_a?(Hash)
+ cnf.each do |key, val|
+ set_flag(key, val, residual: unused)
+ end
else
- unused.push(cnf)
+ raise ArgumentError.new("Expecting 'Symbol' or 'Hash'. Given: #{cnf.class}")
end
end.yield_self do |unused|
- raise "Unknown configuaration options #{unused}" unless unused.empty?
+ raise ArgumentError.new("Unknown configuaration options #{unused}") unless unused.empty?
+ end
+ end
+
+ private
+
+ def set_flag(key, val = true, residual: [])
+ case key
+ when :restructure
+ self.can_restructure = val
+ when :configure
+ self.can_configure = val
+ when :can_permission
+ self.can_permission = val
+ when :create_actions
+ self.can_create_actions = val
+ when :admin_actions
+ self.can_administrate_actions = val
+ when :subscribed
+ self.subscribed = val
+ when :subscribed_to_tasks
+ self.subscribed_to_tasks = val
+ else
+ residual.push(cnf)
end
end
end
end
end