Class: Trello::BasicData
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Dirty, ActiveModel::Serializers::JSON, ActiveModel::Validations, JsonUtils
- Defined in:
- lib/trello/basic_data.rb
Direct Known Subclasses
Action, Attachment, Board, Card, CheckItemState, Checklist, Comment, CustomField, CustomFieldItem, CustomFieldOption, Item, Label, LabelName, List, Member, Notification, Organization, PluginDatum, Token, Webhook
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from JsonUtils
included
Constructor Details
#initialize(fields = {}) ⇒ BasicData
Returns a new instance of BasicData.
69
70
71
|
# File 'lib/trello/basic_data.rb', line 69
def initialize(fields = {})
update_fields(fields)
end
|
Instance Attribute Details
#client ⇒ Object
95
96
97
|
# File 'lib/trello/basic_data.rb', line 95
def client
@client ||= self.class.client
end
|
Class Method Details
.client ⇒ Object
61
62
63
|
# File 'lib/trello/basic_data.rb', line 61
def self.client
Trello.client
end
|
.create(options) ⇒ Object
20
21
22
|
# File 'lib/trello/basic_data.rb', line 20
def create(options)
client.create(path_name, options)
end
|
.find(id, params = {}) ⇒ Object
16
17
18
|
# File 'lib/trello/basic_data.rb', line 16
def find(id, params = {})
client.find(path_name, id, params)
end
|
.many(name, opts = {}) ⇒ Object
57
58
59
|
# File 'lib/trello/basic_data.rb', line 57
def self.many(name, opts = {})
AssociationBuilder::HasMany.build(self, name, opts)
end
|
.one(name, opts = {}) ⇒ Object
53
54
55
|
# File 'lib/trello/basic_data.rb', line 53
def self.one(name, opts = {})
AssociationBuilder::HasOne.build(self, name, opts)
end
|
.parse(response) ⇒ Object
30
31
32
33
34
|
# File 'lib/trello/basic_data.rb', line 30
def parse(response)
from_response(response).tap do |basic_data|
yield basic_data if block_given?
end
end
|
.parse_many(response) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/trello/basic_data.rb', line 36
def parse_many(response)
from_response(response).map do |data|
data.tap do |d|
yield d if block_given?
end
end
end
|
.path_name ⇒ Object
12
13
14
|
# File 'lib/trello/basic_data.rb', line 12
def path_name
name.split("::").last.underscore
end
|
.register_attributes(*names_and_options) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/trello/basic_data.rb', line 45
def self.register_attributes(*names_and_options)
has_opts = names_and_options.last.kind_of?(Hash)
readonly_attributes = has_opts ? names_and_options.pop[:readonly] : []
attributes = names_and_options
RegisterAttributes.execute(self, attributes, readonly_attributes)
end
|
.save(options) ⇒ Object
24
25
26
27
28
|
# File 'lib/trello/basic_data.rb', line 24
def save(options)
new(options).tap do |basic_data|
yield basic_data if block_given?
end.save
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
Two objects are equal if their id methods are equal.
83
84
85
|
# File 'lib/trello/basic_data.rb', line 83
def ==(other)
self.class == other.class && id == other.id
end
|
#hash ⇒ Object
Delegate hash key computation to class and id pair
91
92
93
|
# File 'lib/trello/basic_data.rb', line 91
def hash
[self.class, id].hash
end
|
#refresh! ⇒ Object
Refresh the contents of our object.
78
79
80
|
# File 'lib/trello/basic_data.rb', line 78
def refresh!
self.class.find(id)
end
|
#update_fields(fields) ⇒ Object
73
74
75
|
# File 'lib/trello/basic_data.rb', line 73
def update_fields(fields)
raise NotImplementedError, "#{self.class} does not implement update_fields."
end
|