Sha256: 2a6ce11a78d93ce608462cd6dde482d5004d89b1a9adfb8aaf1e2e6ac0792b17

Contents?: true

Size: 1.55 KB

Versions: 15

Compression:

Stored size: 1.55 KB

Contents

require 'modularize'

module RestPack::Service
  class Loader

    def self.load(gem_name, module_name)
      require 'require_all'

      require 'restpack_serializer'
      require 'active_support/core_ext'

      service_path = self.get_service_path(caller, gem_name)

      require "#{service_path}/version"
      require "#{service_path}/configuration"
      require_all "#{service_path}/tasks"

      Modularize.create module_name
      Modularize.create "#{module_name}::Models"
      Modularize.create "#{module_name}::Serializers"
      Modularize.create "#{module_name}::Tasks"
      Modularize.create "#{module_name}::Jobs"
      Modularize.create "#{module_name}::Commands"

      require_service_module 'models', service_path
      require_service_module 'serializers', service_path
      require_service_module 'commands', service_path
      require_service_module 'jobs', service_path
    end

    private

    def self.require_service_module(module_name, service_path)
      path = "#{service_path}/#{module_name.downcase}"
      require_all(path) if File.directory?(path)
    end

    def self.get_service_path(load_caller, restpack_service_name)
      #Gets the path of the calling service : http://stackoverflow.com/questions/14772381/get-directory-of-file-that-instantiated-a-class-ruby
      source_file = nil
      load_caller.each do |s|
        if(s =~ /(require|require_relative)/)
          source_file = File.dirname(File.expand_path(s.split(':')[0]))
          break
        end
      end
      "#{source_file}/#{restpack_service_name}"
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
restpack_service-0.0.83 lib/restpack_service/loader.rb
restpack_service-0.0.82 lib/restpack_service/loader.rb
restpack_service-0.0.81 lib/restpack_service/loader.rb
restpack_service-0.0.80 lib/restpack_service/loader.rb
restpack_service-0.0.79 lib/restpack_service/loader.rb
restpack_service-0.0.78 lib/restpack_service/loader.rb
restpack_service-0.0.77 lib/restpack_service/loader.rb
restpack_service-0.0.76 lib/restpack_service/loader.rb
restpack_service-0.0.75 lib/restpack_service/loader.rb
restpack_service-0.0.74 lib/restpack_service/loader.rb
restpack_service-0.0.73 lib/restpack_service/loader.rb
restpack_service-0.0.72 lib/restpack_service/loader.rb
restpack_service-0.0.71 lib/restpack_service/loader.rb
restpack_service-0.0.70 lib/restpack_service/loader.rb
restpack_service-0.0.69 lib/restpack_service/loader.rb