extend_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +12 -0
- data/extend_data.gemspec +21 -0
- data/lib/extend_data.rb +39 -0
- data/lib/extend_data/version.rb +3 -0
- data/spec/extend_data_error_spec.rb +30 -0
- data/spec/extend_data_normal_spec.rb +58 -0
- data/spec/spec_helper.rb +6 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3588ad02581b05299c44a5a8b375d40dbcb7a16e
|
4
|
+
data.tar.gz: 3d0be1063f1d57653329f943d5589d592509b2a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3a790fa43a62e6c2497a43d7de594592eb9102b7f84ffd3da06e55c30b3e4c553b25c6c8beb569823177bd41c41a01284e393d8f0825352c47c2a2df57b66f5
|
7
|
+
data.tar.gz: 59e27f11f6d1e8165e0a6c6610cd3a4182c40a8a1224fba57720113958599d949dd42c39ece850cc9208f58d0e1c2502c16600128db7749579222be686ad3337
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 yukinoraru
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# ExtendData
|
2
|
+
|
3
|
+
`Object::EXTEND_DATA` is an alternative for `Object::DATA`.
|
4
|
+
It's a Hash-like accessor for multiple data sections of the executed file.
|
5
|
+
|
6
|
+
To create multiple data sections use `__${SECTION_NAME}__` below `__END__`, then you can access via `EXTEND_DATA["SECTION_NAME"]`.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
After `require 'extend_data'`, you can use `Object::EXTEND_DATA` constant.
|
10
|
+
|
11
|
+
require 'extend_data'
|
12
|
+
puts EXTEND_DATA["SECTION1"], EXTEND_DATA["SECTION2"], EXTEND_DATA["SECTION3"]
|
13
|
+
#=> "data1"
|
14
|
+
"data2"
|
15
|
+
"data3"
|
16
|
+
|
17
|
+
__END__
|
18
|
+
data0
|
19
|
+
__SECTION1__
|
20
|
+
data1
|
21
|
+
__SECTION2__
|
22
|
+
data2
|
23
|
+
__SECTION3__
|
24
|
+
data3
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
gem 'extend_data'
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install extend_data
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
task :default => :spec
|
5
|
+
|
6
|
+
desc "Run all specs in spec directory"
|
7
|
+
task :spec do
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
9
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
10
|
+
spec.rspec_opts = ['--backtrace']
|
11
|
+
end
|
12
|
+
end
|
data/extend_data.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'extend_data/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "extend_data"
|
8
|
+
gem.version = ExtendData::VERSION
|
9
|
+
gem.authors = ["yukinoraru"]
|
10
|
+
gem.email = ["yukinoraru@gmail.com"]
|
11
|
+
gem.description = %q{ExtendData is an alternative for Object::DATA}
|
12
|
+
gem.summary = %q{To create multiple data sections use `__${SECTION_NAME}__` below `__END__`, then you can access via `EXTEND_DATA["SECTION_NAME"]`.}
|
13
|
+
gem.homepage = "http://github.com/yukinoraru/extend_data"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
end
|
data/lib/extend_data.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "extend_data/version"
|
2
|
+
|
3
|
+
module ExtendData
|
4
|
+
|
5
|
+
def self.reload()
|
6
|
+
Object.class_eval { remove_const(:EXTEND_DATA) } if Object.const_defined?(:EXTEND_DATA)
|
7
|
+
end
|
8
|
+
|
9
|
+
def Object.const_missing(name)
|
10
|
+
if name.to_s =~ /^EXTEND_DATA$/
|
11
|
+
|
12
|
+
# get
|
13
|
+
path = (caller[0].split(":")).first
|
14
|
+
file = File.open(path).read
|
15
|
+
app, data = file.gsub("\r\n", "\n").split(/^__END__$/, 2)
|
16
|
+
|
17
|
+
if data.nil?
|
18
|
+
return super
|
19
|
+
end
|
20
|
+
|
21
|
+
# create
|
22
|
+
sections = %w(END) | data.scan(/^__([\w\d_\-]+)__$/).flatten
|
23
|
+
sections_data = data.split(/^__[\w\d_\-]+__$\n/)
|
24
|
+
|
25
|
+
# assign
|
26
|
+
extend_data = Hash.new
|
27
|
+
sections.zip(sections_data).each do |e|
|
28
|
+
extend_data[e.first] = e.last
|
29
|
+
end
|
30
|
+
|
31
|
+
#p path, data, sections_data, extend_data
|
32
|
+
const_set(name, extend_data)
|
33
|
+
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require_relative '../lib/extend_data'
|
4
|
+
|
5
|
+
describe "Case2" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
ExtendData::reload
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Object::EXTEND_DATA has to be a Hash" do
|
12
|
+
EXTEND_DATA.class.to_s == "Hash"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "All sections has to be nil" do
|
16
|
+
EXTEND_DATA.each do |k,v|
|
17
|
+
v.should == nil if k =~ /SECTION/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
__END__
|
24
|
+
__SECTION1__
|
25
|
+
__SECTION2__
|
26
|
+
__SECTION3__
|
27
|
+
__SECTION4__
|
28
|
+
__SECTION5__
|
29
|
+
__SECTION6__
|
30
|
+
__SECTION7__
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require_relative '../lib/extend_data'
|
4
|
+
|
5
|
+
describe "Case1" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
ExtendData::reload
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Object::EXTEND_DATA has to be a Hash" do
|
12
|
+
EXTEND_DATA.class.to_s == "Hash"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Object::EXTEND_DATA has multiple section data" do
|
16
|
+
EXTEND_DATA["TEST1"].should == "test1\ntest1\ntest1\n\n"
|
17
|
+
EXTEND_DATA["TEST-2"].should == "test2\n\n\n\n"
|
18
|
+
EXTEND_DATA["TEST_3"].should =~ /\n+/
|
19
|
+
EXTEND_DATA["TEST___4"].length.should > 0
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
__END__
|
25
|
+
end
|
26
|
+
__TEST1__
|
27
|
+
test1
|
28
|
+
test1
|
29
|
+
test1
|
30
|
+
|
31
|
+
__TEST-2__
|
32
|
+
test2
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
__TEST_3__
|
37
|
+
|
38
|
+
|
39
|
+
__TEST___4__
|
40
|
+
__NOT_A_SECTION__
|
41
|
+
__NOT_A_SECTION__
|
42
|
+
__NOT_A_SECTION__
|
43
|
+
__NOT_A_SECTION__
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extend_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yukinoraru
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: ExtendData is an alternative for Object::DATA
|
28
|
+
email:
|
29
|
+
- yukinoraru@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- Gemfile
|
37
|
+
- Guardfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- extend_data.gemspec
|
42
|
+
- lib/extend_data.rb
|
43
|
+
- lib/extend_data/version.rb
|
44
|
+
- spec/extend_data_error_spec.rb
|
45
|
+
- spec/extend_data_normal_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: http://github.com/yukinoraru/extend_data
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.2.0.preview.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: To create multiple data sections use `__${SECTION_NAME}__` below `__END__`,
|
70
|
+
then you can access via `EXTEND_DATA["SECTION_NAME"]`.
|
71
|
+
test_files:
|
72
|
+
- spec/extend_data_error_spec.rb
|
73
|
+
- spec/extend_data_normal_spec.rb
|
74
|
+
- spec/spec_helper.rb
|