scripter 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: 3c66bf719d7e14053871e12fbc8c827863094f1b
4
- data.tar.gz: a5754f961a63a731ac262c8f6af29b1c9b0c48da
3
+ metadata.gz: 9f0201170065926cb11040f1672c0efbe407b2c7
4
+ data.tar.gz: 3f625a1617a9645881f365107f79cda2c4e836b0
5
5
  SHA512:
6
- metadata.gz: cf09a1d44d70d1871f209f58b38ba12fba38a30da1eefe983f346df966e2d2093a24b26ecd69c8478aee21c63f7fa34ef383ef4510340489c3f0eb13b0c620cc
7
- data.tar.gz: 9f161a11fc0033c6b93295a8804f6c5823a04739b6a5db4f6e3e27526447078cee7066ec6273aca5cbab05083d22bbc72246e5abf7ae5e9f8ddd7f57eeb3416e
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[:#{env_variable}]
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
- Hash[command_line_arguments.select{|arg| arg.include?('=')}.map{|arg| arg.split("=")}]
23
- end
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, type_cast_env_variable(nomalized_key, value)]
29
+ [nomalized_key, value]
30
30
  end
31
- Hash[env_variables]
31
+ Hash[raw_env_variables]
32
32
  end
33
33
  end
34
34
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Scripter
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -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(:env_variables)
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(:env_variables).and_return({test_variable: 'something'})
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 "#raw_env_variables should return only variables" do
41
- expect(@it.raw_env_variables).to eq({'RAILS_ENV'=>'test', 'COUNTRIES'=>'LV,EE,FI', 'use_cache'=>'1'})
42
- end
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.3
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-10-24 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler