global 0.2.2 → 1.0.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: ff7ffaa8d2e0f5e244d2a8afbe0d8e938cea9244
4
- data.tar.gz: 8153165733bd12e6c4673c39abdbb16b706a7fc6
3
+ metadata.gz: 5ada6d5fbc1aaf1b03e1e5db9200c33f2e22108e
4
+ data.tar.gz: bd7c8bc34931654e6bd89fb6d2cf6fd4c7e7d123
5
5
  SHA512:
6
- metadata.gz: efa24df45cb25c916773f4ff7c1dcc0621421016f567a54af18f77bae41a9242e9dd9a5f5bf942db4db8e133f0b17d971fed83de28fd787cf301859d035b5d61
7
- data.tar.gz: 01156ae25535c3d559da859c6717feb59c07510291e23306920e722d35bf3c8c112b789c61d633ec7dc1d019f9ee36380c9889c56b1c7a5e990a2b79930363ff
6
+ metadata.gz: 6209994c37c074286978e2b34e5d81fc0b93818fc75fb682cb0750de13ac2656926cbde9639507e3d0f9049469b9789b853d3a61bedbdfdf528849db242165f8
7
+ data.tar.gz: b5c74f586b5dd5db6c1826e355ba159ecd6e05b316071c212acf4ac3d9801a776742c5a0693b1ca1a9cdd9fa1ab69bb03be33d4d66fdd59f78b35c19498d7180
@@ -0,0 +1,91 @@
1
+ Layout/EmptyLinesAroundBlockBody:
2
+ Enabled: false
3
+
4
+ Layout/SpaceInsideBlockBraces:
5
+ Enabled: true
6
+ EnforcedStyle: space
7
+ EnforcedStyleForEmptyBraces: no_space
8
+ SpaceBeforeBlockParameters: true
9
+
10
+ Layout/SpaceBeforeBlockBraces:
11
+ Enabled: true
12
+ EnforcedStyle: space
13
+ EnforcedStyleForEmptyBraces: space
14
+
15
+ Layout/SpaceInsideHashLiteralBraces:
16
+ Enabled: true
17
+ EnforcedStyle: compact
18
+ EnforcedStyleForEmptyBraces: no_space
19
+
20
+ Layout/EmptyLinesAroundClassBody:
21
+ Enabled: true
22
+ EnforcedStyle: empty_lines_except_namespace
23
+
24
+ Layout/EmptyLinesAroundModuleBody:
25
+ Enabled: true
26
+ EnforcedStyle: empty_lines_except_namespace
27
+
28
+ Layout/MultilineMethodCallIndentation:
29
+ Enabled: true
30
+ EnforcedStyle: indented
31
+
32
+ Layout/AlignHash:
33
+ Enabled: true
34
+ EnforcedLastArgumentHashStyle: always_ignore
35
+
36
+ Style/RaiseArgs:
37
+ EnforcedStyle: compact
38
+
39
+ Style/YodaCondition:
40
+ Enabled: false
41
+
42
+ Style/FrozenStringLiteralComment:
43
+ Enabled: true
44
+ EnforcedStyle: always
45
+
46
+ Style/RegexpLiteral:
47
+ Enabled: true
48
+ EnforcedStyle: slashes
49
+ AllowInnerSlashes: false
50
+
51
+ Layout/IndentHash:
52
+ EnforcedStyle: consistent
53
+
54
+ Style/Documentation:
55
+ Enabled: false
56
+
57
+ Style/SafeNavigation:
58
+ Enabled: true
59
+ Whitelist:
60
+ - present?
61
+ - blank?
62
+ - presence
63
+
64
+ Lint/AmbiguousBlockAssociation:
65
+ Exclude:
66
+ - 'spec/**/*'
67
+
68
+ Naming/PredicateName:
69
+ Exclude:
70
+ - 'spec/**/*'
71
+
72
+ Style/NumericPredicate:
73
+ Exclude:
74
+ - 'spec/**/*'
75
+
76
+ Metrics/BlockLength:
77
+ Exclude:
78
+ - 'spec/**/*'
79
+
80
+ Metrics/LineLength:
81
+ Max: 120
82
+ Exclude:
83
+ - 'spec/**/*'
84
+
85
+ Metrics/AbcSize:
86
+ Max: 22
87
+ Exclude:
88
+ - 'spec/**/*'
89
+
90
+ Style/ModuleFunction:
91
+ EnforcedStyle: extend_self
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.1
@@ -4,12 +4,10 @@ cache:
4
4
  bundler: true
5
5
 
6
6
  rvm:
7
- - 2.0
8
- - 2.1
9
7
  - 2.2
10
- - 2.3.3
11
- - 2.4.2
12
- - 2.5.0
8
+ - 2.3
9
+ - 2.4
10
+ - 2.5
13
11
  - jruby-19mode
14
12
  - ruby-head
15
13
  - jruby-head
data/Gemfile CHANGED
@@ -1,9 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in global.gemspec
4
6
  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
data/README.md CHANGED
@@ -124,6 +124,39 @@ Nested options can then be accessed as follows:
124
124
  => "development value"
