Class: Pipekit::Config
- Inherits:
-
Object
- Object
- Pipekit::Config
- Defined in:
- lib/pipekit/config.rb
Constant Summary collapse
- NotSetError =
Class.new(Exception)
Class Attribute Summary collapse
Class Method Summary collapse
- .custom_field_values(resource, field) ⇒ Object
- .custom_fields(resource) ⇒ Object
- .fetch(key, default = nil) ⇒ Object
-
.field_id(resource, key) ⇒ Object
Finds the Pipedrive field ID from the config.
-
.field_name(resource, key) ⇒ Object
Finds the field name in the config from the Pipedrive ID.
-
.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.
-
.field_value_id(resource, field, value) ⇒ Object
Finds the Pipedrive field value ID from the config if one exists for that field/value.
- .set(key, value) ⇒ Object
Class Attribute Details
.file_path ⇒ Object
87 88 89 |
# File 'lib/pipekit/config.rb', line 87 def file_path @file_path || raise_config_error end |
Class Method Details
.custom_field_values(resource, field) ⇒ Object
81 82 83 84 85 |
# File 'lib/pipekit/config.rb', line 81 def custom_field_values(resource, field) fetch("field_values", {}) .fetch(resource.to_s, {}) .fetch(field.to_s, {}) end |
.custom_fields(resource) ⇒ Object
76 77 78 79 |
# File 'lib/pipekit/config.rb', line 76 def custom_fields(resource) fetch("fields", {}) .fetch(resource.to_s, {}) end |
.fetch(key, default = nil) ⇒ Object
68 69 70 |
# File 'lib/pipekit/config.rb', line 68 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 |
# File 'lib/pipekit/config.rb', line 47 def field_value(resource, field, value) custom_field_values(resource, field) .fetch(value, 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"
62 63 64 65 66 |
# File 'lib/pipekit/config.rb', line 62 def field_value_id(resource, field, value) custom_field_values(resource, field) .invert .fetch(value, value) end |
.set(key, value) ⇒ Object
72 73 74 |
# File 'lib/pipekit/config.rb', line 72 def set(key, value) config[key.to_s] = value end |