class Trello::BasicData

Attributes

client[W]

Public Class Methods

client() click to toggle source
# File lib/trello/basic_data.rb, line 70
def self.client
  Trello.client
end
create(options) click to toggle source
# File lib/trello/basic_data.rb, line 20
def create(options)
  client.create(path_name, options)
end
find(id, params = {}) click to toggle source
# File lib/trello/basic_data.rb, line 16
def find(id, params = {})
  client.find(path_name, id, params)
end
many(name, opts = {}) click to toggle source
# File lib/trello/basic_data.rb, line 66
def self.many(name, opts = {})
  AssociationBuilder::HasMany.build(self, name, opts)
end
new(fields = {}) click to toggle source
# File lib/trello/basic_data.rb, line 76
def initialize(fields = {})
  initialize_fields(fields)
end
one(name, opts = {}) click to toggle source
# File lib/trello/basic_data.rb, line 62
def self.one(name, opts = {})
  AssociationBuilder::HasOne.build(self, name, opts)
end
parse(response) { |basic_data| ... } click to toggle source
# 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) { |d| ... } click to toggle source
# 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() click to toggle source
# File lib/trello/basic_data.rb, line 12
def path_name
  name.split("::").last.underscore
end
register_attrs() click to toggle source
# File lib/trello/basic_data.rb, line 56
def self.register_attrs
  schema.attrs.values.each do |attribute|
    attribute.register(self)
  end
end
save(options) { |basic_data| ... } click to toggle source
# 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
schema(&block) click to toggle source
# File lib/trello/basic_data.rb, line 45
def self.schema(&block)
  @schema ||= Schema.new
  return @schema unless block_given?

  @schema.instance_eval(&block)

  register_attrs

  @schema
end

Public Instance Methods

==(other) click to toggle source

Two objects are equal if their id methods are equal.

# File lib/trello/basic_data.rb, line 148
def ==(other)
  self.class == other.class && id == other.id
end
Also aliased as: eql?
attributes() click to toggle source
# File lib/trello/basic_data.rb, line 168
def attributes
  @__attributes ||= ActiveSupport::HashWithIndifferentAccess.new
end
client() click to toggle source
# File lib/trello/basic_data.rb, line 160
def client
  @client ||= self.class.client
end
collection_name() click to toggle source
# File lib/trello/basic_data.rb, line 134
def collection_name
  @collection_path ||= ActiveSupport::Inflector.pluralize(element_name)
end
collection_path() click to toggle source
# File lib/trello/basic_data.rb, line 126
def collection_path
  "/#{collection_name}"
end
element_name() click to toggle source
# File lib/trello/basic_data.rb, line 138
def element_name
  @element_name ||= model_name.element
end
element_path() click to toggle source
# File lib/trello/basic_data.rb, line 130
def element_path
  "/#{collection_name}/#{id}"
end
eql?(other)

Alias hash equality to equality

Alias for: ==
hash() click to toggle source

Delegate hash key computation to class and id pair

# File lib/trello/basic_data.rb, line 156
def hash
  [self.class, id].hash
end
refresh!() click to toggle source

Refresh the contents of our object.

# File lib/trello/basic_data.rb, line 143
def refresh!
  self.class.find(id)
end
save() click to toggle source
# File lib/trello/basic_data.rb, line 80
def save
  return update! if id

  payload = {}

  schema.attrs.each do |_, attribute|
    payload = attribute.build_payload_for_create(attributes, payload)
  end

  post(collection_path, payload)
end
schema() click to toggle source
# File lib/trello/basic_data.rb, line 164
def schema
  self.class.schema
end
update!() click to toggle source
# File lib/trello/basic_data.rb, line 92
def update!
  fail "Cannot save new instance." unless id

  @previously_changed = changes

  payload = {}
  changed_attrs = attributes.select {|name, _| changed.include?(name.to_s)}

  schema.attrs.each do |_, attribute|
    payload = attribute.build_payload_for_update(changed_attrs, payload)
  end

  from_response client.put(element_path, payload)

  @changed_attributes.clear if @changed_attributes.respond_to?(:clear)
  changes_applied if respond_to?(:changes_applied)

  self
end
update_fields(fields) click to toggle source
# File lib/trello/basic_data.rb, line 112
def update_fields(fields)
  attrs = {}

  schema.attrs.each do |_, attribute|
    attrs = attribute.build_pending_update_attributes(fields, attrs)
  end

  attrs.each do |name, value|
    send("#{name}=", value)
  end

  self
end

Private Instance Methods

attributes=(attrs) click to toggle source
# File lib/trello/basic_data.rb, line 174
def attributes=(attrs)
  @__attributes = attrs
end
initialize_fields(fields) click to toggle source
# File lib/trello/basic_data.rb, line 178
def initialize_fields(fields)
  schema.attrs.each do |_, attribute|
    self.attributes = attribute.build_attributes(fields, attributes)
  end

  self
end
post(path, body) click to toggle source
# File lib/trello/basic_data.rb, line 186
def post(path, body)
  from_response client.post(path, body)
end
put(path, body) click to toggle source
# File lib/trello/basic_data.rb, line 190
def put(path, body)
  from_response client.put(path, body)
end