Class: InfinumAzure::Resources::Params
- Inherits:
-
Object
- Object
- InfinumAzure::Resources::Params
- Defined in:
- app/services/infinum_azure/resources/params.rb
Constant Summary collapse
- NORMALIZATIONS =
{ uid: :propagate, email: :propagate, first_name: :propagate, last_name: :propagate, avatar_url: :propagate, deactivated_at: { procedure: ->(value) { [false, nil].include?(value) ? nil : Time.zone.now }, target_name: :deactivated }, employee: { procedure: ->(value) { value&.include?('employees') }, target_name: :groups }, groups: :propagate }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(params = {}) ⇒ Params
constructor
A new instance of Params.
Constructor Details
#initialize(params = {}) ⇒ Params
Returns a new instance of Params.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/infinum_azure/resources/params.rb', line 27 def initialize(params = {}) NORMALIZATIONS.each do |attribute, operation| value = if operation == :propagate params[attribute] elsif operation.is_a?(Hash) operation[:procedure].call(params[operation[:target_name]]) else raise 'unsupported normalization' end instance_variable_set(:"@#{attribute}", value) end end |
Class Method Details
.normalize(payload) ⇒ Object
23 24 25 |
# File 'app/services/infinum_azure/resources/params.rb', line 23 def self.normalize(payload) new(payload).as_json end |
Instance Method Details
#as_json ⇒ Object
41 42 43 44 45 |
# File 'app/services/infinum_azure/resources/params.rb', line 41 def as_json NORMALIZATIONS.keys.index_with do |key| instance_variable_get(:"@#{key}") end end |