125
125
  ```
126
126
 
127
+ ### Environment files
128
+
129
+ Config file `global/aws.yml` with:
130
+ ```yml
131
+ :default:
132
+ activated: false
133
+
134
+ staging:
135
+ activated: true
136
+ api_key: 'nothing'
137
+
138
+ ```
139
+
140
+ And file `global/aws.production.yml` with:
141
+ ```yml
142
+ :activated: true
143
+ :api_key: 'some api key'
144
+ :api_secret: 'some secret'
145
+
146
+ ```
147
+
148
+ Provide such configuration on `Global.environment = 'production'` environment:
149
+
150
+ ```ruby
151
+ > Global.aws.activated
152
+ => true
153
+ > Global.aws.api_key
154
+ => 'some api key'
155
+ > Global.aws.api_secret
156
+ => 'some secret'
157
+ ```
158
+
159
+ **Warning**: files with dot(s) in name will be skipped by Global (except this env files).
127
160
 
128
161
  ### ERB support
129
162
 
@@ -162,7 +195,7 @@ Global.configure do |config|
162
195
  config.only = ["LIST_OF_FILES_TO_INCLUDE_ON_FRONT_END"] # default []
163
196
  end
164
197
  ```
165
- By default all files are excluded due to security reasons. Don't include files which contain protected information like api keys or credentials.
198
+ By default all files are excluded due to security reasons. Don't include files which contain protected information like api keys or credentials.
166
199
 
167
200
  Require global file in `application.js`:
168
201
 
@@ -184,7 +217,7 @@ If your application has `admin` and `application` namespace:
184
217
 
185
218
  # app/assets/javascripts/admin.js.coffee
186
219
  #= require admin/global
187
- ```
220
+ ```
188
221
 
189
222
  ```erb
190
223
  # app/assets/javascripts/application/global.js.erb
@@ -213,7 +246,7 @@ Global.hosts.web
213
246
  => "localhost"
214
247
  ```
215
248
 
216
- And in production:
249
+ And in production:
217
250
 
