self_data 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d17cc66d335be216b1e7f8360814296be20b5dcd
4
+ data.tar.gz: 2df2b6448361d9f4ad7ef83d79f11e608fa1388f
5
+ SHA512:
6
+ metadata.gz: 4947330d01da42f4abc83365f79fd585bdf28b1b0f01eaf1f6b7c736da2d95f92f7f1998052ac53d3741c4f5e3f9befd7d558c153bcc66bac1bb76ad56c83bb7
7
+ data.tar.gz: 891834266d340f052a44c483f97ffcab6aa64126b206f7f806e223d584f59f7ad63c860ae1be6908e1bc0f9f676f389fd26e45a2854cd8a136a0c4b9fca0b6a9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+ Exclude:
4
+ - 'self_data.gemspec'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Style/StringLiterals:
10
+ Enabled: false
11
+
12
+ Style/MultilineOperationIndentation:
13
+ EnforcedStyle: indented
14
+
15
+ Style/AndOr:
16
+ EnforcedStyle: conditionals
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in self_data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2015 7dr1v3
2
+
3
+
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # SelfData
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "self_data"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ SelfData.default_formats = [:erb, :yaml]
2
+ SelfData.default_options = {}
3
+ SelfData.filters = []
4
+
5
+ SelfData.add_converter :erb, ->(data, options) { ERB.new(data).result(options[:context]) }
6
+ SelfData.add_converter :yaml, ->(data, _options) { YAML.load(data) }
@@ -0,0 +1,31 @@
1
+ class SelfData
2
+ Error = Class.new(StandardError)
3
+
4
+ class NoDataFound < Error
5
+ attr_reader :file
6
+
7
+ def initialize(file = nil)
8
+ @file = file
9
+ super("No data found in #{file}")
10
+ end
11
+ end
12
+
13
+ class ConverterNotFound < Error
14
+ attr_reader :format
15
+
16
+ def initialize(format = nil)
17
+ @format = format
18
+ super("Not found converter for #{format}")
19
+ end
20
+ end
21
+
22
+ class ConversionError < Error
23
+ attr_reader :real_error, :format
24
+
25
+ def initialize(format = nil, real_error = nil)
26
+ @format = format
27
+ @real_error = real_error
28
+ super("#{format}: #{real_error.inspect}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ class SelfData
2
+ VERSION = "0.1.0"
3
+ end
data/lib/self_data.rb ADDED
@@ -0,0 +1,63 @@
1
+ require "yaml"
2
+ require "active_support/core_ext/module/delegation.rb"
3
+ require "active_support/core_ext/class/attribute.rb"
4
+
5
+ class SelfData
6
+ class_attribute :default_formats, :default_options, :filters, :converters
7
+
8
+ class << self
9
+ delegate :read, :load, to: :new
10
+
11
+ def add_filter(&block)
12
+ filters << block
13
+ end
14
+
15
+ def add_converter(name, block)
16
+ self.converters ||= {}
17
+ self.converters[name] = block
18
+ end
19
+ end
20
+
21
+ attr_reader :file
22
+
23
+ def initialize(file = caller_file)
24
+ @file = file
25
+ end
26
+
27
+ def load(*formats, **options)
28
+ formats = default_formats if formats.empty?
29
+ options = default_options if options.empty?
30
+
31
+ formats.reduce(read) do |data, format|
32
+ fail ConverterNotFound, format unless converters[format]
33
+ begin
34
+ converters[format].call(data, options)
35
+ rescue => e
36
+ raise ConversionError, format, e
37
+ end
38
+ end
39
+ end
40
+
41
+ def read
42
+ IO.read(file).scan(/\n__END__\n(.*)/m).flatten.first or fail NoDataFound, file
43
+ end
44
+
45
+ private
46
+
47
+ def caller_file
48
+ calls = caller.lazy
49
+ .map { |call_string| call_string.split(':').first }
50
+ .select { |file| file != __FILE__ }
51
+ .select(&File.method(:exist?))
52
+
53
+ filters.each do |filter|
54
+ calls = calls.select(&filter.method(:call))
55
+ end
56
+
57
+ calls.first
58
+ end
59
+ end
60
+
61
+ require "self_data/errors"
62
+ require "self_data/version"
63
+ require "self_data/config"
data/self_data.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'self_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "self_data"
8
+ spec.version = SelfData::VERSION
9
+ spec.authors = ["TDrive"]
10
+ spec.email = ["tdrive@xc0de.ru"]
11
+
12
+ spec.summary = ""
13
+ spec.description = "It's like DATA but better"
14
+ spec.homepage = "https://github.com/7dr1v3/self_data"
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "activesupport", ">= 3.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.4"
27
+ spec.add_development_dependency "rubocop", "~> 0.35"
28
+ spec.add_development_dependency "pry"
29
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: self_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TDrive
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.35'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.35'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: It's like DATA but better
98
+ email:
99
+ - tdrive@xc0de.ru
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/self_data.rb
115
+ - lib/self_data/config.rb
116
+ - lib/self_data/errors.rb
117
+ - lib/self_data/version.rb
118
+ - self_data.gemspec
119
+ homepage: https://github.com/7dr1v3/self_data
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: ''
143
+ test_files: []