class Trello::Schema::Attribute::Base

Attributes

name[R]
options[R]
serializer[R]

Public Class Methods

new(name:, options:, serializer:) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 8
def initialize(name:, options:, serializer:)
  @name = name.to_sym
  @options = options || {}
  @serializer = serializer
end

Public Instance Methods

build_attributes(params, attributes) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 14
def build_attributes(params, attributes)
  raise 'Need override'
end
build_payload_for_create(attributes, payload) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 26
def build_payload_for_create(attributes, payload)
  raise 'Need override'
end
build_payload_for_update(attributes, payload) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 30
def build_payload_for_update(attributes, payload)
  raise 'Need override'
end
build_pending_update_attributes(params, attributes) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 18
def build_pending_update_attributes(params, attributes)
  params = params.with_indifferent_access

  return attributes unless params.key?(remote_key) || params.key?(name)

  build_attributes(params, attributes)
end
create_only?() click to toggle source
# File lib/trello/schema/attribute/base.rb, line 42
def create_only?
  options[:create_only] == true
end
default() click to toggle source
# File lib/trello/schema/attribute/base.rb, line 67
def default
  return nil unless options.key?(:default)

  options[:default]
end
for_action?(action) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 52
def for_action?(action)
  case action
  when :create
    create_only? || (!update_only? && !readonly? && !primary_key?)
  when :update
    update_only? || primary_key? || (!create_only? && !readonly?)
  else
    false
  end
end
primary_key?() click to toggle source
# File lib/trello/schema/attribute/base.rb, line 46
def primary_key?
  return false unless options.key?(:primary_key)

  options[:primary_key] 
end
readonly?() click to toggle source
# File lib/trello/schema/attribute/base.rb, line 34
def readonly?
  options[:readonly] == true
end
register(model_klass) click to toggle source
# File lib/trello/schema/attribute/base.rb, line 73
def register(model_klass)
  AttributeRegistration.register(model_klass, self)
end
remote_key() click to toggle source
# File lib/trello/schema/attribute/base.rb, line 63
def remote_key
  (options[:remote_key] || name).to_s
end
update_only?() click to toggle source
# File lib/trello/schema/attribute/base.rb, line 38
def update_only?
  options[:update_only] == true
end