Class: Trello::CustomField
- Defined in:
- lib/trello/custom_field.rb
Overview
A Custom Field can be activated on a board. Values are stored at the card level.
Constant Summary collapse
- SYMBOL_TO_STRING =
{ id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' }
Instance Attribute Summary collapse
- #field_group ⇒ String
- #id ⇒ String
- #model_id ⇒ String
- #model_type ⇒ String
- #name ⇒ String
- #options ⇒ Array<Hash>
- #pos ⇒ Float
- #type ⇒ String
Attributes inherited from BasicData
Class Method Summary collapse
-
.create(options) ⇒ Object
Create a new custom field and save it on Trello.
-
.find(id, params = {}) ⇒ Object
Find a custom field by its id.
Instance Method Summary collapse
-
#create_new_option(value) ⇒ Object
If type == ‘list’, create a new option and add to this Custom Field.
-
#delete ⇒ Object
Delete this custom field Also deletes all associated values across all cards.
-
#delete_option(option_id) ⇒ Object
Will also clear it from individual cards that have this option selected.
-
#save ⇒ Object
Saves a record.
-
#update! ⇒ Object
Update an existing custom field.
- #update_fields(fields) ⇒ Object
Methods inherited from BasicData
#==, client, #hash, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save
Methods included from JsonUtils
Constructor Details
This class inherits a constructor from Trello::BasicData
Instance Attribute Details
#field_group ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#id ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#model_id ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#model_type ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#name ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#options ⇒ Array<Hash>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#pos ⇒ Float
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
#type ⇒ String
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/trello/custom_field.rb', line 20 class CustomField < BasicData register_attributes :id, :model_id, :model_type, :field_group, :name, :pos, :type validates_presence_of :id, :model_id, :model_type, :name, :type, :pos SYMBOL_TO_STRING = { id: 'id', name: 'name', model_id: 'idModel', model_type: 'modelType', field_group: 'fieldGroup', type: 'type', pos: 'pos' } class << self # Find a custom field by its id. def find(id, params = {}) client.find('customFields', id, params) end # Create a new custom field and save it on Trello. def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end end # References Board where this custom field is located # Currently, model_type will always be "board" at the customFields endpoint one :board, path: :boards, using: :model_id # If type == 'list' many :custom_field_options, path: 'options' def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end # Saves a record. def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end # Update an existing custom field. def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end # Delete this custom field # Also deletes all associated values across all cards def delete client.delete("/customFields/#{id}") end # If type == 'list', create a new option and add to this Custom Field def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end # Will also clear it from individual cards that have this option selected def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end end |
Class Method Details
.create(options) ⇒ Object
Create a new custom field and save it on Trello.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/trello/custom_field.rb', line 41 def create() client.create('customFields', 'name' => [:name], 'idModel' => [:model_id], 'modelType' => [:model_type], 'fieldGroup' => [:field_group], 'type' => [:type], 'pos' => [:pos] ) end |
.find(id, params = {}) ⇒ Object
Find a custom field by its id.
36 37 38 |
# File 'lib/trello/custom_field.rb', line 36 def find(id, params = {}) client.find('customFields', id, params) end |
Instance Method Details
#create_new_option(value) ⇒ Object
If type == ‘list’, create a new option and add to this Custom Field
103 104 105 106 |
# File 'lib/trello/custom_field.rb', line 103 def create_new_option(value) payload = { value: value } client.post("/customFields/#{id}/options", payload) end |
#delete ⇒ Object
Delete this custom field Also deletes all associated values across all cards
98 99 100 |
# File 'lib/trello/custom_field.rb', line 98 def delete client.delete("/customFields/#{id}") end |
#delete_option(option_id) ⇒ Object
Will also clear it from individual cards that have this option selected
109 110 111 |
# File 'lib/trello/custom_field.rb', line 109 def delete_option(option_id) client.delete("/customFields/#{id}/options/#{option_id}") end |
#save ⇒ Object
Saves a record.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trello/custom_field.rb', line 72 def save # If we have an id, just update our fields. return update! if id from_response client.post("/customFields", { name: name, idModel: model_id, modelType: model_type, type: type, pos: pos, fieldGroup: field_group }) end |
#update! ⇒ Object
Update an existing custom field.
87 88 89 90 91 92 93 94 |
# File 'lib/trello/custom_field.rb', line 87 def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }] @changed_attributes.clear client.put("/customFields/#{id}", payload) end |
#update_fields(fields) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/trello/custom_field.rb', line 60 def update_fields(fields) attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id] attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name] attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id] attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type] attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group] attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type] attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos] self end |