218
251
  ``` js
219
252
  Global.hosts.web
@@ -233,4 +266,3 @@ Global.hosts.web
233
266
  ## Copyright
234
267
 
235
268
  Copyright (c) Railsware LLC. See LICENSE.txt for further details.
236
-
data/Rakefile CHANGED
@@ -1,11 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
 
4
6
  Bundler.require
5
7
 
6
8
  require 'rspec/core/rake_task'
7
- require "bundler/gem_tasks"
9
+ require 'bundler/gem_tasks'
10
+ require 'rubocop/rake_task'
8
11
 
9
12
  RSpec::Core::RakeTask.new(:spec)
13
+ RuboCop::RakeTask.new(:rubocop) do |task|
14
+ task.options = ['-D'] # Display cop name
15
+ task.fail_on_error = true
16
+ end
10
17
 
11
- task :default => :spec
18
+ desc 'Run all tests'
19
+ task default: %i[rubocop spec]
@@ -1,33 +1,36 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require "global/version"
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+ require 'global/version'
3
5
 
4
6
  Gem::Specification.new do |s|
5
- s.name = "global"
7
+ s.name = 'global'
6
8
  s.version = Global::VERSION
7
- s.authors = ["Railsware LLC"]
8
- s.email = "contact@railsware.com"
9
+ s.authors = ['Railsware LLC']
10
+ s.email = 'contact@railsware.com'
9
11
 
10
- s.rubyforge_project = "global"
12
+ s.rubyforge_project = 'global'
11
13
 
12
- s.description = "Simple way to load your configs from yaml"
13
- s.summary = "Simple way to load your configs from yaml"
14
+ s.description = 'Simple way to load your configs from yaml'
15
+ s.summary = 'Simple way to load your configs from yaml'
14
16
 
15
17
  s.files = `git ls-files`.split("\n")
16
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ s.require_paths = ['lib']
19
21
 
20
- s.homepage = "https://github.com/railsware/global"
21
- s.licenses = ["MIT"]
22
+ s.homepage = 'https://github.com/railsware/global'
23
+ s.licenses = ['MIT']
22
24
 
23
- s.add_development_dependency "rspec", ">= 3.0"
24
- s.add_development_dependency "simplecov", "~> 0.7.1"
25
- s.add_development_dependency "rake", "~> 10.1.0"
25
+ s.add_development_dependency 'rake', '~> 12.3.1'
26
+ s.add_development_dependency 'rspec', '>= 3.0'
27
+ s.add_development_dependency 'rubocop', '~> 0.57'
28
+ s.add_development_dependency 'simplecov', '~> 0.16.1'
26
29
  if defined?(JRUBY_VERSION)
27
- s.add_development_dependency "therubyrhino", ">= 0"
30
+ s.add_development_dependency 'therubyrhino', '>= 0'
28
31
  else
29
- s.add_development_dependency "therubyracer", ">= 0"
32
+ s.add_development_dependency 'therubyracer', '>= 0'
30
33
  end
31
34
 
32
- s.add_runtime_dependency "activesupport", ">= 2.0"
35
+ s.add_runtime_dependency 'activesupport', '>= 2.0'
33
36
  end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'yaml'
3
4
 
4
5
  require 'active_support/core_ext/hash/indifferent_access'
@@ -10,5 +11,7 @@ require 'global/engine' if defined?(Rails)
10
11
  require 'global/version'
11
12
 
12
13
  module Global
14
+
13
15
  extend Base
16
+
14
17
  end
@@ -1,10 +1,14 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'erb'
4
4
  require 'json'
5
5
 
6
6
  module Global
7
7
  module Base
8
+
9
+ FILE_ENV_SPLIT = '.'
10
+ YAML_EXT = '.yml'
11
+
8
12
  extend self
9
13
 
10
14
  attr_writer :environment, :config_directory, :namespace, :except, :only
@@ -23,11 +27,11 @@ module Global
23
27
  end
24
28
 
25
29
  def environment
26
- @environment || raise("environment should be defined")
30
+ @environment || raise('environment should be defined')
27
31
  end
28
32
 
29
33
  def config_directory
30
- @config_directory || raise("config_directory should be defined")
34
+ @config_directory || raise('config_directory should be defined')
31
35
  end
32
36
 
33
37
  def namespace
@@ -60,34 +64,51 @@ module Global
60
64
  def load_from_file(dir, env)
61
65
  config = {}
62
66
 
63
- if File.exists?(file = "#{dir}.yml")
64
- configurations = YAML::load(ERB.new(IO.read(file)).result)
65
- config = configurations[:default] || configurations["default"] || {}
66
- config.deep_merge!(configurations[env] || {})
67
+ if File.exist?(file = "#{dir}#{YAML_EXT}")
68
+ configurations = load_yml_file(file)
69
+ config = get_config_by_key(configurations, 'default')
70
+ config.deep_merge!(get_config_by_key(configurations, env))
71
+ if File.exist?(env_file = "#{dir}#{FILE_ENV_SPLIT}#{env}#{YAML_EXT}")
72
+ config.deep_merge!(load_yml_file(env_file) || {})
73
+ end
67
74
  end
68
75
 
69
76
  config
70
77
  end
71
78
 
79
+ def get_config_by_key(config, key)
80
+ config[key.to_sym] || config[key.to_s] || {}
81
+ end
82
+
83
+ def load_yml_file(file)
84
+ YAML.safe_load(
85
+ ERB.new(IO.read(file)).result,
86
+ [Date, Time, DateTime, Symbol], [], true
87
+ )
88
+ end
89
+
72
90
  def load_from_directory(dir, env)
73
91
  config = {}
74
92
 
75
93
  if File.directory?(dir)
76
94
  Dir["#{dir}/*"].each do |entry|
77
- namespace = entry.gsub(/^#{dir}\/?/, '').gsub(/\.yml$/, '')
78
- config.deep_merge!(namespace => load_configuration(entry.gsub(/\.yml$/, ''), env))
95
+ namespace = File.basename(entry, YAML_EXT)
96
+ next if namespace.include? FILE_ENV_SPLIT # skip files with dot(s) in name
97
+ file_with_path = File.join(File.dirname(entry), File.basename(entry, YAML_EXT))
98
+ config.deep_merge!(namespace => load_configuration(file_with_path, env))
79
99
  end
80
100
  end
81
101
 
82
102
  config
83
103
  end
84
-
85
- def respond_to_missing?(method, include_private=false)
104
+
105
+ def respond_to_missing?(method, include_private = false)
86
106
  configuration.key?(method) || super
87
107
  end
88
108
 
89
109
  def method_missing(method, *args, &block)
90
110
  configuration.key?(method) ? configuration[method] : super
91
111
  end
112
+
92
113
  end
93
114
  end
@@ -1,15 +1,17 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
4
 
5
5
  module Global
6
6
  class Configuration
7
+
7
8
  extend Forwardable
8
9
 
9
10
  attr_reader :hash
10
11
 
11
- def_delegators :hash, :key?, :has_key?, :include?, :member?, :[], :[]=, :to_hash, :to_json, :inspect
12
-
12
+ def_delegators :hash, :key?, :has_key?, :include?,
13
+ :member?, :[], :[]=, :to_hash, :to_json,
14
+ :inspect, :fetch
13
15
 
14
16
  def initialize(hash)
15
17
  @hash = hash.respond_to?(:with_indifferent_access) ? hash.with_indifferent_access : hash
@@ -17,28 +19,23 @@ module Global
17
19
 
18
20
  def filter(options = {})
19
21
  keys = filtered_keys_list(options)
20
- hash.select{|key, _| keys.include?(key)}
22
+ hash.select { |key, _| keys.include?(key) }
21
23
  end
22
24
 
23
25
  private
24
26
 
25
27
  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
28
+ return hash.keys - options[:except].map(&:to_s) if options[:except].is_a?(Array)
29
+ return hash.keys & options[:only].map(&:to_s) if options[:only].is_a?(Array)
33
30
 
34
31
  return hash.keys if options[:only] == :all
35
32
  return [] if options[:except] == :all
36
- return []
33
+ []
37
34
  end
38
35
 
39
36
  protected
40
37
 
41
- def respond_to_missing?(method_name, include_private=false)
38
+ def respond_to_missing?(method_name, include_private = false)
42
39
  method = normalize_key_by_method(method_name)
43
40
  key?(method) || super
44
41
  end
@@ -47,7 +44,7 @@ module Global
47
44
  method = normalize_key_by_method(method)
48
45
  if key?(method)
49
46
  value = hash[method]
50
- value.kind_of?(Hash) ? Global::Configuration.new(value) : value
47
+ value.is_a?(Hash) ? Global::Configuration.new(value) : value
51
48
  else
52
49
  super
53
50
  end
@@ -57,6 +54,5 @@ module Global
57
54
  '?' == method.to_s[-1] ? method.to_s[0..-2] : method
58
55
  end
59
56
 
60
-
61
57
  end
62
58
  end
@@ -1,21 +1,24 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Global
4
+
3
5
  class SprocketsExtension
6
+
4
7
  GLOBAL_JS_ASSET = 'global-js'
5
8
 
6
- def initialize(filename, &block)
9
+ def initialize(filename)
7
10
  @filename = filename
8
- @source = block.call
11
+ @source = yield
9
12
  end
10
13
 
11
- def render(context, empty_hash_wtf)
14
+ def render(context, _empty_hash_wtf)
12
15
  self.class.run(@filename, @source, context)
13
16
  end
14
17
 
15
- def self.run(filename, source, context)
18
+ def self.run(_filename, source, context)
16
19
  if GLOBAL_JS_ASSET == context.logical_path
17
20
  configs = Dir.glob("#{Global.config_directory}#{File::SEPARATOR}*.yml")
18
- configs.map{ |config| context.depend_on(config) }
21
+ configs.map { |config| context.depend_on(config) }
19
22
  end
20
23
  source
21
24
  end
@@ -28,51 +31,54 @@ module Global
28
31
  result = run(filename, source, context)
29
32
  context.metadata.merge(data: result)
30
33
  end
31
- end
32
34
 
35
+ end
33
36
 
34
37
  class Engine < ::Rails::Engine
38
+
35
39
  require 'sprockets/version'
36
40
  v2 = Gem::Dependency.new('', ' ~> 2')
37
41
  vgte3 = Gem::Dependency.new('', ' >= 3')
38
42
  sprockets_version = Gem::Version.new(::Sprockets::VERSION).release
39
43
  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"
44
+ when ->(v) { v2.match?('', v) }
45
+ { after: 'sprockets.environment' }
46
+ when ->(v) { vgte3.match?('', v) }
47
+ { after: :engines_blank_point, before: :finisher_hook }
48
+ else
49
+ raise StandardError.new("Sprockets version #{sprockets_version} is not supported")
46
50
  end
47
51
 
48
52
  is_running_rails = defined?(Rails) && Rails.respond_to?(:version)
49
- is_running_rails_32 = is_running_rails && Rails.version.match(/3\.2/)
53
+ is_running_rails32 = is_running_rails && Rails.version.match(/3\.2/)
50
54
 
51
55
  initializer 'global-js.dependent_on_configs', initializer_args do
52
56
  case sprockets_version
53
- when -> (v) { v2.match?('', v) },
54
- -> (v) { vgte3.match?('', v) }
57
+ when ->(v) { v2.match?('', v) },
58
+ ->(v) { vgte3.match?('', v) }
55
59
 
56
60
  # It seems rails 3.2 is not working if
57
61
  # `Rails.application.config.assets.configure` is used for
58
62
  # registering preprocessor
59
- if is_running_rails_32
63
+ if is_running_rails32
60
64
  Rails.application.assets.register_preprocessor(
61
- "application/javascript",
65
+ 'application/javascript',
62
66
  SprocketsExtension
63
67
  )
64
68
  elsif Rails.application.config.respond_to?(:assets)
65
69
  # Other rails version, assumed newer
66
70
  Rails.application.config.assets.configure do |config|
67
71
  config.register_preprocessor(
68
- "application/javascript",
72
+ 'application/javascript',
69
73
  SprocketsExtension
70
74
  )
71
75
  end
72
76
  end
73
77
  else
74
- raise StandardError, "Sprockets version #{sprockets_version} is not supported"
78
+ raise StandardError.new("Sprockets version #{sprockets_version} is not supported")
75
79
  end
76
80
  end
81
+
77
82
  end
83
+
78
84
  end
@@ -1,5 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Global
4
- VERSION = "0.2.2"
4
+
5
+ VERSION = '1.0.0'
6
+
5
7
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ :api_key: 'some api key'
3
+ :api_secret: 'some secret'
@@ -0,0 +1,6 @@
1
+ :default:
2
+ activated: false
3
+
4
+ test:
5
+ activated: true
6
+ api_key: 'nothing'
@@ -1,149 +1,151 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  RSpec.describe Global::Configuration do
4
- let(:hash){ { "key" => "value", "nested" => { "key" => "value" } } }
5
- let(:configuration){ described_class.new hash }
6
+ let(:hash) { { 'key' => 'value', 'nested' => { 'key' => 'value' }} }
7
+ let(:configuration) { described_class.new hash }
6
8
 
7
- describe "#hash" do
8
- subject{ configuration.hash }
9
+ describe '#hash' do
10
+ subject { configuration.hash }
9
11
 
10
- it{ is_expected.to eq(hash) }
12
+ it { is_expected.to eq(hash) }
11
13
  end
12
14
 
13
- describe "#to_hash" do
14
- subject{ configuration.to_hash }
15
+ describe '#to_hash' do
16
+ subject { configuration.to_hash }
15
17
 
16
- it{ is_expected.to eq(hash) }
18
+ it { is_expected.to eq(hash) }
17
19
  end
18
20
 
19
- describe "key?" do
20
- subject{ configuration.key?(:key) }
21
+ describe 'key?' do
22
+ subject { configuration.key?(:key) }
21
23
 
22
- it{ is_expected.to be_truthy }
24
+ it { is_expected.to be_truthy }
23
25
  end
24
26
 
25
- describe "has_key?" do
26
- subject{ configuration.has_key?(:key) }
27
+ describe 'has_key?' do
28
+ subject { configuration.key?(:key) }
27
29
 
28
- it{ is_expected.to be_truthy }
30
+ it { is_expected.to be_truthy }
29
31
  end
30
32
 
31
- describe "include?" do
32
- subject{ configuration.include?(:key) }
33
+ describe 'include?' do
34
+ subject { configuration.include?(:key) }
33
35
 
34
- it{ is_expected.to be_truthy }
36
+ it { is_expected.to be_truthy }
35
37
  end
36
38
 
37
- describe "member?" do
38
- subject{ configuration.member?(:key) }
39
+ describe 'member?' do
40
+ subject { configuration.member?(:key) }
39
41
 
40
- it{ is_expected.to be_truthy }
42
+ it { is_expected.to be_truthy }
41
43
  end
42
44
 
43
- describe "#[]" do
44
- subject{ configuration[:key] }
45
+ describe '#[]' do
46
+ subject { configuration[:key] }
45
47
 
46
- it{ is_expected.to eq("value") }
48
+ it { is_expected.to eq('value') }
47
49
  end
48
50
 
49
- describe "#[]=" do
50
- subject{ configuration[:new_key] }
51
+ describe '#[]=' do
52
+ subject { configuration[:new_key] }
51
53
 
52
- before{ configuration[:new_key] = "new_value" }
54
+ before { configuration[:new_key] = 'new_value' }
53
55
 
54
- it{ is_expected.to eq("new_value") }
56
+ it { is_expected.to eq('new_value') }
55
57
  end
56
58
 
57
- describe "#inspect" do
58
- subject{ configuration.inspect }
59
+ describe '#inspect' do
60
+ subject { configuration.inspect }
59
61
 
60
- it{ is_expected.to eq(hash.inspect) }
62
+ it { is_expected.to eq(hash.inspect) }
61
63
  end
62
64
 
63
- describe "#filter" do
64
- subject{ configuration.filter(filter_options) }
65
+ describe '#filter' do
66
+ subject { configuration.filter(filter_options) }
65
67
 
66
- context "when include all" do
67
- let(:filter_options){ { only: :all } }
68
+ context 'when include all' do
69
+ let(:filter_options) { { only: :all } }
68
70
 
69
- it{ should == {"key"=>"value", "nested"=>{"key"=>"value"}} }
71
+ it { should == { 'key' => 'value', 'nested' => { 'key' => 'value' }} }
70
72
  end
71
73
 
72
- context "when except all" do
73
- let(:filter_options){ { except: :all } }
74
+ context 'when except all' do
75
+ let(:filter_options) { { except: :all } }
74
76
 
75
- it{ should == {} }
77
+ it { should == {} }
76
78
  end
77
79
 
78
- context "when except present" do
79
- let(:filter_options){ { except: %w(key) } }
80
+ context 'when except present' do
81
+ let(:filter_options) { { except: %w[key] } }
80
82
 
81
- it{ should == {"nested"=>{"key"=>"value"}} }
83
+ it { should == { 'nested' => { 'key' => 'value' }} }
82
84
  end
83
85
 
84
- context "when include present" do
85
- let(:filter_options){ { only: %w(key) } }
86
+ context 'when include present' do
87
+ let(:filter_options) { { only: %w[key] } }
86
88
 
87
- it{ should == {"key"=>"value"} }
89
+ it { should == { 'key' => 'value' } }
88
90
  end
89
91
 
90
- context "when empty options" do
91
- let(:filter_options){ {} }
92
+ context 'when empty options' do
93
+ let(:filter_options) { {} }
92
94
 
93
- it{ should == {} }
95
+ it { should == {} }
94
96
  end
95
97
  end
96
98
 
97
- describe "#method_missing" do
98
- context "when key exist" do
99
- subject{ configuration.key }
99
+ describe '#method_missing' do
100
+ context 'when key exist' do
101
+ subject { configuration.key }
100
102
 
101
- it{ is_expected.to eq("value") }
103
+ it { is_expected.to eq('value') }
102
104
  end
103
105
 
104
- context "when key does not exist" do
105
- subject{ configuration.some_key }
106
+ context 'when key does not exist' do
107
+ subject { configuration.some_key }
106
108
 
107
- it{ expect { subject }.to raise_error(NoMethodError) }
109
+ it { expect { subject }.to raise_error(NoMethodError) }
108
110
  end
109
111
 
110
- context "with nested hash" do
111
- subject{ configuration.nested.key }
112
+ context 'with nested hash' do
113
+ subject { configuration.nested.key }
112
114
 
113
- it{ is_expected.to eq("value") }
115
+ it { is_expected.to eq('value') }
114
116
  end
115
117
  end
116
118
 
117
- describe "#respond_to_missing?" do
118
- context "when key exist" do
119
- subject{ configuration.respond_to?(:key) }
119
+ describe '#respond_to_missing?' do
120
+ context 'when key exist' do
121
+ subject { configuration.respond_to?(:key) }
120
122
 
121
- it{ is_expected.to eq(true) }
123
+ it { is_expected.to eq(true) }
122
124
  end
123
125
 
124
- context "when key does not exist" do
125
- subject{ configuration.respond_to?(:some_key) }
126
+ context 'when key does not exist' do
127
+ subject { configuration.respond_to?(:some_key) }
126
128
 
127
- it{ is_expected.to eq(false) }
129
+ it { is_expected.to eq(false) }
128
130
  end
129
131
 
130
- context "with nested hash" do
131
- subject{ configuration.nested.respond_to?(:key) }
132
+ context 'with nested hash' do
133
+ subject { configuration.nested.respond_to?(:key) }
132
134
 
133
- it{ is_expected.to eq(true) }
135
+ it { is_expected.to eq(true) }
134
136
  end
135
137
 
136
- context "when call it by method" do
137
- subject{ configuration.method(:key).call }
138
+ context 'when call it by method' do
139
+ subject { configuration.method(:key).call }
138
140
 
139
- it{ is_expected.to eq("value") }
141
+ it { is_expected.to eq('value') }
140
142
  end
141
143
 
142
- context "when call it by method, which not exist" do
144
+ context 'when call it by method, which not exist' do
143
145
  it 'raise error' do
144
- expect{ configuration.method(:some_key) }.to raise_error(NameError)
146
+ expect { configuration.method(:some_key) }.to raise_error(NameError)
145
147
  end
146
148
  end
147
149
  end
148
150
 
149
- end
151
+ end
@@ -1,13 +1,15 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- RSpec.describe Global, "generate js in Rails" do
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Global, 'generate js in Rails' do
4
6
  before do
5
- evaljs("var window = this;", true)
6
- jscontext[:log] = lambda {|context, value| puts value.inspect}
7
+ evaljs('var window = this;', true)
8
+ jscontext[:log] = ->(_context, value) { puts value.inspect }
7
9
 
8
10
  described_class.configure do |config|
9
- config.environment = "test"
10
- config.config_directory = File.join(Dir.pwd, "spec/files")
11
+ config.environment = 'test'
12
+ config.config_directory = File.join(Dir.pwd, 'spec/files')
11
13
  end
12
14
 
13
15
  end
@@ -22,20 +24,20 @@ RSpec.describe Global, "generate js in Rails" do
22
24
  evaljs(described_class.generate_js)
23
25
  end
24
26
 
25
- it "should generate valid global config" do
26
- expect(evaljs("Global.rspec_config.default_value")).to eq('default value')
27
+ it 'should generate valid global config' do
28
+ expect(evaljs('Global.rspec_config.default_value')).to eq('default value')
27
29
  end
28
30
 
29
- it "should generate valid global config for array" do
30
- expect(evaljs("Global.nested_config.some_array_value.length")).to eq(3)
31
+ it 'should generate valid global config for array' do
32
+ expect(evaljs('Global.nested_config.some_array_value.length')).to eq(3)
31
33
  end
32
34
 
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
+ it 'should generate valid global config for array, first element' do
36
+ expect(evaljs('Global.nested_config.some_array_value[0]')).to eq('First')
35
37
  end
36
38
 
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
+ it 'should generate valid global config for array, last element' do
40
+ expect(evaljs('Global.nested_config.some_array_value[2]')).to eq('Third')
39
41
  end
40
42
 
41
43
  end
@@ -50,8 +52,8 @@ RSpec.describe Global, "generate js in Rails" do
50
52
  evaljs(described_class.generate_js)
51
53
  end
52
54
 
53
- it "should generate valid global config" do
54
- expect(evaljs("CustomGlobal.rspec_config.default_value")).to eq('default value')
55
+ it 'should generate valid global config' do
56
+ expect(evaljs('CustomGlobal.rspec_config.default_value')).to eq('default value')
55
57
  end
56
58
 
57
59
  end
@@ -61,8 +63,8 @@ RSpec.describe Global, "generate js in Rails" do
61
63
  evaljs(described_class.generate_js(namespace: 'CustomGlobalNamespace', only: :all))
62
64
  end
63
65
 
64
- it "should generate valid global config" do
65
- expect(evaljs("CustomGlobalNamespace.rspec_config.default_value")).to eq('default value')
66
+ it 'should generate valid global config' do
67
+ expect(evaljs('CustomGlobalNamespace.rspec_config.default_value')).to eq('default value')
66
68
  end
67
69
 
68
70
  end
@@ -78,12 +80,12 @@ RSpec.describe Global, "generate js in Rails" do
78
80
  evaljs(described_class.generate_js)
79
81
  end
80
82
 
81
- it "should generate visible global config" do
82
- expect(evaljs("Global.bool_config.works")).to eq(true)
83
+ it 'should generate visible global config' do
84
+ expect(evaljs('Global.bool_config.works')).to eq(true)
83
85
  end
84
86
 
85
- it "should have not some keys in js" do
86
- expect(evaljs("Global.nested_config")).to be_nil
87
+ it 'should have not some keys in js' do
88
+ expect(evaljs('Global.nested_config')).to be_nil
87
89
  end
88
90
 
89
91
  end
@@ -98,16 +100,16 @@ RSpec.describe Global, "generate js in Rails" do
98
100
  evaljs(described_class.generate_js)
99
101
  end
100
102
 
101
- it "should generate visible global config with bool_config" do
102
- expect(evaljs("Global.bool_config.works")).to eq(true)
103
+ it 'should generate visible global config with bool_config' do
104
+ expect(evaljs('Global.bool_config.works')).to eq(true)
103
105
  end
104
106
 
105
- it "should generate visible global config with rspec_config" do
106
- expect(evaljs("Global.rspec_config.default_value")).to eq('default value')
107
+ it 'should generate visible global config with rspec_config' do
108
+ expect(evaljs('Global.rspec_config.default_value')).to eq('default value')
107
109
  end
108
110
 
109
- it "should have not some keys in js" do
110
- expect(evaljs("Global.nested_config")).to be_nil
111
+ it 'should have not some keys in js' do
112
+ expect(evaljs('Global.nested_config')).to be_nil
111
113
  end
112
114
 
113
115
  end
@@ -1,130 +1,143 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  RSpec.describe Global do
4
6
 
5
7
  before(:each) do
6
8
  described_class.configure do |config|
7
- config.environment = "test"
8
- config.config_directory = File.join(Dir.pwd, "spec/files")
9
+ config.environment = 'test'
10
+ config.config_directory = File.join(Dir.pwd, 'spec/files')
9
11
  end
10
12
  end
11
13
 
12
- describe ".environment" do
13
- subject{ described_class.environment }
14
+ describe '.environment' do
15
+ subject { described_class.environment }
14
16
 
15
- it{ is_expected.to eq("test") }
17
+ it { is_expected.to eq('test') }
16
18
 
17
- context "when undefined" do
18
- before{ described_class.environment = nil }
19
+ context 'when undefined' do
20
+ before { described_class.environment = nil }
19
21
 
20
- it{ expect{ subject }.to raise_error("environment should be defined") }
22
+ it { expect { subject }.to raise_error('environment should be defined') }
21
23
  end
22
24
  end
23
25
 
24
- describe ".config_directory" do
25
- subject{ described_class.config_directory }
26
+ describe '.config_directory' do
27
+ subject { described_class.config_directory }
26
28
 
27
- it{ is_expected.to eq(File.join(Dir.pwd, "spec/files"))}
29
+ it { is_expected.to eq(File.join(Dir.pwd, 'spec/files')) }
28
30
 
29
- context "when undefined" do
30
- before{ described_class.config_directory = nil }
31
+ context 'when undefined' do
32
+ before { described_class.config_directory = nil }
31
33
 
32
- it{ expect{ subject }.to raise_error("config_directory should be defined") }
34
+ it { expect { subject }.to raise_error('config_directory should be defined') }
33
35
  end
34
36
  end
35
37
 
36
- describe ".configuration" do
37
- subject{ described_class.configuration }
38
+ describe '.configuration' do
39
+ subject { described_class.configuration }
38
40
 
39
- it{ is_expected.to be_instance_of(Global::Configuration) }
41
+ it { is_expected.to be_instance_of(Global::Configuration) }
40
42
 
41
- context "when load from directory" do
43
+ context 'when load from directory' do
42
44
  describe '#rspec_config' do
43
45
  subject { super().rspec_config }
44
46
  describe '#to_hash' do
45
47
  subject { super().to_hash }
46
- it { is_expected.to eq({"default_value"=>"default value", "test_value"=>"test value"}) }
48
+ it { is_expected.to eq('default_value' => 'default value', 'test_value' => 'test value') }
47
49
  end
48
50
  end
49
51
  end
50
52
 
51
- context "when load from file" do
52
- before{ described_class.config_directory = File.join(Dir.pwd, "spec/files/rspec_config") }
53
+ context 'when load from file' do
54
+ before { described_class.config_directory = File.join(Dir.pwd, 'spec/files/rspec_config') }
53
55
 
54
56
  describe '#rspec_config' do
55
57
  subject { super().rspec_config }
56
58
  describe '#to_hash' do
57
59
  subject { super().to_hash }
58
- it { is_expected.to eq({"default_value"=>"default value", "test_value"=>"test value"}) }
60
+ it { is_expected.to eq('default_value' => 'default value', 'test_value' => 'test value') }
59
61
  end
60
62
  end
61
63
  end
62
64
 
63
- context "when nested directories" do
64
- it{ expect(subject.rspec["config"].to_hash).to eq({"default_value"=>"default nested value", "test_value"=>"test nested value"}) }
65
+ context 'when nested directories' do
66
+ it { expect(subject.rspec['config'].to_hash).to eq('default_value' => 'default nested value', 'test_value' => 'test nested value') }
67
+ end
68
+
69
+ context 'when boolean' do
70
+ it { expect(subject.bool_config.works).to eq(true) }
71
+ it { expect(subject.bool_config.works?).to eq(true) }
65
72
  end
66
73
 
67
- context "when boolean" do
68
- it{ expect(subject.bool_config.works).to eq(true) }
69
- it{ expect(subject.bool_config.works?).to eq(true) }
74
+ context 'environment file' do
75
+ it { expect(subject.aws.activated).to eq(true) }
76
+ it { expect(subject.aws.api_key).to eq('some api key') }
77
+ it { expect(subject.aws.api_secret).to eq('some secret') }
78
+ end
79
+
80
+ context 'skip files with dots in name' do
81
+ it { expect(subject['aws.test']).to eq(nil) }
82
+ it { expect { subject.fetch('aws.test') }.to raise_error(KeyError, /key not found/) }
70
83
  end
71
84
  end
72
85
 
73
- context ".reload!" do
74
- subject{ described_class.reload! }
86
+ context '.reload!' do
87
+ subject { described_class.reload! }
75
88
 
76
89
  before do
77
90
  described_class.configuration
78
- described_class.environment = "development"
91
+ described_class.environment = 'development'
79
92
  end
80
93
 
81
94
  after do
82
- described_class.environment = "test"
95
+ described_class.environment = 'test'
83
96
  described_class.reload!
84
97
  end
85
98
 
86
- it{ is_expected.to be_instance_of(Global::Configuration) }
99
+ it { is_expected.to be_instance_of(Global::Configuration) }
87
100
 
88
101
  describe '#rspec_config' do
89
102
  subject { super().rspec_config }
90
103
  describe '#to_hash' do
91
104
  subject { super().to_hash }
92
- it { is_expected.to eq({"default_value"=>"default value", "test_value"=>"development value"}) }
105
+ it { is_expected.to eq('default_value' => 'default value', 'test_value' => 'development value') }
93
106
  end
94
107
  end
95
108
  end
96
-
97
- describe ".respond_to_missing?" do
98
- context "when file exists" do
99
- subject{ described_class.respond_to?(:rspec_config) }
100
109
 
101
- it{ is_expected.to be_truthy }
110
+ describe '.respond_to_missing?' do
111
+ context 'when file exists' do
112
+ subject { described_class.respond_to?(:rspec_config) }
113
+
114
+ it { is_expected.to be_truthy }
102
115
  end
103
116
 
104
- context "when file does not exist" do
105
- subject{ described_class.respond_to?(:some_file) }
117
+ context 'when file does not exist' do
118
+ subject { described_class.respond_to?(:some_file) }
106
119
 
107
- it{ is_expected.to be_falsey }
120
+ it { is_expected.to be_falsey }
108
121
  end
109
122
  end
110
123
 
111
- describe ".method_missing" do
112
- context "when file exists" do
113
- subject{ described_class.rspec_config }
124
+ describe '.method_missing' do
125
+ context 'when file exists' do
126
+ subject { described_class.rspec_config }
114
127
 
115
- it{ is_expected.to be_kind_of(Global::Configuration) }
128
+ it { is_expected.to be_kind_of(Global::Configuration) }
116
129
  end
117
130
 
118
- context "when file does not exist" do
119
- subject{ described_class.some_file }
131
+ context 'when file does not exist' do
132
+ subject { described_class.some_file }
120
133
 
121
- it{ expect{ subject }.to raise_error(NoMethodError) }
134
+ it { expect { subject }.to raise_error(NoMethodError) }
122
135
  end
123
136
 
124
- context "when file with nested hash" do
125
- subject{ described_class.nested_config }
137
+ context 'when file with nested hash' do
138
+ subject { described_class.nested_config }
126
139
 
127
- it{ is_expected.to be_kind_of(Global::Configuration) }
140
+ it { is_expected.to be_kind_of(Global::Configuration) }
128
141
  end
129
142
 
130
143
  end
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $:.unshift(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
  require 'rspec'
6
6
  require 'global'
7
7
  require 'simplecov'
@@ -40,4 +40,4 @@ RSpec.configure do |config|
40
40
 
41
41
  config.order = 'random'
42
42
  config.include JavascriptHelper
43
- end
43
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(JRUBY_VERSION)
2
4
  require 'rhino'
3
5
  JS_LIB_CLASS = Rhino
@@ -7,6 +9,7 @@ else
7
9
  end
8
10
 
9
11
  module JavascriptHelper
12
+
10
13
  def evaljs(string, force = false)
11
14
  jscontext(force).eval(string)
12
15
  end
@@ -21,4 +24,4 @@ module JavascriptHelper
21
24
  end
22
25
  end
23
26
 
24
- end
27
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.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: 2018-04-26 00:00:00.000000000 Z
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 12.3.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 12.3.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,33 +39,33 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: simplecov
42
+ name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 0.7.1
47
+ version: '0.57'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 0.7.1
54
+ version: '0.57'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rake
56
+ name: simplecov
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 10.1.0
61
+ version: 0.16.1
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 10.1.0
68
+ version: 0.16.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: therubyracer
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +102,7 @@ extra_rdoc_files: []
88
102
  files:
89
103
  - ".gitignore"
90
104
  - ".rspec"
105
+ - ".rubocop.yml"
91
106
  - ".ruby-version"
92
107
  - ".travis.yml"
93
108
  - Gemfile
@@ -101,6 +116,8 @@ files:
101
116
  - lib/global/configuration.rb
102
117
  - lib/global/engine.rb
103
118
  - lib/global/version.rb
119
+ - spec/files/aws.test.yml
120
+ - spec/files/aws.yml
104
121
  - spec/files/bool_config.yml
105
122
  - spec/files/nested_config.yml
106
123
  - spec/files/rspec/config.yml
@@ -135,6 +152,8 @@ signing_key:
135
152
  specification_version: 4
136
153
  summary: Simple way to load your configs from yaml
137
154
  test_files:
155
+ - spec/files/aws.test.yml
156
+ - spec/files/aws.yml
138
157
  - spec/files/bool_config.yml
139
158
  - spec/files/nested_config.yml
140
159
  - spec/files/rspec/config.yml