Class: Trello::Schema::Attribute::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/trello/schema/attribute/base.rb

Direct Known Subclasses

BoardPref, CustomFieldDisplay, Default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options:, serializer:) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/trello/schema/attribute/base.rb', line 8

def initialize(name:, options:, serializer:)
  @name = name.to_sym
  @options = options || {}
  @serializer = serializer
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/trello/schema/attribute/base.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/trello/schema/attribute/base.rb', line 6

def options
  @options
end

#serializerObject (readonly)

Returns the value of attribute serializer.



6
7
8
# File 'lib/trello/schema/attribute/base.rb', line 6

def serializer
  @serializer
end

Instance Method Details

#build_attributes(params, attributes) ⇒ Object



14
15
16
# File 'lib/trello/schema/attribute/base.rb', line 14

def build_attributes(params, attributes)
  raise 'Need override'
end

#build_payload_for_create(attributes, payload) ⇒ Object



26
27
28
# 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) ⇒ Object



30
31
32
# 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) ⇒ Object



18
19
20
21
22
23
24
# 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?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/trello/schema/attribute/base.rb', line 42

def create_only?
  options[:create_only] == true
end

#defaultObject



67
68
69
70
71
# File 'lib/trello/schema/attribute/base.rb', line 67

def default
  return nil unless options.key?(:default)

  options[:default]
end

#for_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
# 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?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/trello/schema/attribute/base.rb', line 46

def primary_key?
  return false unless options.key?(:primary_key)

  options[:primary_key] 
end

#readonly?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/trello/schema/attribute/base.rb', line 34

def readonly?
  options[:readonly] == true
end

#register(model_klass) ⇒ Object



73
74
75
# File 'lib/trello/schema/attribute/base.rb', line 73

def register(model_klass)
  AttributeRegistration.register(model_klass, self)
end

#remote_keyObject



63
64
65
# File 'lib/trello/schema/attribute/base.rb', line 63

def remote_key
  (options[:remote_key] || name).to_s
end

#update_only?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/trello/schema/attribute/base.rb', line 38

def update_only?
  options[:update_only] == true
end