Class: Trello::CustomFieldItem
- Defined in:
- lib/trello/custom_field_item.rb
Overview
A custom field item contains the value for a custom field on a particular card.
Instance Attribute Summary
Attributes inherited from BasicData
Instance Method Summary collapse
-
#initialize(fields = {}) ⇒ CustomFieldItem
constructor
A new instance of CustomFieldItem.
-
#option_value ⇒ Object
Need to make another call to get the actual value if the custom field type == ‘list’.
-
#remove ⇒ Object
You can’t “delete” a custom field item, you can only clear the value.
-
#save ⇒ String
Saves a record.
-
#type ⇒ Object
Type is saved at the CustomField level Can equally be derived from :value, with a little parsing work: 42.
- #update! ⇒ Object
-
#update_fields(fields) ⇒ Object
Update the fields of a custom field item.
Methods inherited from BasicData
#==, client, create, find, #hash, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save
Methods included from JsonUtils
Constructor Details
#initialize(fields = {}) ⇒ CustomFieldItem
Returns a new instance of CustomFieldItem.
29 30 31 |
# File 'lib/trello/custom_field_item.rb', line 29 def initialize(fields = {}) initialize_fields(fields) end |
Instance Method Details
#option_value ⇒ Object
Need to make another call to get the actual value if the custom field type == ‘list’
71 72 73 74 75 76 77 |
# File 'lib/trello/custom_field_item.rb', line 71 def option_value if option_id option_endpoint = "/customFields/#{custom_field_id}/options/#{option_id}" option = CustomFieldOption.from_response client.get(option_endpoint) option.value end end |
#remove ⇒ Object
You can’t “delete” a custom field item, you can only clear the value
59 60 61 62 |
# File 'lib/trello/custom_field_item.rb', line 59 def remove params = { value: {} } client.put("/card/#{model_id}/customField/#{custom_field_id}/item", params) end |
#save ⇒ String
Saves a record.
the Trello API.
49 50 51 52 53 54 55 56 |
# File 'lib/trello/custom_field_item.rb', line 49 def save # If we have an id, just update our fields. return update! if id from_response client.put("/card/#{model_id}/customField/#{custom_field_id}/item", { value: value }) end |
#type ⇒ Object
Type is saved at the CustomField level Can equally be derived from :value, with a little parsing work: 42
66 67 68 |
# File 'lib/trello/custom_field_item.rb', line 66 def type custom_field.type end |
#update! ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/trello/custom_field_item.rb', line 33 def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [key.to_sym, values[1]] }] @changed_attributes.clear if @changed_attributes.respond_to?(:clear) changes_applied if respond_to?(:changes_applied) client.put("/card/#{model_id}/customField/#{custom_field_id}/item", payload) end |
#update_fields(fields) ⇒ Object
Update the fields of a custom field item.
Supply a hash of string keyed data retrieved from the Trello API representing an item state.
19 20 21 22 23 24 25 26 27 |
# File 'lib/trello/custom_field_item.rb', line 19 def update_fields(fields) if fields_has_key?(fields, 'value') send('value_will_change!') elsif fields_has_key?(fields, 'idValue') send('option_id_will_change!') end initialize_fields(fields) end |