global 0.0.3 → 0.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
2
  SHA1:
3
- metadata.gz: a948818df60cb23dc3695891852506c443ca6130
4
- data.tar.gz: 8765c67649a429336e040cbbbe000736474646bf
3
+ metadata.gz: 34fd5c7c444192f6ad38962cc264488bb75794c9
4
+ data.tar.gz: d2cf50332549632d30e568e7b84f255aee706b22
5
5
  SHA512:
6
- metadata.gz: 8b3eaf9cbcb32138af748b51943733026142df18a673bb1bd7a6928aa238d5b5b6b28f59a534eb058110725094e00876257485bb11e77310b2780f841f6a64b6
7
- data.tar.gz: ca9b019175be4a8e5eccaa6a76e04025022dbde9cb0df498a59747f7e1166df86db231df9340d539b1ffca2d8100e8af3e2a18f82f3cd478c892b775564c4c84
6
+ metadata.gz: 138a9a5f829f1a6665101328d839a7e0fa814488ab0c45a3d7ec013344d458eac0df39d28d6a786f6704f2b4956aae2ed48d69a6744a52a4db69d953ce78c02b
7
+ data.tar.gz: 7f0ff0af444ed05b31e57dcafb892fa8b1ce7bd077a4e75146fe64a65c0f89a405d56926dedd24570912a74f7c20684cb7f3099a2cfdaf621d1d90700ec66829
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .rspec
6
- coverage/**
6
+ coverage/**
7
+ .DS_Store
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1.2
data/.travis.yml CHANGED
@@ -2,7 +2,10 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.2
6
+ - jruby-19mode
5
7
  - ruby-head
8
+ - jruby-head
6
9
  notifications:
7
10
  email: false
8
11
  branches:
@@ -11,4 +14,5 @@ branches:
11
14
  - development
12
15
  matrix:
13
16
  allow_failures:
14
- - rvm: ruby-head
17
+ - rvm: ruby-head
18
+ - rvm: jruby-head
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # global [![Build Status](https://travis-ci.org/railsware/global.png)](https://travis-ci.org/railsware/global) [![Code Climate](https://codeclimate.com/github/railsware/global.png)](https://codeclimate.com/github/railsware/global)
1
+ # Global [![Build Status](https://travis-ci.org/railsware/global.png)](https://travis-ci.org/railsware/global) [![Code Climate](https://codeclimate.com/github/railsware/global.png)](https://codeclimate.com/github/railsware/global)
2
2
 
3
- ## Description
3
+ The 'global' gem provides accessor methods for your configuration data and share configuration across backend and frontend. The data is stored in yaml files.
4
4
 
5
- Global provides accessors methods to your configuration which is stored in yaml files.
5
+ ## Installation
6
6
 
7
- ## Instalation
7
+ Add to Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'global'
@@ -17,11 +17,22 @@ gem 'global'
17
17
  > Global.config_directory = "PATH_TO_DIRECTORY_WITH_FILES"
18
18
  ```
19
19
 
20
+ Or you can use `configure` block:
21
+
22
+ ```ruby
23
+ Global.configure do |config|
24
+ config.environment = "YOUR_ENV_HERE"
25
+ config.config_directory = "PATH_TO_DIRECTORY_WITH_FILES"
26
+ end
27
+ ```
28
+
20
29
  For rails put initialization into `config/initializers/global.rb`
21
30
 
22
31
  ```ruby
23
- Global.environment = Rails.env.to_s
24
- Global.config_directory = Rails.root.join('config/global').to_s
32
+ Global.configure do |config|
33
+ config.environment = Rails.env.to_s
34
+ config.config_directory = Rails.root.join('config/global').to_s
35
+ end
25
36
  ```
26
37
 
27
38
  ## Usage
@@ -42,7 +53,7 @@ production:
42
53
  api: api.myhost.com
43
54
  ```
44
55
 
45
- Now for development environment we have next data:
56
+ In the development environment we now have:
46
57
 
47
58
  ```ruby
48
59
  > Global.hosts
@@ -57,10 +68,10 @@ Config file `config/global/web/basic_auth.yml` with:
57
68
 
58
69
  ```yml
59
70
  test:
60
- username: user
71
+ username: test_user
61
72
  password: secret
62
73
  development:
63
- username: user
74
+ username: development_user
64
75
  password: secret
65
76
  production:
66
77
  username: production_user
@@ -89,7 +100,7 @@ production:
89
100
  api: api.myhost.com
90
101
  ```
91
102
 
92
- Data from default section uses until it's overridden in specific environment.
103
+ Data from the default section is used until it's overridden in a specific environment.
93
104
 
94
105
  ### Nested configurations
95
106
 
@@ -106,13 +117,14 @@ production:
106
117
  key: "production value"
107
118
  ```
108
119
 
109
- Access to nested options provides like:
120
+ Nested options can then be accessed as follows:
110
121
 
111
122
  ```ruby
112
123
  > Global.nested.group.key
113
124
  => "development value"
114
125
  ```
115
126
 
127
+
116
128
  ### ERB support
117
129
 
118
130
  Config file `global/file_name.yml` with:
@@ -126,7 +138,7 @@ production:
126
138
  key: <%=3+3%>
127
139
  ```
128
140
 
129
- As a result in development environment we have:
141
+ As a result, in the development environment we have:
130
142
 
131
143
  ```ruby
132
144
  > Global.file_name.key
@@ -139,6 +151,75 @@ As a result in development environment we have:
139
151
  > Global.reload!
140
152
  ```
141
153
 
154
+ ## JavaScript in Rails support
155
+
156
+ ### Configuration
157
+
158
+ ```ruby
159
+ Global.configure do |config|
160
+ config.namespace = "JAVASCRIPT_OBJECT_NAME" # default Global
161
+ config.except = ["LIST_OF_FILES_TO_EXCLUDE_ON_FRONT_END"] # default :all
162
+ config.only = ["LIST_OF_FILES_TO_INCLUDE_ON_FRONT_END"] # default []
163
+ end
164
+ ```
165
+ By default all files are excluded due to security reasons. Don't include files which contain protected information like api keys or credentials.
166
+
167
+ Require global file in `application.js`:
168
+
169
+ ``` js
170
+ /*
171
+ = require global-js
172
+ */
173
+ ```
174
+
175
+ ### Advanced Configuration
176
+
177
+ In case you need different configurations for different parts of your application, you should create the files manually.
178
+
179
+ If your application has `admin` and `application` namespace:
180
+
181
+ ```erb
182
+ # app/assets/javascripts/admin/global.js.erb
183
+ <%= Global.generate_js(namespace: "AdminSettings", only: %w(admin hosts)) %>
184
+
185
+ # app/assets/javascripts/admin.js.coffee
186
+ #= require admin/global
187
+ ```
188
+
189
+ ```erb
190
+ # app/assets/javascripts/application/global.js.erb
191
+ <%= Global.generate_js(namespace: "AppSettings", except: %w(admin credentials)) %>
192
+
193
+ # app/assets/javascripts/application.js.coffee
194
+ #= require application/global
195
+ ```
196
+
197
+ ### Usage
198
+
199
+ Config file example `global/hosts.yml`:
200
+
201
+ ```yml
202
+ development:
203
+ web: localhost
204
+ api: api.localhost
205
+ production:
206
+ web: myhost.com
207
+ api: api.myhost.com
208
+ ```
209
+ After that in development environment we have:
210
+
211
+ ``` js
212
+ Global.hosts.web
213
+ => "localhost"
214
+ ```
215
+
216
+ And in production:
217
+
218
+ ``` js
219
+ Global.hosts.web
220
+ => "myhost.com"
221
+ ```
222
+
142
223
  ## Contributing to global
143
224
 
144
225
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -151,6 +232,5 @@ As a result in development environment we have:
151
232
 
152
233
  ## Copyright
153
234
 
154
- Copyright (c) 2013 Railsware LLC. See LICENSE.txt for
155
- further details.
235
+ Copyright (c) Railsware LLC. See LICENSE.txt for further details.
156
236
 
@@ -0,0 +1,2 @@
1
+ <%# encoding: UTF-8 %>
2
+ <%= Global.generate_js %>
data/global.gemspec CHANGED
@@ -20,9 +20,14 @@ Gem::Specification.new do |s|
20
20
  s.homepage = "https://github.com/railsware/global"
21
21
  s.licenses = ["MIT"]
22
22
 
23
- s.add_development_dependency "rspec", "~> 2.14.1"
23
+ s.add_development_dependency "rspec", ">= 3.0"
24
24
  s.add_development_dependency "simplecov", "~> 0.7.1"
25
25
  s.add_development_dependency "rake", "~> 10.1.0"
26
+ if defined?(JRUBY_VERSION)
27
+ s.add_development_dependency "therubyrhino", ">= 0"
28
+ else
29
+ s.add_development_dependency "therubyracer", ">= 0"
30
+ end
26
31
 
27
- s.add_runtime_dependency "activesupport"
32
+ s.add_runtime_dependency "activesupport", ">= 2.0"
28
33
  end
data/lib/global.rb CHANGED
@@ -1,11 +1,13 @@
1
+ # encoding: utf-8
1
2
  require 'yaml'
2
3
 
3
4
  require 'active_support/core_ext/hash/indifferent_access'
4
5
  require 'active_support/core_ext/hash/deep_merge'
5
6
 
6
- require "global/configuration"
7
- require "global/base"
8
- require "global/version"
7
+ require 'global/configuration'
8
+ require 'global/base'
9
+ require 'global/engine' if defined?(Rails)
10
+ require 'global/version'
9
11
 
10
12
  module Global
11
13
  extend Base
data/lib/global/base.rb CHANGED
@@ -1,7 +1,18 @@
1
- require "erb"
1
+ # encoding: utf-8
2
+
3
+ require 'erb'
4
+ require 'json'
2
5
 
3
6
  module Global
4
7
  module Base
8
+ extend self
9
+
10
+ attr_writer :environment, :config_directory, :namespace, :except, :only
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
5
16
  def configuration
6
17
  @configuration ||= load_configuration(config_directory, environment)
7
18
  end
@@ -11,14 +22,6 @@ module Global
11
22
  configuration
12
23
  end
13
24
 
14
- def environment=(env)
15
- @environment = env
16
- end
17
-
18
- def config_directory=(dir)
19
- @config_directory = dir
20
- end
21
-
22
25
  def environment
23
26
  @environment || raise("environment should be defined")
24
27
  end
@@ -27,13 +30,30 @@ module Global
27
30
  @config_directory || raise("config_directory should be defined")
28
31
  end
29
32
 
33
+ def namespace
34
+ @namespace ||= 'Global'
35
+ end
36
+
37
+ def except
38
+ @except ||= :all
39
+ end
40
+
41
+ def only
42
+ @only ||= []
43
+ end
44
+
45
+ def generate_js(options = {})
46
+ current_namespace = options[:namespace] || namespace
47
+
48
+ js_options = { except: except, only: only }.merge(options)
49
+ "window.#{current_namespace} = #{configuration.filter(js_options).to_json}"
50
+ end
51
+
30
52
  protected
31
53
 
32
54
  def load_configuration(dir, env)
33
55
  config = load_from_file(dir, env)
34
-
35
56
  config.deep_merge!(load_from_directory(dir, env))
36
-
37
57
  Configuration.new(config)
38
58
  end
39
59
 
@@ -1,4 +1,6 @@
1
- require "forwardable"
1
+ # encoding: utf-8
2
+
3
+ require 'forwardable'
2
4
 
3
5
  module Global
4
6
  class Configuration
@@ -6,13 +8,34 @@ module Global
6
8
 
7
9
  attr_reader :hash
8
10
 
9
- def_delegators :hash, :to_hash, :key?, :[], :[]=, :inspect
11
+ def_delegators :hash, :key?, :[], :[]=, :to_hash, :to_json, :inspect
10
12
 
11
13
 
12
14
  def initialize(hash)
13
15
  @hash = hash.respond_to?(:with_indifferent_access) ? hash.with_indifferent_access : hash
14
16
  end
15
17
 
18
+ def filter(options = {})
19
+ keys = filtered_keys_list(options)
20
+ hash.select{|key, _| keys.include?(key)}
21
+ end
22
+
23
+ private
24
+
25
+ def filtered_keys_list(options)
26
+ if options[:except].is_a?(Array)
27
+ return hash.keys - options[:except].map(&:to_s)
28
+ end
29
+
30
+ if options[:only].is_a?(Array)
31
+ return hash.keys & options[:only].map(&:to_s)
32
+ end
33
+
34
+ return hash.keys if options[:only] == :all
35
+ return [] if options[:except] == :all
36
+ return []
37
+ end
38
+
16
39
  protected
17
40
 
18
41
  def method_missing(method, *args, &block)
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ module Global
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Global
2
- VERSION = "0.0.3"
4
+ VERSION = "0.1.0"
3
5
  end
@@ -1,6 +1,10 @@
1
1
  :default:
2
2
  nested:
3
3
  test_value: "default value"
4
+ some_array_value:
5
+ - "First"
6
+ - "Second"
7
+ - "Third"
4
8
 
5
9
  test:
6
10
  nested:
@@ -7,25 +7,25 @@ describe Global::Configuration do
7
7
  describe "#hash" do
8
8
  subject{ configuration.hash }
9
9
 
10
- it{ should == hash }
10
+ it{ is_expected.to eq(hash) }
11
11
  end
12
12
 
13
13
  describe "#to_hash" do
14
14
  subject{ configuration.to_hash }
15
15
 
16
- it{ should == hash }
16
+ it{ is_expected.to eq(hash) }
17
17
  end
18
18
 
19
19
  describe "key?" do
20
20
  subject{ configuration.key?(:key) }
21
21
 
22
- it{ should be_true }
22
+ it{ is_expected.to be_truthy }
23
23
  end
24
24
 
25
25
  describe "#[]" do
26
26
  subject{ configuration[:key] }
27
27
 
28
- it{ should == "value" }
28
+ it{ is_expected.to eq("value") }
29
29
  end
30
30
 
31
31
  describe "#[]=" do
@@ -33,32 +33,66 @@ describe Global::Configuration do
33
33
 
34
34
  before{ configuration[:new_key] = "new_value" }
35
35
 
36
- it{ should == "new_value" }
36
+ it{ is_expected.to eq("new_value") }
37
37
  end
38
38
 
39
39
  describe "#inspect" do
40
40
  subject{ configuration.inspect }
41
41
 
42
- it{ should == hash.inspect }
42
+ it{ is_expected.to eq(hash.inspect) }
43
+ end
44
+
45
+ describe "#filter" do
46
+ subject{ configuration.filter(filter_options) }
47
+
48
+ context "when include all" do
49
+ let(:filter_options){ { only: :all } }
50
+
51
+ it{ should == {"key"=>"value", "nested"=>{"key"=>"value"}} }
52
+ end
53
+
54
+ context "when except all" do
55
+ let(:filter_options){ { except: :all } }
56
+
57
+ it{ should == {} }
58
+ end
59
+
60
+ context "when except present" do
61
+ let(:filter_options){ { except: %w(key) } }
62
+
63
+ it{ should == {"nested"=>{"key"=>"value"}} }
64
+ end
65
+
66
+ context "when include present" do
67
+ let(:filter_options){ { only: %w(key) } }
68
+
69
+ it{ should == {"key"=>"value"} }
70
+ end
71
+
72
+ context "when empty options" do
73
+ let(:filter_options){ {} }
74
+
75
+ it{ should == {} }
76
+ end
43
77
  end
44
78
 
45
79
  describe "#method_missing" do
46
80
  context "when key exist" do
47
81
  subject{ configuration.key }
48
82
 
49
- it{ should == "value" }
83
+ it{ is_expected.to eq("value") }
50
84
  end
51
85
 
52
86
  context "when key does not exist" do
53
87
  subject{ configuration.some_key }
54
88
 
55
- it{ lambda { subject }.should raise_error(NoMethodError) }
89
+ it{ expect { subject }.to raise_error(NoMethodError) }
56
90
  end
57
91
 
58
92
  context "with nested hash" do
59
93
  subject{ configuration.nested.key }
60
94
 
61
- it{ should == "value" }
95
+ it{ is_expected.to eq("value") }
62
96
  end
63
97
  end
64
98
  end
@@ -0,0 +1,114 @@
1
+ require "spec_helper"
2
+
3
+ describe Global, "generate js in Rails" do
4
+ before do
5
+ evaljs("var window = this;", true)
6
+ jscontext[:log] = lambda {|context, value| puts value.inspect}
7
+
8
+ described_class.configure do |config|
9
+ config.environment = "test"
10
+ config.config_directory = File.join(Dir.pwd, "spec/files")
11
+ end
12
+
13
+ end
14
+
15
+ context 'simple generate' do
16
+ before do
17
+ described_class.configure do |config|
18
+ config.namespace = 'Global'
19
+ config.except = :all
20
+ config.only = :all
21
+ end
22
+ evaljs(described_class.generate_js)
23
+ end
24
+
25
+ it "should generate valid global config" do
26
+ expect(evaljs("Global.rspec_config.default_value")).to eq('default value')
27
+ end
28
+
29
+ it "should generate valid global config for array" do
30
+ expect(evaljs("Global.nested_config.some_array_value.length")).to eq(3)
31
+ end
32
+
33
+ it "should generate valid global config for array, first element" do
34
+ expect(evaljs("Global.nested_config.some_array_value[0]")).to eq("First")
35
+ end
36
+
37
+ it "should generate valid global config for array, last element" do
38
+ expect(evaljs("Global.nested_config.some_array_value[2]")).to eq("Third")
39
+ end
40
+
41
+ end
42
+
43
+ context 'custom namespace' do
44
+ before do
45
+ described_class.configure do |config|
46
+ config.namespace = 'CustomGlobal'
47
+ config.except = :all
48
+ config.only = :all
49
+ end
50
+ evaljs(described_class.generate_js)
51
+ end
52
+
53
+ it "should generate valid global config" do
54
+ expect(evaljs("CustomGlobal.rspec_config.default_value")).to eq('default value')
55
+ end
56
+
57
+ end
58
+
59
+ context 'custom namespace from function' do
60
+ before do
61
+ evaljs(described_class.generate_js(namespace: 'CustomGlobalNamespace', only: :all))
62
+ end
63
+
64
+ it "should generate valid global config" do
65
+ expect(evaljs("CustomGlobalNamespace.rspec_config.default_value")).to eq('default value')
66
+ end
67
+
68
+ end
69
+
70
+ context 'only select' do
71
+ before do
72
+ described_class.configure do |config|
73
+ config.namespace = 'Global'
74
+ config.except = :all
75
+ config.only = [:bool_config]
76
+ end
77
+
78
+ evaljs(described_class.generate_js)
79
+ end
80
+
81
+ it "should generate visible global config" do
82
+ expect(evaljs("Global.bool_config.works")).to eq(true)
83
+ end
84
+
85
+ it "should have not some keys in js" do
86
+ expect(evaljs("Global.nested_config")).to be_nil
87
+ end
88
+
89
+ end
90
+
91
+ context 'except select' do
92
+ before do
93
+ described_class.configure do |config|
94
+ config.namespace = 'Global'
95
+ config.except = [:nested_config]
96
+ config.only = []
97
+ end
98
+ evaljs(described_class.generate_js)
99
+ end
100
+
101
+ it "should generate visible global config with bool_config" do
102
+ expect(evaljs("Global.bool_config.works")).to eq(true)
103
+ end
104
+
105
+ it "should generate visible global config with rspec_config" do
106
+ expect(evaljs("Global.rspec_config.default_value")).to eq('default value')
107
+ end
108
+
109
+ it "should have not some keys in js" do
110
+ expect(evaljs("Global.nested_config")).to be_nil
111
+ end
112
+
113
+ end
114
+ end
data/spec/global_spec.rb CHANGED
@@ -1,57 +1,72 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Global do
4
+
4
5
  before(:each) do
5
- described_class.environment = "test"
6
- described_class.config_directory = File.join(Dir.pwd, "spec/files")
6
+ described_class.configure do |config|
7
+ config.environment = "test"
8
+ config.config_directory = File.join(Dir.pwd, "spec/files")
9
+ end
7
10
  end
8
11
 
9
12
  describe ".environment" do
10
13
  subject{ described_class.environment }
11
14
 
12
- it{ should == "test" }
15
+ it{ is_expected.to eq("test") }
13
16
 
14
17
  context "when undefined" do
15
18
  before{ described_class.environment = nil }
16
19
 
17
- it{ lambda{ subject }.should raise_error("environment should be defined") }
20
+ it{ expect{ subject }.to raise_error("environment should be defined") }
18
21
  end
19
22
  end
20
23
 
21
24
  describe ".config_directory" do
22
25
  subject{ described_class.config_directory }
23
26
 
24
- it{ should == File.join(Dir.pwd, "spec/files")}
27
+ it{ is_expected.to eq(File.join(Dir.pwd, "spec/files"))}
25
28
 
26
29
  context "when undefined" do
27
30
  before{ described_class.config_directory = nil }
28
31
 
29
- it{ lambda{ subject }.should raise_error("config_directory should be defined") }
32
+ it{ expect{ subject }.to raise_error("config_directory should be defined") }
30
33
  end
31
34
  end
32
35
 
33
36
  describe ".configuration" do
34
37
  subject{ described_class.configuration }
35
38
 
36
- it{ should be_instance_of(Global::Configuration) }
39
+ it{ is_expected.to be_instance_of(Global::Configuration) }
37
40
 
38
41
  context "when load from directory" do
39
- its("rspec_config.to_hash"){ should == {"default_value"=>"default value", "test_value"=>"test value"} }
42
+ describe '#rspec_config' do
43
+ subject { super().rspec_config }
44
+ describe '#to_hash' do
45
+ subject { super().to_hash }
46
+ it { is_expected.to eq({"default_value"=>"default value", "test_value"=>"test value"}) }
47
+ end
48
+ end
40
49
  end
41
50
 
42
51
  context "when load from file" do
43
52
  before{ described_class.config_directory = File.join(Dir.pwd, "spec/files/rspec_config") }
44
53
 
45
- its("rspec_config.to_hash"){ should == {"default_value"=>"default value", "test_value"=>"test value"} }
54
+ describe '#rspec_config' do
55
+ subject { super().rspec_config }
56
+ describe '#to_hash' do
57
+ subject { super().to_hash }
58
+ it { is_expected.to eq({"default_value"=>"default value", "test_value"=>"test value"}) }
59
+ end
60
+ end
46
61
  end
47
62
 
48
63
  context "when nested directories" do
49
- it{ subject.rspec["config"].to_hash.should == {"default_value"=>"default nested value", "test_value"=>"test nested value"} }
64
+ it{ expect(subject.rspec["config"].to_hash).to eq({"default_value"=>"default nested value", "test_value"=>"test nested value"}) }
50
65
  end
51
66
 
52
67
  context "when boolean" do
53
- it{ subject.bool_config.works.should == true }
54
- it{ subject.bool_config.works?.should == true }
68
+ it{ expect(subject.bool_config.works).to eq(true) }
69
+ it{ expect(subject.bool_config.works?).to eq(true) }
55
70
  end
56
71
  end
57
72
 
@@ -68,27 +83,34 @@ describe Global do
68
83
  described_class.reload!
69
84
  end
70
85
 
71
- it{ should be_instance_of(Global::Configuration) }
72
- its("rspec_config.to_hash"){ should == {"default_value"=>"default value", "test_value"=>"development value"} }
86
+ it{ is_expected.to be_instance_of(Global::Configuration) }
87
+
88
+ describe '#rspec_config' do
89
+ subject { super().rspec_config }
90
+ describe '#to_hash' do
91
+ subject { super().to_hash }
92
+ it { is_expected.to eq({"default_value"=>"default value", "test_value"=>"development value"}) }
93
+ end
94
+ end
73
95
  end
74
96
 
75
97
  describe ".method_missing" do
76
98
  context "when file exists" do
77
99
  subject{ described_class.rspec_config }
78
100
 
79
- it{ should be_kind_of(Global::Configuration) }
101
+ it{ is_expected.to be_kind_of(Global::Configuration) }
80
102
  end
81
103
 
82
104
  context "when file does not exist" do
83
105
  subject{ described_class.some_file }
84
106
 
85
- it{ lambda{ subject }.should raise_error(NoMethodError) }
107
+ it{ expect{ subject }.to raise_error(NoMethodError) }
86
108
  end
87
109
 
88
110
  context "when file with nested hash" do
89
111
  subject{ described_class.nested_config }
90
112
 
91
- it{ should be_kind_of(Global::Configuration) }
113
+ it{ is_expected.to be_kind_of(Global::Configuration) }
92
114
  end
93
115
 
94
116
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $:.unshift(File.dirname(__FILE__))
5
+ require 'rspec'
6
+ require 'global'
1
7
  require 'simplecov'
8
+ require 'support/javascript_helper'
2
9
 
3
10
  SimpleCov.start do
4
11
  add_filter '/spec/'
@@ -7,11 +14,10 @@ SimpleCov.start do
7
14
  end
8
15
 
9
16
  RSpec.configure do |config|
10
- require "global"
11
-
12
- config.treat_symbols_as_metadata_keys_with_true_values = true
17
+
13
18
  config.run_all_when_everything_filtered = true
14
19
  config.filter_run :focus
15
20
 
16
21
  config.order = 'random'
22
+ config.include JavascriptHelper
17
23
  end
@@ -0,0 +1,24 @@
1
+ if defined?(JRUBY_VERSION)
2
+ require 'rhino'
3
+ JS_LIB_CLASS = Rhino
4
+ else
5
+ require 'v8'
6
+ JS_LIB_CLASS = V8
7
+ end
8
+
9
+ module JavascriptHelper
10
+ def evaljs(string, force = false)
11
+ jscontext(force).eval(string)
12
+ end
13
+
14
+ private
15
+
16
+ def jscontext(force = false)
17
+ if force
18
+ @jscontext = JS_LIB_CLASS::Context.new
19
+ else
20
+ @jscontext ||= JS_LIB_CLASS::Context.new
21
+ end
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,97 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.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: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.14.1
19
+ version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.14.1
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.7.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.7.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 10.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 10.1.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: activesupport
56
+ name: therubyracer
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
69
83
  description: Simple way to load your configs from yaml
70
84
  email: contact@railsware.com
71
85
  executables: []
72
86
  extensions: []
73
87
  extra_rdoc_files: []
74
88
  files:
75
- - .gitignore
76
- - .rspec
77
- - .ruby-version
78
- - .travis.yml
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".ruby-version"
92
+ - ".travis.yml"
79
93
  - Gemfile
80
94
  - LICENSE.txt
81
95
  - README.md
82
96
  - Rakefile
97
+ - app/assets/javascripts/global-js.js.erb
83
98
  - global.gemspec
84
99
  - lib/global.rb
85
100
  - lib/global/base.rb
86
101
  - lib/global/configuration.rb
102
+ - lib/global/engine.rb
87
103
  - lib/global/version.rb
88
104
  - spec/files/bool_config.yml
89
105
  - spec/files/nested_config.yml
90
106
  - spec/files/rspec/config.yml
91
107
  - spec/files/rspec_config.yml
92
108
  - spec/global/configuration_spec.rb
109
+ - spec/global/global_js_spec.rb
93
110
  - spec/global_spec.rb
94
111
  - spec/spec_helper.rb
112
+ - spec/support/javascript_helper.rb
95
113
  homepage: https://github.com/railsware/global
96
114
  licenses:
97
115
  - MIT
@@ -102,17 +120,17 @@ require_paths:
102
120
  - lib
103
121
  required_ruby_version: !ruby/object:Gem::Requirement
104
122
  requirements:
105
- - - '>='
123
+ - - ">="
106
124
  - !ruby/object:Gem::Version
107
125
  version: '0'
108
126
  required_rubygems_version: !ruby/object:Gem::Requirement
109
127
  requirements:
110
- - - '>='
128
+ - - ">="
111
129
  - !ruby/object:Gem::Version
112
130
  version: '0'
113
131
  requirements: []
114
132
  rubyforge_project: global
115
- rubygems_version: 2.1.11
133
+ rubygems_version: 2.2.2
116
134
  signing_key:
117
135
  specification_version: 4
118
136
  summary: Simple way to load your configs from yaml
@@ -122,5 +140,7 @@ test_files:
122
140
  - spec/files/rspec/config.yml
123
141
  - spec/files/rspec_config.yml
124
142
  - spec/global/configuration_spec.rb
143
+ - spec/global/global_js_spec.rb
125
144
  - spec/global_spec.rb
126
145
  - spec/spec_helper.rb
146
+ - spec/support/javascript_helper.rb