Sha256: 6b69751b9f56ee703ede5a03f0b65b39c648fc7a0e1092ef475c48ffef3d6032

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

require "surrounded/rails/version"
require "surrounded"
require "rails"
module Surrounded
  class Railtie < ::Rails::Railtie
    initializer 'surrounded.active_record' do |app|
      ActiveRecord::Base.send(:include, ::Surrounded)
      ActiveRecord::Base.class_eval {
        # Ideally this should hook into the initialization process
        # and set the @__surroundings__ collection there.
        # Currently I haven't found a way to do that.
        #
        # Surrounded uses respond_to_missing? and method_missing
        # which are two methods used when an ActiveRecord object
        # is initialized.
        #
        # The after_initialize callback happens after those methods
        # are used.
        #
        define_method(:surroundings){
          @__surroundings__ ||= []
        }
        private :surroundings
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
surrounded-rails-0.0.1 lib/surrounded/railtie.rb