Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/srghma/require_module

Evaluates file content inside Module.new, with cache
https://github.com/srghma/require_module

Last synced: 26 days ago
JSON representation

Evaluates file content inside Module.new, with cache

Awesome Lists containing this project

README

        

# require_module

[![Build Status](https://travis-ci.org/BjornMelgaard/require_module.svg?branch=master)](https://travis-ci.org/BjornMelgaard/require_module)
[![Gem Version](https://badge.fury.io/rb/require_module.svg)](https://badge.fury.io/rb/require_module)

Evaluates file content inside Module.new, with cache

# Install
```rb
gem 'require_module'
```

# API

## require_module(fullpath)

Evaluates file content inside Module.new and returns new module

```rb
require_module('/home/user/rubyapp/lib', cache: false) # returns #
require_module('/home/user/rubyapp/lib') # returns :HomeUserRubyappLib
```

## require_module_relative(relative_path)

Similar to "require_module", but path is relative to file, where function is executed

Check `lib/require_module.rb` for more

# Example
If you don't want you modules to intersect, they should have unique name.
I was tired of coming up with new names, so created this gem.

Instead of

```rb
# lib.rb
module GloballyUniqueName
module_function

def somefn
'Ima helper'
end
end
```

```rb
# consumer.rb
require_relative './lib'

module Consumer
include GloballyUniqueName

def foo
somefn == 'Ima helper'
end
end
```

You can write this

```rb
# lib.rb
module_function

def somefn
'Ima helper'
end
```

```rb
# consumer.rb
module Consumer
include require_module_relative('./lib')

def foo
somefn == 'Ima helper'
end
end
```