Class: PaymentTest::PluginPropertyUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/payment_test/plugin_property_utils.rb

Class Method Summary collapse

Class Method Details

.add_property_if_not_exist(properties, key_name, key_value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/payment_test/plugin_property_utils.rb', line 13

def self.add_property_if_not_exist(properties, key_name, key_value)
  if get_property_or_nil(properties, key_name).nil?
    prop = Killbill::Plugin::Model::PluginProperty.new
    prop.key = key_name
    prop.value = key_value
    properties << prop
  end
end

.get_property_or_nil(properties, key_name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/payment_test/plugin_property_utils.rb', line 5

def self.get_property_or_nil(properties, key_name)
  test_props = (properties || []).select { |e| e.key == key_name }
  if test_props.size > 1
    raise ArgumentError.new "multiple property with key #{key_name} is not allowed"
  end
  test_props.size == 1 ? test_props[0] : nil
end

.validate_properties(properties) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/payment_test/plugin_property_utils.rb', line 22

def self.validate_properties(properties)
  if properties.nil?
    return
  end

  if !properties.is_a? Array
    raise ArgumentError.new "properties should be an Array"
  end

  properties.each do |p|
    if !p.is_a? Killbill::Plugin::Model::PluginProperty
      raise ArgumentError.new "Each property should be of type Killbill::Plugin::Model::PluginProperty"
    end
  end
end