https://github.com/umbrellio/self_data
It's like native ruby DATA but you can use it not only for main file.
https://github.com/umbrellio/self_data
Last synced: about 1 year ago
JSON representation
It's like native ruby DATA but you can use it not only for main file.
- Host: GitHub
- URL: https://github.com/umbrellio/self_data
- Owner: umbrellio
- License: mit
- Created: 2015-12-01T07:46:41.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-03-16T08:51:36.000Z (over 3 years ago)
- Last Synced: 2024-10-31T13:01:30.924Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 31.3 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SelfData · [](https://badge.fury.io/rb/self_data) [](https://travis-ci.org/umbrellio/self_data) [](https://coveralls.io/github/umbrellio/self_data)
It's like native ruby `DATA` but you can use it not only for main file.
## Installation
```ruby
# Gemfile
gem 'self_data'
```
```shell
$ bundle install
-- or --
$ gem install self_data
```
```ruby
require 'self_data'
```
## Synopsis
```ruby
# main.rb
require 'self_data'
require './a.rb'
puts "DATA: #{A.native_data}"
puts "SelfData: #{A.self_data}"
__END__
main.rb data
```
```ruby
# a.rb
module A
module_function
def native_data
DATA.read
end
def self_data
SelfData.read
end
end
__END__
a.rb data
```
and if you execute it, you'll get:
```shell
$ ruby main.rb
DATA: main.rb data
SelfData: a.rb data
```
## Usage and Notes
Use `SelfData.read()` to get text or use `SelfData.load(*formats, **options)` to get formatted data (like yaml, xml, erb, etc).
Look at the [lib/self_data/config.rb](https://github.com/umbrellio/self_data/blob/master/lib/self_data/config.rb) for more details.
SelfData uses `caller`, it's not fast, that's why you shouldn't use SelfData in loops.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/self_data.
## License
Released under MIT License.
## Authors
Created by [7dr1v3](https://github.com/7dr1v3)