global 0.1.2 → 0.2.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: d261b1f7e73030d8006467431156cfc1a39c4788
4
- data.tar.gz: 0012a6c457ad0c674bdfa3c126447db4361a56bd
3
+ metadata.gz: 6a7a9a5f156b4b36c926824c62d8d6fd048299c4
4
+ data.tar.gz: c329c0815b12aece018e069943370ca3e4a89d3f
5
5
  SHA512:
6
- metadata.gz: 0e2dec1011fb245458c2a92fa9dcdebcfd0662a0d1295285329c6fcfb21ca2e9f5c52e73d865d3789f76b7b0791f5015e3e0da8ab24c04dcda31001889af9769
7
- data.tar.gz: 0c96806548f0a4585cf07c75cd89a6f5ba52b871cfe3998d6971d831080f979f410fc828c7638d2673b70c7d02e5e34af2c3d225cb66d725578adc101c6e82d0
6
+ metadata.gz: 44cc4084bb0cbf4de92b1243c77b3a17ecb3c330d4b38940296af1ddc7dabbcb20e3e4559ce0c1431f9aad3baf3854055659c041ea2a0e04d1856aea4e70572a
7
+ data.tar.gz: 7cd22c3acb70423318182cad6783b5e99811dd2c0887d9660b6051ddf0689291d003e77a79b86b44c534bae76774afa5f34433398f6f041feb93e585b7d8236c
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.4.1
@@ -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
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in global.gemspec
4
4
  gemspec
5
+
6
+ if RUBY_VERSION < "2.2.2"
7
+ # activesupport 5+ requires MRI 2.2.2+
8
+ gem "activesupport", "< 5.0.0"
9
+ end
@@ -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 options[:except] == :all
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
@@ -1,17 +1,78 @@
1
1
  # encoding: utf-8
2
-
3
2
  module Global
4
- class Engine < ::Rails::Engine
3
+ class SprocketsExtension
5
4
  GLOBAL_JS_ASSET = 'global-js'
6
5
 
7
- initializer 'global-js.dependent_on_configs', after: "sprockets.environment" do
8
- if Rails.application.assets.respond_to?(:register_preprocessor)
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
- Rails.application.assets.register_preprocessor 'application/javascript', :'global-js_dependent_on_configs' do |ctx, data|
11
- configs.map{ |config| ctx.depend_on(config) } if ctx.logical_path == GLOBAL_JS_ASSET
12
- data
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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Global
4
- VERSION = "0.1.2"
5
- end
4
+ VERSION = "0.2.0"
5
+ end
@@ -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 "#respond_to?" do
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.1.2
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: 2015-01-13 00:00:00.000000000 Z
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.2.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