scripter 0.0.3 → 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 +4 -4
- data/lib/scripter/env_variables.rb +9 -9
- data/lib/scripter/version.rb +1 -1
- data/spec/scripter/base_spec.rb +1 -1
- data/spec/scripter/env_variables_spec.rb +8 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f0201170065926cb11040f1672c0efbe407b2c7
|
4
|
+
data.tar.gz: 3f625a1617a9645881f365107f79cda2c4e836b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 191a420aa3f1f066400e832ae9eea617e304579bdf740e48557fc196ed2689a39c65e31d48b19f6357c226e24a696943570a0aac28cd5c4ea16dfbd64d00c80c
|
7
|
+
data.tar.gz: d3929b681c41148813611e828cb2ef3632b2ed31cb154e69d54c3e3925cbbdbb6d3b7ff3b733240589ea353a260e9de4adaf3cd5ac7d93629caab28d0ff6de40
|
@@ -11,7 +11,10 @@ module Scripter
|
|
11
11
|
variables.each do |env_variable|
|
12
12
|
class_eval %{
|
13
13
|
def #{env_variable}
|
14
|
-
env_variables
|
14
|
+
@env_variables ||= {}
|
15
|
+
@env_variables.fetch(:#{env_variable}) do
|
16
|
+
@env_variables[:#{env_variable}] = type_cast_env_variable(:#{env_variable}, raw_env_variables[:#{env_variable}])
|
17
|
+
end
|
15
18
|
end
|
16
19
|
}
|
17
20
|
end
|
@@ -19,16 +22,13 @@ module Scripter
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def raw_env_variables
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def env_variables
|
26
|
-
@env_variables ||= begin
|
27
|
-
env_variables = raw_env_variables.map do |key, value|
|
25
|
+
@raw_env_variables ||= begin
|
26
|
+
raw_env_variables = command_line_arguments.select{|arg| arg.include?('=')}.map do |arg|
|
27
|
+
key, value = arg.split("=")
|
28
28
|
nomalized_key = key.downcase.to_sym
|
29
|
-
[nomalized_key,
|
29
|
+
[nomalized_key, value]
|
30
30
|
end
|
31
|
-
Hash[
|
31
|
+
Hash[raw_env_variables]
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
data/lib/scripter/version.rb
CHANGED
data/spec/scripter/base_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe Scripter::Base do
|
|
27
27
|
it "should have Errors, Logger, EnvVariables and IterationHistory modules included" do
|
28
28
|
expect(subject).to respond_to(:add_error)
|
29
29
|
expect(subject).to respond_to(:log)
|
30
|
-
expect(subject).to respond_to(:
|
30
|
+
expect(subject).to respond_to(:type_cast_env_variable)
|
31
31
|
expect(subject).to respond_to(:cache_store)
|
32
32
|
end
|
33
33
|
|
@@ -3,11 +3,14 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
class Scripter::EnvVariablesTestable
|
5
5
|
include Scripter::EnvVariables
|
6
|
+
env_variables :rails_env, :countries, :use_cache, :report_date
|
6
7
|
|
7
8
|
# custom type casts test
|
8
9
|
def type_cast_env_variable(name, value)
|
9
10
|
if name == :countries
|
10
11
|
value.split(/\s*,\s*/)
|
12
|
+
elsif name == :report_date
|
13
|
+
value.nil? ? Date.today : value
|
11
14
|
else
|
12
15
|
super
|
13
16
|
end
|
@@ -27,7 +30,7 @@ describe Scripter::EnvVariables do
|
|
27
30
|
it "should be able to add new Environment variable getters" do
|
28
31
|
expect(@it.respond_to?(:test_variable)).to be false
|
29
32
|
@it.class.send :env_variables, :test_variable
|
30
|
-
expect(@it).to receive(:
|
33
|
+
expect(@it).to receive(:raw_env_variables).and_return({test_variable: 'something'})
|
31
34
|
expect(@it.test_variable).to eq 'something'
|
32
35
|
end
|
33
36
|
end
|
@@ -37,13 +40,11 @@ describe Scripter::EnvVariables do
|
|
37
40
|
expect(@it).to receive(:command_line_arguments).and_return(['notifications', 'RAILS_ENV=test', 'COUNTRIES=LV,EE,FI', 'use_cache=1'])
|
38
41
|
end
|
39
42
|
|
40
|
-
it
|
41
|
-
|
42
|
-
|
43
|
+
it { expect(@it.rails_env).to eq 'test' }
|
44
|
+
it { expect(@it.countries).to eq ['LV', 'EE', 'FI'] }
|
45
|
+
it { expect(@it.use_cache).to eq true }
|
46
|
+
it { expect(@it.report_date).to eq Date.today }
|
43
47
|
|
44
|
-
it "#env_variables should return normalized type casted variables" do
|
45
|
-
expect(@it.env_variables).to eq({rails_env: 'test', countries: ['LV', 'EE', 'FI'], use_cache: true})
|
46
|
-
end
|
47
48
|
end
|
48
49
|
|
49
50
|
describe "#type_cast_env_variable" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scripter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artūrs Mekšs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|