class Pipekit::Config
Constants
- NotSetError
Attributes
file_path[W]
Public Class Methods
custom_field_values(resource, field)
click to toggle source
# 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)
click to toggle source
# File lib/pipekit/config.rb, line 77 def custom_fields(resource) fetch("fields", {}) .fetch(resource.to_s, {}) end
fetch(key, default = nil)
click to toggle source
# File lib/pipekit/config.rb, line 69 def fetch(key, default = nil) config.fetch(key.to_s, default) end
field_id(resource, key)
click to toggle source
Finds the Pipedrive field ID from the config
Example
Config.field_id(:person, "middle_name") # => "asbasdfasc2343443" Config.field_id(:person, "name") # => "name"
# 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)
click to toggle source
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"
# 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)
click to toggle source
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"
# 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)
click to toggle source
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"
# File lib/pipekit/config.rb, line 63 def field_value_id(resource, field, value) custom_field_values(resource, field) .invert .fetch(value, value) end
file_path()
click to toggle source
# File lib/pipekit/config.rb, line 88 def file_path @file_path || raise_config_error end
set(key, value)
click to toggle source
# File lib/pipekit/config.rb, line 73 def set(key, value) config[key.to_s] = value end
Private Class Methods
config()
click to toggle source
# File lib/pipekit/config.rb, line 94 def config @config ||= load_config end
load_config()
click to toggle source
# File lib/pipekit/config.rb, line 102 def load_config yaml = ERB.new(File.read(file_path)).result YAML.load(yaml) end
raise_config_error()
click to toggle source
# File lib/pipekit/config.rb, line 98 def raise_config_error raise NotSetError, "You need to create a yaml file with your Pipedrive config and set the path to the file using `Pipekit.config_file_path = 'path/to/file.yml'`" end