Sha256: dda449c597c9a94d27f298a0fa6e7fbcf89c4bdaeeee7c9f23e0e03c6ca09044

Contents?: true

Size: 780 Bytes

Versions: 3

Compression:

Stored size: 780 Bytes

Contents

module Draper::ActiveModelSupport
  module Proxies
    def self.extended(base)
      # These methods (as keys) will be created only if the correspondent
      # model responds to the method
      proxies = [:to_param, :errors, :id]

      proxies.each do |method_name|
        if base.model.respond_to?(method_name)
          base.singleton_class.class_eval do
            if !base.class.instance_methods.include?(method_name) || base.class.instance_method(method_name).owner === Draper::Base
              define_method(method_name) do |*args, &block|
                model.send(method_name, *args, &block)
              end
            end
          end
        end
      end

      base.class_eval do
        def to_model
          self
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
draper-0.18.0 lib/draper/active_model_support.rb
draper-0.17.0 lib/draper/active_model_support.rb
draper-0.16.0 lib/draper/active_model_support.rb