me 1.0.0 → 1.0.1

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: 304856b9ef39cde35ad5b81e881b5e6b0a96bd0c
4
- data.tar.gz: b9905fe65fefbe6454414c6870a547b01a1185a6
3
+ metadata.gz: 898af76edd87becf6ff12a8e0e55eaa58f0fa989
4
+ data.tar.gz: 0ee4f2ef8512bb40af859f12483e910a694f11e3
5
5
  SHA512:
6
- metadata.gz: eebb9092782e75ff680c6f3c8cf9e0f4129ba134922b30cf4b6caa32afcfcdc09a04c1dc2d12b9e0a032cf21343f01f1c5fcb3eb8f8b2e8dc9b4f5f028f7f4fe
7
- data.tar.gz: 9090e74963e7d8f783847419cba4f9b355da5dc1be7f42513edb38dbfa4e6f61b20492ab07dca6f66f5108abcf42bb8aaf596a04d7eb88f293ad4a4ff0ccf4b3
6
+ metadata.gz: bb03aa34cb50bc149e8ea424d5ccbac528a55938699d479863eabec6c3dab7b66c078f069e775a7bbe484fa688ca80a0237ba92173859943c59ccb2ca1edc5db
7
+ data.tar.gz: f43288ae071d933cd9a0b36ad99fa7671d5b1b0063712866308259ef2fcd7652e888b1f42874f2e67ac660e0290314a817f72202e2bd57853db6607fbe11fdf0
@@ -1,6 +1,7 @@
1
1
  require "thor"
2
2
 
3
3
  # common
4
+ require "me/store"
4
5
  require "me/registry"
5
6
  require "me/executor"
6
7
  require "me/errors"
@@ -1,6 +1,5 @@
1
1
  require "me/thread_scope"
2
2
  require "me/git_config"
3
- require "me/store2"
4
3
 
5
4
  module Me
6
5
  # Represents certain person, or person in certain role or situation
@@ -1,4 +1,3 @@
1
- require "me/store2"
2
1
  require "me/git_config"
3
2
  require "me/errors"
4
3
 
@@ -39,15 +38,15 @@ module Me
39
38
  end
40
39
 
41
40
  def fetch_name
42
- scoped.get("name")
41
+ scoped.fetch("name") { nil }
43
42
  end
44
43
 
45
44
  def fetch_email
46
- scoped.get("email")
45
+ scoped.fetch("email") { nil }
47
46
  end
48
47
 
49
48
  def store
50
- @_store ||= Store2.build
49
+ @_store ||= Store.build
51
50
  end
52
51
 
53
52
  def scoped
@@ -1,5 +1,4 @@
1
1
  require "me/identity"
2
- require "me/store2"
3
2
 
4
3
  module Me
5
4
  module Mappers
@@ -33,7 +32,7 @@ module Me
33
32
  end
34
33
 
35
34
  def store
36
- @_store ||= Store2.build
35
+ @_store ||= Store.build
37
36
  end
38
37
  end
39
38
  end
@@ -1,6 +1,6 @@
1
- require "me/store2"
2
1
  require "me/ssh_config"
3
2
  require "me/errors"
3
+ require "me/store"
4
4
 
5
5
  module Me
6
6
  module Mappers
@@ -38,11 +38,11 @@ module Me
38
38
 
39
39
  def fetch_keys(keys)
40
40
  return keys if keys && !keys.empty?
41
- scoped.get("keys")
41
+ scoped.fetch("keys") { nil }
42
42
  end
43
43
 
44
44
  def store
45
- @_store ||= Store2.build
45
+ @_store ||= Store.build
46
46
  end
47
47
 
48
48
  def identity
@@ -0,0 +1,48 @@
1
+ require "store2"
2
+
3
+ module Me
4
+ module Store
5
+ class Environment < Struct.new(:value)
6
+ def self.wrap(env)
7
+ return env if env.is_a?(self)
8
+ new(env)
9
+ end
10
+
11
+ def to_s
12
+ "_#{value}"
13
+ end
14
+ end
15
+
16
+ class NullEnvironment < Environment
17
+ def to_s
18
+ ""
19
+ end
20
+ end
21
+ end
22
+
23
+ class << Store
24
+ def build
25
+ store2.build
26
+ end
27
+
28
+ private
29
+
30
+ def store2
31
+ @_store2 ||= Store2.open(filename)
32
+ end
33
+
34
+ def filename
35
+ File.join(user_home, ".me#{filename_suffix}.yml")
36
+ end
37
+
38
+ def user_home
39
+ ENV.fetch("HOME")
40
+ end
41
+
42
+ def filename_suffix
43
+ Store::Environment.wrap(
44
+ ENV.fetch("ME_ENV", Store::NullEnvironment.new)
45
+ )
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Me
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/me.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "thor"
22
+ spec.add_dependency "store2"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.7"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
@@ -10,7 +10,7 @@ module Me
10
10
  let(:active_identity) { "james" }
11
11
 
12
12
  before do
13
- store = Store2.build
13
+ store = Store.build
14
14
  store.set("active_identity", active_identity)
15
15
  store.save
16
16
  end
@@ -1,5 +1,6 @@
1
1
  ENV["ME_ENV"] ||= "test"
2
2
 
3
+ require "store2"
3
4
  require "me/thread_scope"
4
5
 
5
6
  RSpec.configure do |config|
@@ -28,8 +29,10 @@ RSpec.configure do |config|
28
29
 
29
30
  Kernel.srand config.seed
30
31
 
31
- config.before do
32
- Me::Store2.new._reset
32
+ config.around do |example|
33
+ Store2._with_reset do
34
+ example.run
35
+ end
33
36
  end
34
37
 
35
38
  config.after do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: me
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksii Fedorov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: store2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +112,7 @@ files:
98
112
  - lib/me/ssh_activation.rb
99
113
  - lib/me/ssh_config.rb
100
114
  - lib/me/ssh_config_view_model.rb
101
- - lib/me/store2.rb
115
+ - lib/me/store.rb
102
116
  - lib/me/thread_scope.rb
103
117
  - lib/me/version.rb
104
118
  - lib/me/view.rb
@@ -116,7 +130,6 @@ files:
116
130
  - spec/me/mappers/identity_store2_spec.rb
117
131
  - spec/me/mappers/ssh_config_store2_spec.rb
118
132
  - spec/me/ssh_config_spec.rb
119
- - spec/me/store2_spec.rb
120
133
  - spec/spec_helper.rb
121
134
  - test.sh
122
135
  homepage: https://github.com/waterlink/me
@@ -139,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
152
  version: '0'
140
153
  requirements: []
141
154
  rubyforge_project:
142
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.4.6
143
156
  signing_key:
144
157
  specification_version: 4
145
158
  summary: Small tool for switching common identities (ssh keys, git config, etc)
@@ -157,5 +170,4 @@ test_files:
157
170
  - spec/me/mappers/identity_store2_spec.rb
158
171
  - spec/me/mappers/ssh_config_store2_spec.rb
159
172
  - spec/me/ssh_config_spec.rb
160
- - spec/me/store2_spec.rb
161
173
  - spec/spec_helper.rb
