Sha256: 5317b198ead5212fb7cb8c2a9e2a5d9030fbf2a746482424d0371ac6b17c0ee1

Contents?: true

Size: 844 Bytes

Versions: 4

Compression:

Stored size: 844 Bytes

Contents

module Gitter
  module Model

    def self.included base
      base.send :attr_reader, :model
    end

    # evaluate data (string or proc) in context of grid
    def eval data, model = nil
      instance_variable_set :"@model", model
      attributes.each do |name,block|
        instance_variable_set :"@#{name}", instance_eval(&block)
      end

      res = instance_eval &data

      remove_instance_variable :"@model"
      attributes.each do |name,block|
        remove_instance_variable :"@#{name}"
      end

      res
    end

    def decorate *args
      @decorator.decorate *args
    end

    def attribute name, &block
      self.class.send :attr_reader, name
      attributes[name] = block or raise ArgumentError, "missing block for model #{model}"
    end

    private
    def attributes
      @attributes||={}
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gitter-1.1.6 lib/gitter/model.rb
gitter-1.1.5 lib/gitter/model.rb
gitter-1.1.4 lib/gitter/model.rb
gitter-1.1.3 lib/gitter/model.rb