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
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
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
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
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
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 |