self_data 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1201a0f6a585e439017884ffa5b3afec52eac0aa1a9a0087117e326d1b340a58
4
- data.tar.gz: d31a28c60370483eb586ef7f727c7ce5dcaa9cd2dc1b944901727943c1335c88
3
+ metadata.gz: 0aea1610e7159d6d6ee44a4767f6906e007c436352debb0b852a59ce3550a889
4
+ data.tar.gz: 67a2e1ba3dbaf1c39a0c0c6ba62013d6fb6ef23bf6c35b1fe49e8b78a3b9606d
5
5
  SHA512:
6
- metadata.gz: cefd92d3033735314a03cede47baf2bf5c962b51eb7f5dcbec922dd4553f50b60e904bcda4e5f728a676f1f669a502b86962a7bf3dc8cc573d6bf4b2c7eb8820
7
- data.tar.gz: 0f4197e8a3e5b1e268e14d7ce5f8e471fcd1889b932bb9e97a2bc8d420e1a6dd837a8e3078dd2251a8fe7694166c8a9ee71dabe49c6411ee7dbfdb338ecf747a
6
+ metadata.gz: 7901656e8e7c1427e069e97f33e8a6262fd5a8a4e2ce49d0bb296cdde14965d9ccb6ceb30703632f01d2b4c3059a80b46070fa760698904c7da67488767238f1
7
+ data.tar.gz: 8a9026eaf762ae36aa1247927e4f8dfbf1f2ca557582ebace53258a638473e4cd0b58a0b1f82166b25e140d9945bc956f0a322a3a44bd076e5c56ac7fa16cc6f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SelfData
2
2
 
3
- It's like native ruby DATA but you can use it not only for main file.
3
+ It's like native ruby `DATA` but you can use it not only for main file.
4
4
 
5
5
  For example:
6
6
  ```ruby
@@ -48,4 +48,4 @@ Use `SelfData.read()` to get text or use `SelfData.load(*formats, **options)` to
48
48
  Look at the [lib/self_data/config.rb](https://github.com/umbrellio/self_data/blob/master/lib/self_data/config.rb) for more details.
49
49
 
50
50
  # Note
51
- SelfData use caller, it's not fast, that is why you shouldn't use SelfData in loops.
51
+ SelfData uses `caller`, it's not fast, that's why you shouldn't use SelfData in loops.
@@ -2,22 +2,33 @@
2
2
 
3
3
  require "yaml"
4
4
  require "json"
5
- require "active_support/core_ext/module/delegation.rb"
6
- require "active_support/core_ext/class/attribute.rb"
7
5
 
8
6
  class SelfData
9
- class_attribute :default_formats, :default_options, :filters, :converters
10
-
11
7
  class << self
12
- delegate :read, :load, to: :new
8
+ attr_accessor :default_formats, :default_options
9
+
10
+ def read(*args)
11
+ new.read(*args)
12
+ end
13
+
14
+ def load(*args)
15
+ new.load(*args)
16
+ end
17
+
18
+ def filters
19
+ @filters ||= []
20
+ end
13
21
 
14
22
  def add_filter(&block)
15
23
  filters << block
16
24
  end
17
25
 
26
+ def converters
27
+ @converters ||= {}
28
+ end
29
+
18
30
  def add_converter(name, block)
19
- self.converters ||= {}
20
- self.converters[name] = block
31
+ converters[name] = block
21
32
  end
22
33
  end
23
34
 
@@ -28,13 +39,13 @@ class SelfData
28
39
  end
29
40
 
30
41
  def load(*formats, **options)
31
- formats = default_formats if formats.empty?
32
- options = default_options if options.empty?
42
+ formats = self.class.default_formats if formats.empty?
43
+ options = self.class.default_options if options.empty?
33
44
 
34
45
  formats.reduce(read) do |data, format|
35
- raise ConverterNotFound, format unless converters[format]
46
+ raise ConverterNotFound, format unless self.class.converters[format]
36
47
  begin
37
- converters[format].call(data, options)
48
+ self.class.converters[format].call(data, options)
38
49
  rescue => e
39
50
  raise ConversionError.new(format, e)
40
51
  end
@@ -53,7 +64,7 @@ class SelfData
53
64
  .reject { |file| file == __FILE__ }
54
65
  .select(&File.method(:exist?))
55
66
 
56
- filters.each do |filter|
67
+ self.class.filters.each do |filter|
57
68
  calls = calls.select(&filter.method(:call))
58
69
  end
59
70
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  SelfData.default_formats = [:erb, :yaml]
4
4
  SelfData.default_options = {}
5
- SelfData.filters = []
6
5
 
7
6
  SelfData.add_converter :erb, -> (data, options) { ERB.new(data).result(options[:context]) }
8
7
  SelfData.add_converter :yaml, -> (data, _options) { YAML.load(data) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SelfData
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -22,8 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_runtime_dependency "activesupport", ">= 3.0"
26
-
27
25
  spec.add_development_dependency "bundler"
28
26
  spec.add_development_dependency "pry"
29
27
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: self_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Umbrellio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-04 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement