hexx-settings 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f8dcc52c3d6fc8e63932c27ef1414eb5ce2932e
4
- data.tar.gz: c1ee88023c131ccb60fa17f9374f89dfaf74d8f5
3
+ metadata.gz: eea12d82992465509602ac4fa8286d33979127fa
4
+ data.tar.gz: 15b2a30e2c8444d6aadd45b7a0731e439dc0529c
5
5
  SHA512:
6
- metadata.gz: 868238a3dd12f0aec79f45bc27fbef438a905b5f41be5da0b5ee7ae45316cdd5f1dc25787b051bee4feea04d78b477c5aa2674b4f2f50fcb99388c9b989d8409
7
- data.tar.gz: 3e3e89b855d31914b9fb846b8747da1d70f62da4c86846bcd7f031fc8ec42ddb48c26e77deb6732f0ae3e18b95023550f865e744cad4b252d7a6f695c6cbffc6
6
+ metadata.gz: c58582296a1408686e04a2649b6e1d99ff5067fd46ef6dab5bc556b2e3270053ecbf45413e9f644a871d46890a27a20d38c10ebec530a530a3dd41849bee98d9
7
+ data.tar.gz: a78956b1beaca51250139f65598f4cecb898dd00f2cdbac4872093bce8161247d1f5d442aba01912c8cb066dfab14979fc73fc143c572bea6ba624bb247ab1dd
data/README.md CHANGED
@@ -49,6 +49,16 @@ MyGem::Settings.instance.foo # => :bar
49
49
  MyGem::Settings[:foo] # => :bar
50
50
  ```
51
51
 
52
+ It also provides the class method `.initialize_from` to try loading
53
+ settings from given initializer:
54
+
55
+ ```ruby
56
+ MyGem::Settings.initialize_from "my_module", at: ENV["PATH_TO_INITIALIZERS"]
57
+ ```
58
+
59
+ The method doesn't fail when the initializer hasn't been found, but instead
60
+ warns the user.
61
+
52
62
  [singleton instance]: http://ruby-doc.org/stdlib-1.9.3/libdoc/singleton/rdoc/Singleton.html
53
63
 
54
64
  Installation
data/lib/hexx/settings.rb CHANGED
@@ -46,6 +46,30 @@ module Hexx
46
46
  instance.public_send setting
47
47
  end
48
48
 
49
+ # Tries to load given initializer
50
+ #
51
+ # @example
52
+ # Settings.initialize_from "my_module", at: ENV["PATH_TO_INITIALIZER"]
53
+ #
54
+ # @param [#to_s] filename
55
+ # The name of the initializer file to be loaded
56
+ #
57
+ # @option [#to_s] :at
58
+ # The absolute path to the initializers directory
59
+ #
60
+ # @return [undefined]
61
+ #
62
+ def self.initialize_from(filename, at: nil)
63
+ if at
64
+ require File.join at, filename
65
+ else
66
+ warn "You should provide the path to initializers"
67
+ end
68
+ rescue LoadError
69
+ filename << ".rb" unless filename[/\.rb$/]
70
+ warn "You should provide the '#{ filename }' initializer"
71
+ end
72
+
49
73
  end # class Settings
50
74
 
51
75
  end # module Hexx
@@ -6,7 +6,7 @@ module Hexx
6
6
 
7
7
  # The semantic version of the module.
8
8
  # @see http://semver.org/ Semantic versioning 2.0
9
- VERSION = "0.0.1".freeze
9
+ VERSION = "0.1.0".freeze
10
10
 
11
11
  end # class Settings
12
12
 
@@ -77,4 +77,60 @@ describe Hexx::Settings do
77
77
 
78
78
  end # describe []
79
79
 
80
+ describe ".initialize_from" do
81
+
82
+ before { $stderr = StringIO.new }
83
+ after { $stderr = STDERR }
84
+
85
+ context "with unexisting path to intializers" do
86
+
87
+ subject { klass.initialize_from "baz", at: "foo/bar" }
88
+
89
+ it "tries to load the initializer" do
90
+ expect(klass).to receive(:require).with "foo/bar/baz"
91
+ subject
92
+ end
93
+
94
+ it "doesn't fail" do
95
+ expect { subject }.not_to raise_error
96
+ end
97
+
98
+ it "issues a warning" do
99
+ expect { subject }
100
+ .to change { $stderr.string }
101
+ .to "You should provide the 'baz.rb' initializer\n"
102
+ end
103
+
104
+ end # context
105
+
106
+ context "when file has an extension" do
107
+
108
+ subject { klass.initialize_from "baz.rb", at: "foo/bar" }
109
+
110
+ it "issues a proper warning" do
111
+ expect { subject }
112
+ .to change { $stderr.string }
113
+ .to "You should provide the 'baz.rb' initializer\n"
114
+ end
115
+
116
+ end # context
117
+
118
+ context "without path to initializers" do
119
+
120
+ subject { klass.initialize_from "baz" }
121
+
122
+ it "doesn't fail" do
123
+ expect { subject }.not_to raise_error
124
+ end
125
+
126
+ it "issues a warning" do
127
+ expect { subject }
128
+ .to change { $stderr.string }
129
+ .to "You should provide the path to initializers\n"
130
+ end
131
+
132
+ end # context
133
+
134
+ end # describe .initialize_from
135
+
80
136
  end # describe Hexx::Settings
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexx-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hexx-rspec