class Trello::Schema::AttributeRegistration

Attributes

attribute[R]
klass[R]

Public Class Methods

new(klass, attribute) click to toggle source
# File lib/trello/schema/attribute_registration.rb, line 12
def initialize(klass, attribute)
  @klass = klass
  @attribute = attribute
end
register(klass, attribute) click to toggle source
# File lib/trello/schema/attribute_registration.rb, line 5
def register(klass, attribute)
  new(klass, attribute).register
end

Public Instance Methods

register() click to toggle source
# File lib/trello/schema/attribute_registration.rb, line 17
def register
  define_getter
  define_setter
end

Private Instance Methods

define_getter() click to toggle source
# File lib/trello/schema/attribute_registration.rb, line 24
def define_getter
  attribute_name = attribute.name

  klass.class_eval do
    define_method(attribute_name) { @__attributes[attribute_name] }
  end
end
define_setter() click to toggle source
# File lib/trello/schema/attribute_registration.rb, line 32
def define_setter
  return if attribute.readonly?

  attribute_name = attribute.name

  klass.class_eval do
    define_method("#{attribute_name}=") do |value|
      send("#{attribute_name}_will_change!") if value != @__attributes[attribute_name]
      @__attributes[attribute_name] = value
    end
  end
end