Class: Pipekit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pipekit/config.rb

Constant Summary collapse

NotSetError =
Class.new(Exception)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.file_pathObject



88
89
90
# File 'lib/pipekit/config.rb', line 88

def file_path
  @file_path || raise_config_error
end

Class Method Details

.custom_field_values(resource, field) ⇒ Object



82
83
84
85
86
# File 'lib/pipekit/config.rb', line 82

def custom_field_values(resource, field)
  fetch("field_values", {})
    .fetch(resource.to_s, {})
    .fetch(field.to_s, {})
end

.custom_fields(resource) ⇒ Object



77
78
79
80
# File 'lib/pipekit/config.rb', line 77

def custom_fields(resource)
  fetch("fields", {})
    .fetch(resource.to_s, {})
end

.fetch(key, default = nil) ⇒ Object



69
70
71
# File 'lib/pipekit/config.rb', line 69

def fetch(key, default = nil)
  config.fetch(key.to_s, default)
end

.field_id(resource, key) ⇒ Object

Finds the Pipedrive field ID from the config

Example

Config.field_id(:person, "middle_name")
  # => "asbasdfasc2343443"

Config.field_id(:person, "name")
  # => "name"


31
32
33
34
# File 'lib/pipekit/config.rb', line 31

def field_id(resource, key)
  custom_fields(resource)
    .fetch(key.to_s, key.to_s)
end

.field_name(resource, key) ⇒ Object

Finds the field name in the config from the Pipedrive ID

Example

Config.field_name(:person, "asbasdfasc2343443")
  # => "middle_name"

Config.field_name(:person, "name")
  # => "name"


16
17
18
19
20
# File 'lib/pipekit/config.rb', line 16

def field_name(resource, key)
  custom_fields(resource)
    .invert
    .fetch(key.to_s, key.to_s)
end

.field_value(resource, field, value) ⇒ Object

Finds the Pipedrive field value from the config translating from a Pipedrive ID in the config if one exists for that field/value

Example

Config.field_value(:person, "inteview_quality", 66)
  # => "Amazing"

Config.field_value(:person, "inteview_quality", "value_not_there")
  # => "value_not_there"


47
48
49
50
51
# File 'lib/pipekit/config.rb', line 47

def field_value(resource, field, value)
  custom_field_values(resource, field)
    .reduce({}) { |result, (k,v)| result.tap { |result| result[k.to_s] = v } }
    .fetch(value.to_s, value)
end

.field_value_id(resource, field, value) ⇒ Object

Finds the Pipedrive field value ID from the config if one exists for that field/value

Example

Config.field_value_id(:person, "inteview_quality", "Amazing")
  # => 66

Config.field_value_id(:person, "inteview_quality", "value_not_there")
  # => "value_not_there"


63
64
65
66
67
# File 'lib/pipekit/config.rb', line 63

def field_value_id(resource, field, value)
  custom_field_values(resource, field)
    .invert
    .fetch(value, value)
end

.set(key, value) ⇒ Object



73
74
75
# File 'lib/pipekit/config.rb', line 73

def set(key, value)
  config[key.to_s] = value
end