Sha256: dc7e1fa3777b1f31cd5059d1315b11d383abc2e4867322ebc84c4f45d7c9a024

Contents?: true

Size: 933 Bytes

Versions: 14

Compression:

Stored size: 933 Bytes

Contents

# -*- coding: utf-8 -*-


require 'reflex/model'


module Reflex


  module ModelOwner

    attr_reader :model

    def model=(model)
      return if model == @model
      @model.remove_handler self if @model
      @model = model
      @model.add_handler self    if @model
      model
    end

    def data=(data)
      unless data.nil?
        self.model = Model.new unless @model
        @model.data = data
      else
        self.model = nil
      end
      data
    end

    def data()
      @model ? @model.data : nil
    end

    def invoke(*args)
      @model.invoke(*args) if @model
    end

    def on_data_attach(e)
      invoke :update, {}, only: self
    end

    def on_data_detach(e)
      invoke :update, {}, only: self
    end

    [:int, :float, :string, :[], :[]=].each do |name|
      define_method name do |*args|
        @model ? @model.send(name, *args) : nil
      end
    end

  end# ModelOwner


end# Reflex

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
reflexion-0.1.35 lib/reflex/model_owner.rb
reflexion-0.1.34 lib/reflex/model_owner.rb
reflexion-0.1.33 lib/reflex/model_owner.rb
reflexion-0.1.32 lib/reflex/model_owner.rb
reflexion-0.1.31 lib/reflex/model_owner.rb
reflexion-0.1.30 lib/reflex/model_owner.rb
reflexion-0.1.29 lib/reflex/model_owner.rb
reflexion-0.1.28 lib/reflex/model_owner.rb
reflexion-0.1.27 lib/reflex/model_owner.rb
reflexion-0.1.26 lib/reflex/model_owner.rb
reflexion-0.1.25 lib/reflex/model_owner.rb
reflexion-0.1.24 lib/reflex/model_owner.rb
reflexion-0.1.23 lib/reflex/model_owner.rb
reflexion-0.1.22 lib/reflex/model_owner.rb