Sha256: f68c9760178417b5d971e3dd393ac353ccc3a02cad455af162de2b4a86575073

Contents?: true

Size: 970 Bytes

Versions: 1

Compression:

Stored size: 970 Bytes

Contents

class ModelObserver
  attr_reader :model, :property_name, :property_type, :observer_options
  @@property_type_converters = {
    :undefined => lambda { |value| value },
    :fixnum => lambda { |value| value.to_i },
    :array => lambda { |value| value.to_a }
  }
  def initialize(model, property_name, property_type = :undefined, observer_options = nil)
    property_type = :undefined if property_type.nil?
    @model = model
    @property_name = property_name
    @property_type = property_type
    @observer_options = observer_options || {}
  end
  def update(value)
    converted_value = @@property_type_converters[@property_type].call(value)
    @model.send(@property_name + "=", converted_value) unless evaluate_property == converted_value
  end
  def evaluate_property
    @model.send(@property_name)
  end
  def evaluate_options_property
    @model.send(@property_name + "_options")
  end
  def options_property_name
    self.property_name + "_options"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glimmer-0.1.10.470 lib/command_handlers/models/model_observer.rb