figly 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: 92096fbb361ef15bd69d38780f8a5d1c4b2d1093
4
- data.tar.gz: 54be27cfa55e83e7b4a12eea18f6e0f38d53e13e
3
+ metadata.gz: 65ac42decd3b9d8da0ffa6a4d00401300a0e83dc
4
+ data.tar.gz: d257ea30a2c4242b96d4e3213a4aab91540e213f
5
5
  SHA512:
6
- metadata.gz: 9ecce235ec39a27f398de581105cfaa69f4beafc83838a73c4a61ee7e815b5b960786c93126c7ac46b6244d6cc34745925a9d48b2cfd224079f72ec4ee6ef285
7
- data.tar.gz: 32b0cdc33f3691a5f006fdc9f13ca09fd4b3bdb5ec9de9aa2a99e9ed77f605e800e4a1893b7fda8764386f19ad560510cfffef3f638d297fa86b37141798fd75
6
+ metadata.gz: 170370e713d00bfc38576067ce7ae0b6b4d82bea2febbebb1224c6ecf220aefeef1d88894a5130c18b4344ae96e07276d68d5640134c1cfa52946c87dd2e64b4
7
+ data.tar.gz: 7e04253fef6b344ad1c7a36d54c33344835f14c831033b0fabf18f24a904e69bd4b5174483bdef7ce1de1658269abe028ec17e3b0b59d28b9d0c436ad54e3380
@@ -5,6 +5,7 @@ module Figly
5
5
  class ParserError < StandardError; end
6
6
  class UnsupportedFormatError < StandardError; end
7
7
  class ConfigNotFoundError < StandardError; end
8
+ class ConfigNotLoaded < StandardError; end
8
9
 
9
10
  def self.load_file(path)
10
11
  raise ConfigNotFoundError, "File does not exist: #{path}" unless File.exists?(path)
@@ -47,7 +48,7 @@ module Figly
47
48
  end
48
49
 
49
50
  # Here we merge config files if there are multiple load calls
50
- if defined?(@@data) && !@@data.nil?
51
+ if _config_loaded?
51
52
  _deep_merge(@@data, data)
52
53
  else
53
54
  @@data = data
@@ -60,6 +61,7 @@ module Figly
60
61
  end
61
62
 
62
63
  def self.data
64
+ _ensure_loaded!
63
65
  @@data
64
66
  end
65
67
 
@@ -67,4 +69,14 @@ module Figly
67
69
  merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
68
70
  first.merge!(second, &merger)
69
71
  end
72
+
73
+ def self._ensure_loaded!
74
+ unless _config_loaded?
75
+ raise ConfigNotLoaded, "You must first load the config before attempting to access it"
76
+ end
77
+ end
78
+
79
+ def self._config_loaded?
80
+ defined?(@@data) && @@data
81
+ end
70
82
  end
@@ -1,3 +1,3 @@
1
1
  module Figly
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -59,6 +59,8 @@ describe Figly do
59
59
  end
60
60
 
61
61
  context 'errors' do
62
+ after { Figly.clean }
63
+
62
64
  context 'ParserError' do
63
65
  it 'should error on bad.yml' do
64
66
  expect{Figly.load_file('spec/support/bad.yml')}.to raise_error(Figly::ParserError)
@@ -81,5 +83,9 @@ describe Figly do
81
83
  it 'should raise an error on an unsupported config file format' do
82
84
  expect{ Figly.load_file("spec/support/config.ini") }.to raise_error(Figly::UnsupportedFormatError)
83
85
  end
86
+
87
+ it 'should raise an exception if data is trying to be accessed before Figly has been loaded' do
88
+ expect{ Figly::Settings.a.b }.to raise_error(Figly::ConfigNotLoaded)
89
+ end
84
90
  end
85
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Canty