global 1.0.0 → 1.1.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
- SHA1:
3
- metadata.gz: 5ada6d5fbc1aaf1b03e1e5db9200c33f2e22108e
4
- data.tar.gz: bd7c8bc34931654e6bd89fb6d2cf6fd4c7e7d123
2
+ SHA256:
3
+ metadata.gz: b01380c2ead8dd05766d2d01dff1fbc24aff74ab22d6cdca72b6d5bcf92409e8
4
+ data.tar.gz: 596fd34a00183fca92f01cab9e6a0214275036abc93accea2f88f4646a764448
5
5
  SHA512:
6
- metadata.gz: 6209994c37c074286978e2b34e5d81fc0b93818fc75fb682cb0750de13ac2656926cbde9639507e3d0f9049469b9789b853d3a61bedbdfdf528849db242165f8
7
- data.tar.gz: b5c74f586b5dd5db6c1826e355ba159ecd6e05b316071c212acf4ac3d9801a776742c5a0693b1ca1a9cdd9fa1ab69bb03be33d4d66fdd59f78b35c19498d7180
6
+ metadata.gz: 6fa1a2e2ebc3092e3b61a4c2ce7104db18947c1fb1a9a73b5cfe2bceecfb575485c9cf426a841f63f72b08db84cee51d0fec3eb7d4f4db629d3d9b3edde13252
7
+ data.tar.gz: fee130c0b00643657da8f8bc191a86c111e80a8da40ac1b62c0d34765d775e70ac7393078213425987af1378bcaac02a8f245dc66804aa4b094a2f1f393653fb
data/README.md CHANGED
@@ -15,6 +15,7 @@ gem 'global'
15
15
  ```ruby
16
16
  > Global.environment = "YOUR_ENV_HERE"
17
17
  > Global.config_directory = "PATH_TO_DIRECTORY_WITH_FILES"
18
+ > Global.yaml_whitelist_classes = [] # optional configuration
18
19
  ```
19
20
 
20
21
  Or you can use `configure` block:
@@ -23,6 +24,7 @@ Or you can use `configure` block:
23
24
  Global.configure do |config|
24
25
  config.environment = "YOUR_ENV_HERE"
25
26
  config.config_directory = "PATH_TO_DIRECTORY_WITH_FILES"
27
+ config.yaml_whitelist_classes = [] # optional configuration
26
28
  end
27
29
  ```
28
30
 
@@ -32,9 +34,12 @@ For rails put initialization into `config/initializers/global.rb`
32
34
  Global.configure do |config|
33
35
  config.environment = Rails.env.to_s
34
36
  config.config_directory = Rails.root.join('config/global').to_s
37
+ config.yaml_whitelist_classes = [] # optional configuration
35
38
  end
36
39
  ```
37
40
 
41
+ The `yaml_whitelist_classes` configuration allows you to deserialize other classes from your `.yml`
42
+
38
43
  ## Usage
39
44
 
40
45
  ### General
@@ -62,6 +67,23 @@ In the development environment we now have:
62
67
  => "api.localhost"
63
68
  ```
64
69
 
70
+ #### Deserialize other classes from `.yml`
71
+
72
+ Config file `config/global/validations.yml`:
73
+
74
+ ```yml
75
+ default:
76
+ regexp:
77
+ email: !ruby/regexp /.@.+\../
78
+ ```
79
+
80
+ Ensure that `Regexp` is included in the `yaml_whitelist_classes` array
81
+
82
+ ```ruby
83
+ Global.validations.regexp.email === 'mail@example.com'
84
+ => true
85
+ ```
86
+
65
87
  ### Namespacing
66
88
 
67
89
  Config file `config/global/web/basic_auth.yml` with:
data/lib/global/base.rb CHANGED
@@ -11,7 +11,7 @@ module Global
11
11
 
12
12
  extend self
13
13
 
14
- attr_writer :environment, :config_directory, :namespace, :except, :only
14
+ attr_writer :environment, :config_directory, :namespace, :except, :only, :yaml_whitelist_classes
15
15
 
16
16
  def configure
17
17
  yield self
@@ -46,6 +46,10 @@ module Global
46
46
  @only ||= []
47
47
  end
48
48
 
49
+ def yaml_whitelist_classes
50
+ @yaml_whitelist_classes ||= []
51
+ end
52
+
49
53
  def generate_js(options = {})
50
54
  current_namespace = options[:namespace] || namespace
51
55
 
@@ -83,7 +87,8 @@ module Global
83
87
  def load_yml_file(file)
84
88
  YAML.safe_load(
85
89
  ERB.new(IO.read(file)).result,
86
- [Date, Time, DateTime, Symbol], [], true
90
+ [Date, Time, DateTime, Symbol].concat(yaml_whitelist_classes),
91
+ [], true
87
92
  )
88
93
  end
89
94
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Global
4
4
 
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Railsware LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project: global
150
- rubygems_version: 2.6.11
150
+ rubygems_version: 2.7.6
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Simple way to load your configs from yaml