#coding: utf-8 NS_GEM_ROOT = File.expand_path('../..', __FILE__) #debug this gem #$LOAD_PATH.unshift("#{NS_GEM_ROOT}/lib") require 'fileutils' require 'ns_service_pack/code_hash' require 'ns_service_pack/global_const' require 'ns_service_pack/field_mapping' require 'ns_service_pack/result_packer' require 'ns_service_pack/application_controller_module' if defined?(Rails) #TODO 为什么不能像ActiveRecord::Base一样include,到底什么道理呢??? class ApplicationController < ActionController::Base include ApplicationControllerModule end if defined?(ActiveRecord::Base) ActiveRecord::Base.send(:include, FieldMapping) end end module NsServicePack def self.install #添加一个初始化文件 init_file = "#{Rails.root}/config/initializers/ns_service_pack.rb" unless File.exists?(init_file) FileUtils.cp("#{NS_GEM_ROOT}/config/initializers/ns_service_pack.rb", init_file) puts "==>I have installed a intializer file: #{init_file}" GlobalConst.setup_code_hashes puts "==>Now you can config your constants in folder: #{GlobalConst::APP_CODE_HASHES}" else puts "==>It seems you have installed ns service pack, happy with it or bug report to caory!" end end end puts "==>NsServicePack has installed into application, ^^caory"