Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/srghma/require_module
- Owner: srghma
- License: mit
- Created: 2018-01-12T09:22:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-29T08:20:00.000Z (over 6 years ago)
- Last Synced: 2024-11-20T22:09:51.784Z (about 2 months ago)
- Language: Ruby
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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_functiondef somefn
'Ima helper'
end
end
``````rb
# consumer.rb
require_relative './lib'module Consumer
include GloballyUniqueNamedef foo
somefn == 'Ima helper'
end
end
```You can write this
```rb
# lib.rb
module_functiondef somefn
'Ima helper'
end
``````rb
# consumer.rb
module Consumer
include require_module_relative('./lib')def foo
somefn == 'Ima helper'
end
end
```