Class: Lago::Api::Resources::Feature

Inherits:
Base
  • Object
show all
Defined in:
lib/lago/api/resources/feature.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#create, #destroy, #get, #get_all, #initialize, #update

Constructor Details

This class inherits a constructor from Lago::Api::Resources::Base

Instance Method Details

#api_resourceObject



7
8
9
# File 'lib/lago/api/resources/feature.rb', line 7

def api_resource
  'features'
end

#root_nameObject



11
12
13
# File 'lib/lago/api/resources/feature.rb', line 11

def root_name
  'feature'
end

#whitelist_params(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/lago/api/resources/feature.rb', line 15

def whitelist_params(params)
  result_hash = {
    code: params[:code],
    name: params[:name],
    description: params[:description],
    privileges: whitelist_privileges_params(params[:privileges]),
  }.compact

  { root_name => result_hash }
end

#whitelist_privileges_params(privileges) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lago/api/resources/feature.rb', line 26

def whitelist_privileges_params(privileges)
  privileges&.map do |privilege|
    {
      code: privilege[:code],
      name: privilege[:name],
      value_type: privilege[:value_type],
    }.tap do |h|
      h[:config] = { select_options: privilege[:config][:select_options] } if privilege[:config]
    end
  end
end