config-store 0.1

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.
data/.config-store ADDED
@@ -0,0 +1 @@
1
+ {"store":85,"org":133,"site":"http://127.0.0.1:3000"}
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'rspec'
5
+ end
6
+
7
+ gemspec
8
+
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ config-store (0.1)
5
+ activeresource
6
+ commander
7
+ json
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (3.2.8)
13
+ activesupport (= 3.2.8)
14
+ builder (~> 3.0.0)
15
+ activeresource (3.2.8)
16
+ activemodel (= 3.2.8)
17
+ activesupport (= 3.2.8)
18
+ activesupport (3.2.8)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ builder (3.0.4)
22
+ commander (4.1.2)
23
+ highline (~> 1.6.11)
24
+ diff-lcs (1.1.3)
25
+ highline (1.6.15)
26
+ i18n (0.6.1)
27
+ json (1.7.5)
28
+ multi_json (1.3.6)
29
+ rake (0.9.2.2)
30
+ rspec (2.10.0)
31
+ rspec-core (~> 2.10.0)
32
+ rspec-expectations (~> 2.10.0)
33
+ rspec-mocks (~> 2.10.0)
34
+ rspec-core (2.10.1)
35
+ rspec-expectations (2.10.0)
36
+ diff-lcs (~> 1.1.3)
37
+ rspec-mocks (2.10.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ config-store!
44
+ rake
45
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 SynApps
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Config::Store
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'config-store'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install config-store
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require :default
4
+ require "bundler/gem_tasks"
5
+
data/bin/config-store ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander/import'
4
+ dir_name = File.expand_path("..", File.dirname(__FILE__))
5
+ require "#{dir_name}/lib/config_store"
6
+
7
+ program :version, ConfigStore::Version
8
+ program :description, "Loads environment variables from a remote server for easy and secure sharing/switching of project configuration."
9
+ program :help_formatter, :compact
10
+ default_command :show
11
+
12
+ $log = false
13
+ global_option('-l', '--log', 'Outputs the log of http queries sent to the server') { $log = true }
14
+ def activate_logs
15
+ require 'logger'
16
+ ActiveResource::Base.logger = Logger.new(STDOUT)
17
+ end
18
+ def init(validate = true)
19
+ ConfigStore.validate_file if validate
20
+ activate_logs if $log
21
+ end
22
+ command :show do |c|
23
+ c.syntax = 'config-store show'
24
+ c.summary = 'Displays all the variables for the current store.'
25
+ c.action do |args, options|
26
+ init
27
+ ConfigStore.show
28
+ end
29
+ end
30
+
31
+ command :export do |c|
32
+ c.syntax = 'config-store export'
33
+ c.summary = 'Outputs the all the exports needed for all the env variables in the store.'
34
+ c.action do |args, options|
35
+ init
36
+ ConfigStore.export
37
+ end
38
+ end
39
+
40
+ command :setup do |c|
41
+ c.syntax = 'config-store setup [options]'
42
+ c.summary = 'Creates or mofify your current .config-store file to setup the org/store your project is related to.'
43
+ c.example 'Configures the site, org and store to use within this directory', 'config-store setup site=https://www.mysite.com/endpoint org=myorg store=mystore'
44
+ c.action do |args, options|
45
+ init(false)
46
+ hash = arg_hash(args)
47
+ ConfigStore.setup(hash[:org], hash[:store], hash[:site])
48
+ end
49
+ end
50
+
51
+ command :add do |c|
52
+ c.syntax = 'config-store add key=value'
53
+ c.summary = 'Adds key-value pair(s) to your store.'
54
+ c.example 'Adds two new pairs to your store', 'config-store add key=value key2=value2'
55
+ c.action do |args, options|
56
+ init
57
+ hash = arg_hash(args)
58
+ ConfigStore.add hash
59
+ end
60
+ end
61
+
62
+ command :delete do |c|
63
+ c.syntax = 'config-store delete key1 key2 key3'
64
+ c.summary = 'Deletes keys within your store'
65
+ c.example 'keys names foo and bar will be removed', 'config-store delete foo bar'
66
+ c.action do |args, options|
67
+ activate_logs if $log
68
+ ConfigStore.delete args
69
+ end
70
+ end
71
+
72
+ def arg_hash(args)
73
+ hash = {}
74
+ args.each do |a|
75
+ key_value = a.split('=')
76
+ hash[key_value[0].to_sym] = key_value[1]
77
+ end
78
+ hash
79
+ end
80
+
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "#{lib}/config_store/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "config-store"
8
+ gem.version = ConfigStore::Version
9
+ gem.authors = ["Jeremy Fabre, Emanuel Petre"]
10
+ gem.email = ["jeremy.fabre@hotmail.com, petreemanuel@gmail.com"]
11
+ gem.description = "Config-store helps you manage your projects configs, so you can easily plug and reuse them."
12
+ gem.summary = "Easy configs managements"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'activeresource'
21
+ gem.add_dependency 'json'
22
+ gem.add_dependency 'commander'
23
+ gem.add_development_dependency 'rake'
24
+ gem.add_development_dependency 'rspec'
25
+ end
@@ -0,0 +1,10 @@
1
+ module ConfigStore
2
+
3
+ class Organization < ActiveResource::Base
4
+ extend Query
5
+ self.site = ConfigStore.site
6
+ def self.prefix_options
7
+ {}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ module ConfigStore
2
+ class Pair < ActiveResource::Base
3
+ extend Query
4
+ self.site = ConfigStore.site
5
+ self.prefix = "/organizations/:org_id/stores/:store_id/"
6
+
7
+ def self.store= value
8
+ @@store = value
9
+ end
10
+ def self.org= value
11
+ @@org = value
12
+ end
13
+
14
+ def prefix_options
15
+ self.class.prefix_options
16
+ end
17
+
18
+ def self.prefix_options
19
+ { :org_id => @@org.id, :store_id => @@store.id }
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module ConfigStore
2
+ module Query
3
+ def find_by_name(name)
4
+ all(params: prefix_options).select{|x| x.name == name }.first
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module ConfigStore
2
+ class Store < ActiveResource::Base
3
+ extend Query
4
+ self.site = ConfigStore.site
5
+ self.prefix = "/organizations/:org_id/"
6
+
7
+ def self.org= value
8
+ @@org = value
9
+ end
10
+
11
+ def prefix_options
12
+ self.class.prefix_options
13
+ end
14
+
15
+ def self.prefix_options
16
+ { :org_id => @@org.id }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ConfigStore
2
+ Version = '0.1'
3
+ end
@@ -0,0 +1,120 @@
1
+ require 'active_resource'
2
+ require 'json'
3
+
4
+ module ConfigStore
5
+ def self.site
6
+ @site || 'http://127.0.0.1:3000'
7
+ end
8
+ def self.site=(value)
9
+ @site = value
10
+ end
11
+ def self.store_keys
12
+ @keys ||= get_store_keys
13
+ end
14
+ def self.get_store_keys
15
+ if File.exists? '.config-store'
16
+ File.open('.config-store', 'r') { |f| JSON.parse(f.read).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo } }
17
+ else
18
+ {}
19
+ end
20
+ end
21
+
22
+ self.site = store_keys[:site]
23
+ dir = File.dirname(__FILE__)
24
+ autoload :Query, "#{dir}/config_store/query"
25
+ autoload :Pair, "#{dir}/config_store/pair"
26
+ autoload :Organization, "#{dir}/config_store/organization"
27
+ autoload :Store, "#{dir}/config_store/store"
28
+ autoload :Version, "#{dir}/config_store/version"
29
+
30
+ def self.setup(org_name, store_name, site)
31
+ unless site.nil?
32
+ Organization.site = site
33
+ Store.site = site
34
+ Pair.site = site
35
+ end
36
+ org = Organization.find_by_name(org_name) || Organization.create(name: org_name)
37
+ Store.org = org
38
+ store = Store.find_by_name(store_name) || Store.create(name: org_name)
39
+
40
+ to_store = {:store => store.id, :org => org.id, :site => site || store_keys[:site]}.to_json
41
+ File.open(".config-store", 'w') {|f| f.write(to_store) }
42
+ end
43
+
44
+ def self.show
45
+ load_associations
46
+ pairs = index
47
+
48
+ if pairs.size > 0
49
+ params = pairs.inject("") do |sum, p|
50
+ sum << "#{p.key}=#{p.value}\n"
51
+ end
52
+ else
53
+ params = "No key in the store right now"
54
+ end
55
+ puts "\nConfiguration for org:#{organization.name} store:#{store.name}\n--------------\n" << params
56
+ end
57
+
58
+ def self.export
59
+ load_associations
60
+ pairs = index
61
+
62
+ if pairs.size > 0
63
+ command = pairs.map{|p| "export #{p.key}='#{p.value}'" }.join(' && ')
64
+ $stdout.write command
65
+ else
66
+ $stdout.write "echo \"config-store: Nothing to export.\""
67
+ end
68
+ end
69
+
70
+ def self.add(key_values)
71
+ load_associations
72
+ pairs = index
73
+
74
+ to_create = key_values.select{|k, v| !pairs.any?{|p| p.key == k.to_s } }
75
+ to_update = pairs.select{|p| key_values.keys.any?{|k| p.key == k.to_s } }
76
+
77
+ to_create.each do |k, v|
78
+ Pair.create(:key => k, :value => v)
79
+ end
80
+ to_update.each { |p| p.save! }
81
+ end
82
+
83
+ def self.delete(keys)
84
+ load_associations
85
+
86
+ if keys.size > 0
87
+ to_remove = index.select{|p| keys.any?{|k| p.key == k } }
88
+
89
+ to_remove.each{|p| p.destroy }
90
+ end
91
+ end
92
+
93
+ private
94
+ def self.validate_file
95
+ unless File.exist?('.config-store')
96
+ puts ' --> No .config-store '
97
+ exit
98
+ end
99
+ end
100
+
101
+ def self.index
102
+ @pairs ||= Pair.all(params: Pair.prefix_options)
103
+ end
104
+
105
+ def self.load_associations
106
+ Store.org = organization
107
+ Pair.org = organization
108
+ Pair.store = store
109
+ end
110
+
111
+ def self.store
112
+ @store ||= Store.find(store_keys[:store], params: Store.prefix_options)
113
+ end
114
+ def self.organization
115
+ @org ||= Organization.find(store_keys[:org])
116
+ end
117
+ def self.store_keys
118
+ @keys ||= File.open(".config-store", 'r') { |f| JSON.parse(f.read).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo } }
119
+ end
120
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigStore::Pair do
4
+ before :all do
5
+ @org = ConfigStore::Organization.new name: 'org'
6
+ @org.save!
7
+ ConfigStore::Store.org = @org
8
+
9
+ @store = ConfigStore::Store.new :name => 'my store'
10
+ @store.save!
11
+
12
+ ConfigStore::Pair.store = @store
13
+ ConfigStore::Pair.org = @org
14
+ end
15
+
16
+ after :all do
17
+ @org.destroy
18
+ end
19
+
20
+ it "creates pairs succesfully" do
21
+ expected = ConfigStore::Pair.new key: 'baba', value: 'value'
22
+ expected.save!
23
+
24
+ actual = ConfigStore::Pair.find(expected.id, :params => { store_id: @store.id, org_id: @org.id })
25
+
26
+ actual.should == expected
27
+ end
28
+
29
+ it "updates pairs succesfully" do
30
+ pair = ConfigStore::Pair.new key: 'key', value: 'value'
31
+ pair.save!
32
+
33
+ expected = ConfigStore::Pair.find(pair.id, params: {store_id: @store.id, org_id: @org.id })
34
+ expected.value = 'update'
35
+ expected.save!
36
+
37
+ actual = ConfigStore::Pair.find(expected.id, params: {store_id: @store.id, org_id: @org.id })
38
+
39
+ actual.should == expected
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rubygems'
8
+ require 'bundler/setup'
9
+ Bundler.require :default, :test
10
+ require "#{File.dirname(__FILE__)}/../lib/config_store"
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ #require 'logger'
18
+ #ActiveResource::Base.logger = Logger.new(STDOUT)
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfigStore::Store do
4
+ before :all do
5
+ @org = ConfigStore::Organization.new(name: 'myorg')
6
+ @org.save!
7
+ ConfigStore::Store.org = @org
8
+ end
9
+ after :all do
10
+ @org.destroy
11
+ end
12
+
13
+ it "creates one successfully" do
14
+ expected = ConfigStore::Store.new :name => 'abcd', :org_id => @org.id
15
+ expected.save!
16
+
17
+ actual = ConfigStore::Store.find(expected.id, params: { :org_id => @org.id })
18
+ actual.should == expected
19
+ end
20
+
21
+ it "updates one successfully" do
22
+ store = ConfigStore::Store.new :name => 'abcd'
23
+ store.save!
24
+
25
+ expected = ConfigStore::Store.find(store.id, params: { :org_id => @org.id })
26
+ expected.name = 'boombo'
27
+ expected.save!
28
+
29
+ actual = ConfigStore::Store.find(expected.id, params: { :org_id => @org.id })
30
+
31
+ actual.should == expected
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: config-store
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Fabre, Emanuel Petre
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeresource
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: commander
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Config-store helps you manage your projects configs, so you can easily
95
+ plug and reuse them.
96
+ email:
97
+ - jeremy.fabre@hotmail.com, petreemanuel@gmail.com
98
+ executables:
99
+ - config-store
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .config-store
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/config-store
112
+ - config-store.gemspec
113
+ - lib/config_store.rb
114
+ - lib/config_store/organization.rb
115
+ - lib/config_store/pair.rb
116
+ - lib/config_store/query.rb
117
+ - lib/config_store/store.rb
118
+ - lib/config_store/version.rb
119
+ - spec/pairs_crud_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/store_crud_spec.rb
122
+ homepage: ''
123
+ licenses: []
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: -3760416996985074857
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: -3760416996985074857
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.24
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: Easy configs managements
152
+ test_files:
153
+ - spec/pairs_crud_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/store_crud_spec.rb