@@ -1,147 +0,0 @@
1
- require "yaml"
2
-
3
- module Me
4
- class Store2
5
- class Scoped
6
- def initialize(store, scope)
7
- @store, @scope = store, scope
8
- end
9
-
10
- def ==(other)
11
- return false unless other.is_a?(Scoped)
12
- [self.store, self.scope] ==
13
- [other.store, other.scope]
14
- end
15
-
16
- def scoped(*add_scope)
17
- Scoped.new(store, scope + add_scope)
18
- end
19
-
20
- def get(*keys)
21
- store.get(scope + keys)
22
- end
23
-
24
- def set(*keys, value)
25
- store.set(scope + keys, value)
26
- end
27
-
28
- def has?(*keys)
29
- store.has?(scope + keys)
30
- end
31
-
32
- def get_or_set(*keys, value)
33
- store.get_or_set(scope + keys, value)
34
- end
35
-
36
- def fetch(*keys, &block)
37
- store.fetch(scope + keys, &block)
38
- end
39
-
40
- def save
41
- store.save
42
- end
43
-
44
- def _reset
45
- store._reset
46
- end
47
-
48
- protected
49
-
50
- attr_reader :store, :scope
51
- end
52
-
53
- def initialize
54
- @data = load
55
- end
56
-
57
- def self.build
58
- Store2.new.scoped
59
- end
60
-
61
- def ==(other)
62
- other.is_a?(Store2)
63
- end
64
-
65
- def scoped(*scope)
66
- Scoped.new(self, scope)
67
- end
68
-
69
- def get(keys)
70
- keys.inject(data) { |data, key| data[key] }
71
- end
72
-
73
- def set(keys, value)
74
- get(keys[0...-1])[keys[-1]] = value
75
- end
76
-
77
- def has?(keys)
78
- get(keys[0...-1]).has_key?(keys[-1])
79
- end
80
-
81
- def get_or_set(keys, value)
82
- set(keys, value) unless has?(keys)
83
- get(keys)
84
- end
85
-
86
- def fetch(keys, &block)
87
- return block.call unless has?(keys)
88
- get(keys)
89
- end
90
-
91
- def save
92
- File.write(filename, to_yaml)
93
- end
94
-
95
- def to_yaml
96
- data.to_yaml
97
- end
98
-
99
- def _reset
100
- create
101
- end
102
-
103
- protected
104
-
105
- attr_reader :data
106
-
107
- private
108
-
109
- def load
110
- return create unless File.exist?(filename)
111
- YAML.load_file(filename)
112
- end
113
-
114
- def create
115
- (@data = {}).tap { save }
116
- end
117
-
118
- def filename
119
- "#{user_home}/.me#{filename_suffix}.yml"
120
- end
121
-
122
- def user_home
123
- ENV.fetch("HOME")
124
- end
125
-
126
- def filename_suffix
127
- Environment.wrap(ENV.fetch("ME_ENV", NullEnvironment.new))
128
- end
129
-
130
- class Environment < Struct.new(:value)
131
- def self.wrap(env)
132
- return env if env.is_a?(self)
133
- new(env)
134
- end
135
-
136
- def to_s
137
- "_#{value}"
138
- end
139
- end
140
-
141
- class NullEnvironment < Environment
142
- def to_s
143
- ""
144
- end
145
- end
146
- end
147
- end
@@ -1,151 +0,0 @@
1
- require "me/store2"
2
-
3
- module Me
4
- RSpec.describe Store2 do
5
- subject(:store) { Store2.new }
6
-
7
- describe ".build" do
8
- it "creates scoped instance with empty scope" do
9
- expect(Store2.build).to eq(Store2::Scoped.new(Store2.new, []))
10
- end
11
- end
12
-
13
- describe "#scoped" do
14
- it "creates scoped instance with specified scope" do
15
- expect(store.scoped("hello", "world"))
16
- .to eq(Store2::Scoped.new(Store2.new, ["hello", "world"]))
17
- end
18
- end
19
-
20
- describe "#get and #set" do
21
- it "gets the value given list of keys" do
22
- store.set(["hello"], {})
23
- store.set(["hello", "world"], {})
24
- store.set(["hello", "world", "test"], "12345")
25
-
26
- expect(store.get(["hello", "world", "test"]))
27
- .to eq("12345")
28
- end
29
- end
30
-
31
- describe "#has?" do
32
- it "is true if key is present" do
33
- store.set(["hello"], {})
34
- store.set(["hello", "world"], {})
35
- store.set(["hello", "world", "test"], "12345")
36
-
37
- expect(store.has?(["hello", "world", "test"])).to eq(true)
38
- end
39
-
40
- it "is false if key is not present" do
41
- store.set(["hello"], {})
42
- store.set(["hello", "world"], {})
43
-
44
- expect(store.has?(["hello", "world", "test"])).to eq(false)
45
- end
46
- end
47
-
48
- describe "#get_or_set" do
49
- it "is current value if it is present" do
50
- store.set(["hello"], {})
51
- store.set(["hello", "world"], {})
52
- store.set(["hello", "world", "test"], "09876")
53
-
54
- expect(store.get_or_set(["hello", "world", "test"], "12345")).to eq("09876")
55
- end
56
-
57
- it "is default value if it is not present" do
58
- store.set(["hello"], {})
59
- store.set(["hello", "world"], {})
60
-
61
- expect(store.get_or_set(["hello", "world", "test"], "12345")).to eq("12345")
62
- end
63
-
64
- it "makes the value present if it wasn't" do
65
- store.set(["hello"], {})
66
- store.set(["hello", "world"], {})
67
- store.get_or_set(["hello", "world", "test"], "12345")
68
-
69
- expect(store.get(["hello", "world", "test"])).to eq("12345")
70
- end
71
- end
72
-
73
- describe "#fetch" do
74
- it "behaves like get if value is present" do
75
- store.set(["hello"], {})
76
- store.set(["hello", "world"], {})
77
- store.set(["hello", "world", "test"], "09876")
78
-
79
- expect(store.fetch(["hello", "world", "test"]) { fail }).to eq("09876")
80
- end
81
-
82
- it "calls block if value is not present" do
83
- store.set(["hello"], {})
84
- store.set(["hello", "world"], {})
85
-
86
- expect { store.fetch(["hello", "world", "test"]) { fail } }
87
- .to raise_error(RuntimeError)
88
- end
89
- end
90
- end
91
-
92
- RSpec.describe Store2::Scoped do
93
- subject(:scoped) { described_class.new(store, scope) }
94
-
95
- let(:store) { instance_double(Store2) }
96
- let(:scope) { ["hello", "world", "test"] }
97
-
98
- let(:a_value) { double("A value") }
99
- let(:another_value) { double("A value") }
100
- let(:a_proc) { Proc.new { a_value } }
101
-
102
- describe "#scoped" do
103
- it "creates instance of Scoped with additional scope" do
104
- expect(scoped.scoped("additional", "scope"))
105
- .to eq(described_class.new(store, scope + ["additional", "scope"]))
106
- end
107
- end
108
-
109
- describe "#get" do
110
- it "delegates to store#get" do
111
- allow(store).to receive(:get).with(scope + ["some", "keys"]).and_return(a_value)
112
- expect(scoped.get("some", "keys")).to eq(a_value)
113
- end
114
- end
115
-
116
- describe "#set" do
117
- it "delegates to store#set" do
118
- expect(store).to receive(:set).with(scope + ["some", "keys"], a_value)
119
- scoped.set("some", "keys", a_value)
120
- end
121
- end
122
-
123
- describe "#has?" do
124
- it "delegates to store#has?" do
125
- allow(store).to receive(:has?).with(scope + ["some", "keys"]).and_return(a_value)
126
- expect(scoped.has?("some", "keys")).to eq(a_value)
127
- end
128
- end
129
-
130
- describe "#get_or_set" do
131
- it "delegates to store#get_or_set" do
132
- allow(store).to receive(:get_or_set).with(scope + ["some", "keys"], a_value).and_return(another_value)
133
- expect(scoped.get_or_set("some", "keys", a_value)).to eq(another_value)
134
- end
135
- end
136
-
137
- describe "#fetch" do
138
- it "delegates to store#fetch" do
139
- allow(store).to receive(:fetch).with(scope + ["some", "keys"]).and_yield
140
- expect(scoped.fetch("some", "keys", &a_proc)).to eq(a_value)
141
- end
142
- end
143
-
144
- describe "#save" do
145
- it "delegates to store#save" do
146
- expect(store).to receive(:save)
147
- scoped.save
148
- end
149
- end
150
- end
151
- end