global 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -2
- data/Gemfile +5 -0
- data/lib/global/configuration.rb +8 -12
- data/lib/global/engine.rb +69 -8
- data/lib/global/version.rb +2 -2
- data/spec/global/configuration_spec.rb +31 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a7a9a5f156b4b36c926824c62d8d6fd048299c4
|
4
|
+
data.tar.gz: c329c0815b12aece018e069943370ca3e4a89d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44cc4084bb0cbf4de92b1243c77b3a17ecb3c330d4b38940296af1ddc7dabbcb20e3e4559ce0c1431f9aad3baf3854055659c041ea2a0e04d1856aea4e70572a
|
7
|
+
data.tar.gz: 7cd22c3acb70423318182cad6783b5e99811dd2c0887d9660b6051ddf0689291d003e77a79b86b44c534bae76774afa5f34433398f6f041feb93e585b7d8236c
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
@@ -4,10 +4,11 @@ cache:
|
|
4
4
|
bundler: true
|
5
5
|
|
6
6
|
rvm:
|
7
|
-
- 1.9.3
|
8
7
|
- 2.0
|
9
8
|
- 2.1
|
10
9
|
- 2.2
|
10
|
+
- 2.3.3
|
11
|
+
- 2.4.1
|
11
12
|
- jruby-19mode
|
12
13
|
- ruby-head
|
13
14
|
- jruby-head
|
@@ -25,4 +26,4 @@ branches:
|
|
25
26
|
matrix:
|
26
27
|
allow_failures:
|
27
28
|
- rvm: ruby-head
|
28
|
-
- rvm: jruby-head
|
29
|
+
- rvm: jruby-head
|
data/Gemfile
CHANGED
data/lib/global/configuration.rb
CHANGED
@@ -8,7 +8,7 @@ module Global
|
|
8
8
|
|
9
9
|
attr_reader :hash
|
10
10
|
|
11
|
-
def_delegators :hash, :key?, :[], :[]=, :to_hash, :to_json, :inspect
|
11
|
+
def_delegators :hash, :key?, :has_key?, :include?, :member?, :[], :[]=, :to_hash, :to_json, :inspect
|
12
12
|
|
13
13
|
|
14
14
|
def initialize(hash)
|
@@ -20,15 +20,6 @@ module Global
|
|
20
20
|
hash.select{|key, _| keys.include?(key)}
|
21
21
|
end
|
22
22
|
|
23
|
-
def respond_to?(symbol, include_all=false)
|
24
|
-
method = normalize_key_by_method(symbol)
|
25
|
-
if key?(method)
|
26
|
-
true
|
27
|
-
else
|
28
|
-
super
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
23
|
private
|
33
24
|
|
34
25
|
def filtered_keys_list(options)
|
@@ -41,12 +32,17 @@ module Global
|
|
41
32
|
end
|
42
33
|
|
43
34
|
return hash.keys if options[:only] == :all
|
44
|
-
return [] if
|
35
|
+
return [] if options[:except] == :all
|
45
36
|
return []
|
46
37
|
end
|
47
38
|
|
48
39
|
protected
|
49
40
|
|
41
|
+
def respond_to_missing?(method_name, include_private=false)
|
42
|
+
method = normalize_key_by_method(method_name)
|
43
|
+
key?(method) || super
|
44
|
+
end
|
45
|
+
|
50
46
|
def method_missing(method, *args, &block)
|
51
47
|
method = normalize_key_by_method(method)
|
52
48
|
if key?(method)
|
@@ -63,4 +59,4 @@ module Global
|
|
63
59
|
|
64
60
|
|
65
61
|
end
|
66
|
-
end
|
62
|
+
end
|
data/lib/global/engine.rb
CHANGED
@@ -1,17 +1,78 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
2
|
module Global
|
4
|
-
class
|
3
|
+
class SprocketsExtension
|
5
4
|
GLOBAL_JS_ASSET = 'global-js'
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(filename, &block)
|
7
|
+
@filename = filename
|
8
|
+
@source = block.call
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context, empty_hash_wtf)
|
12
|
+
self.class.run(@filename, @source, context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.run(filename, source, context)
|
16
|
+
if GLOBAL_JS_ASSET == context.logical_path
|
9
17
|
configs = Dir.glob("#{Global.config_directory}#{File::SEPARATOR}*.yml")
|
10
|
-
|
11
|
-
|
12
|
-
|
18
|
+
configs.map{ |config| context.depend_on(config) }
|
19
|
+
end
|
20
|
+
source
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.call(input)
|
24
|
+
filename = input[:filename]
|
25
|
+
source = input[:data]
|
26
|
+
context = input[:environment].context_class.new(input)
|
27
|
+
|
28
|
+
result = run(filename, source, context)
|
29
|
+
context.metadata.merge(data: result)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
class Engine < ::Rails::Engine
|
35
|
+
require 'sprockets/version'
|
36
|
+
v2 = Gem::Dependency.new('', ' ~> 2')
|
37
|
+
vgte3 = Gem::Dependency.new('', ' >= 3')
|
38
|
+
sprockets_version = Gem::Version.new(::Sprockets::VERSION).release
|
39
|
+
initializer_args = case sprockets_version
|
40
|
+
when -> (v) { v2.match?('', v) }
|
41
|
+
{ after: "sprockets.environment" }
|
42
|
+
when -> (v) { vgte3.match?('', v) }
|
43
|
+
{ after: :engines_blank_point, before: :finisher_hook }
|
44
|
+
else
|
45
|
+
raise StandardError, "Sprockets version #{sprockets_version} is not supported"
|
46
|
+
end
|
47
|
+
|
48
|
+
is_running_rails = defined?(Rails) && Rails.respond_to?(:version)
|
49
|
+
is_running_rails_32 = is_running_rails && Rails.version.match(/3\.2/)
|
50
|
+
|
51
|
+
initializer 'global-js.dependent_on_configs', initializer_args do
|
52
|
+
case sprockets_version
|
53
|
+
when -> (v) { v2.match?('', v) },
|
54
|
+
-> (v) { vgte3.match?('', v) }
|
55
|
+
|
56
|
+
# It seems rails 3.2 is not working if
|
57
|
+
# `Rails.application.config.assets.configure` is used for
|
58
|
+
# registering preprocessor
|
59
|
+
if is_running_rails_32
|
60
|
+
Rails.application.assets.register_preprocessor(
|
61
|
+
"application/javascript",
|
62
|
+
SprocketsExtension
|
63
|
+
)
|
64
|
+
else
|
65
|
+
# Other rails version, assumed newer
|
66
|
+
Rails.application.config.assets.configure do |config|
|
67
|
+
config.register_preprocessor(
|
68
|
+
"application/javascript",
|
69
|
+
SprocketsExtension
|
70
|
+
)
|
71
|
+
end
|
13
72
|
end
|
73
|
+
else
|
74
|
+
raise StandardError, "Sprockets version #{sprockets_version} is not supported"
|
14
75
|
end
|
15
76
|
end
|
16
77
|
end
|
17
|
-
end
|
78
|
+
end
|
data/lib/global/version.rb
CHANGED
@@ -22,6 +22,24 @@ RSpec.describe Global::Configuration do
|
|
22
22
|
it{ is_expected.to be_truthy }
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "has_key?" do
|
26
|
+
subject{ configuration.has_key?(:key) }
|
27
|
+
|
28
|
+
it{ is_expected.to be_truthy }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "include?" do
|
32
|
+
subject{ configuration.include?(:key) }
|
33
|
+
|
34
|
+
it{ is_expected.to be_truthy }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "member?" do
|
38
|
+
subject{ configuration.member?(:key) }
|
39
|
+
|
40
|
+
it{ is_expected.to be_truthy }
|
41
|
+
end
|
42
|
+
|
25
43
|
describe "#[]" do
|
26
44
|
subject{ configuration[:key] }
|
27
45
|
|
@@ -96,7 +114,7 @@ RSpec.describe Global::Configuration do
|
|
96
114
|
end
|
97
115
|
end
|
98
116
|
|
99
|
-
describe "#
|
117
|
+
describe "#respond_to_missing?" do
|
100
118
|
context "when key exist" do
|
101
119
|
subject{ configuration.respond_to?(:key) }
|
102
120
|
|
@@ -114,6 +132,18 @@ RSpec.describe Global::Configuration do
|
|
114
132
|
|
115
133
|
it{ is_expected.to eq(true) }
|
116
134
|
end
|
135
|
+
|
136
|
+
context "when call it by method" do
|
137
|
+
subject{ configuration.method(:key).call }
|
138
|
+
|
139
|
+
it{ is_expected.to eq("value") }
|
140
|
+
end
|
141
|
+
|
142
|
+
context "when call it by method, which not exist" do
|
143
|
+
it 'raise error' do
|
144
|
+
expect{ configuration.method(:some_key) }.to raise_error(NameError)
|
145
|
+
end
|
146
|
+
end
|
117
147
|
end
|
118
148
|
|
119
149
|
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: 0.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project: global
|
133
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.4.8
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Simple way to load your configs from yaml
|