moxie 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9ead8d5dc0c1a1c5367dc0a939c43b4ddb5b033
4
+ data.tar.gz: 210dabc5e027ec88f8b86c95647cfa54e3a4f19f
5
+ SHA512:
6
+ metadata.gz: 82c63382de25c30c44977f016bbabc67a17c1c182067a5e5a2be7ab1f90553c3efdbffbd8aaa90b4c176a3a888002fdf550596d143dc04360442a4005a96c0b1
7
+ data.tar.gz: 4ac38a47b7083268b80c9b6a740629e14017d701fc845642ee28179385c38844134477839ba41a4040c43d817978ca878de3e066af6d8c4cb46292c0895a6bff
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ before_install: gem install bundler -v 1.10.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moxie.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Casey O'Hara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/NOTES.md ADDED
@@ -0,0 +1,97 @@
1
+ App
2
+ -id
3
+ -name
4
+ -repo
5
+
6
+ Environment
7
+ -id
8
+ -app
9
+ -name
10
+ -config
11
+
12
+ Build
13
+ -app
14
+ -branch
15
+ -version
16
+
17
+ Image
18
+ -app
19
+ -build
20
+ -env
21
+ -version
22
+
23
+ Instance
24
+ -app
25
+ -image
26
+ -cluster
27
+
28
+ Cluster
29
+ -name
30
+ -app
31
+ -image
32
+ -instances
33
+ -size
34
+
35
+ mox app
36
+ mox app prx
37
+
38
+ mox create --name=prx --repo=git@github.com/PrintReleaf/prx.git
39
+
40
+ mox builds
41
+ mox builds --app=prx
42
+ mox build prx
43
+ mox build prx --branch=master
44
+
45
+ mox releases
46
+ mox releases --app=prx
47
+ mox release prx
48
+ mox release prx --env=production
49
+ mox release prx --env=production --build=latest
50
+ mox release prx --env=production --build=master
51
+ mox release prx --env=production --build=master.20150601T234347
52
+
53
+ mox clusters
54
+ mox cluster create --name=prx-production --app=prx --image=latest
55
+ mox cluster update prx.production --image=latest --size=3
56
+ mox cluster delete prx.production
57
+ mox cluster restart
58
+
59
+
60
+ mox app list
61
+ mox app info
62
+ mox app add
63
+ mox app update
64
+ mox app remove
65
+
66
+
67
+ SET [id] moxie:applications
68
+ STR json moxie:application:123
69
+ SET [id] moxie:application:123:environments
70
+ STR json moxie:environment:456
71
+
72
+
73
+
74
+ Application.all()
75
+ Application.find(1)
76
+ Application.find([1,2,3])
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Moxie
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/moxie`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'moxie'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install moxie
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/moxie.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/mox ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/moxie'
4
+
5
+ Moxie::CLI.start(ARGV)
6
+
data/bin/moxie ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/moxie'
4
+
5
+ Moxie::CLI.start(ARGV)
6
+
data/lib/moxie.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "json"
2
+ require "securerandom"
3
+
4
+ require "hashie"
5
+ require "redis"
6
+ require "redis-namespace"
7
+ require "thor"
8
+
9
+ require_relative "moxie/version"
10
+ require_relative "moxie/errors"
11
+ require_relative "moxie/transforms"
12
+ require_relative "moxie/id"
13
+ require_relative "moxie/store"
14
+ require_relative "moxie/finders"
15
+ require_relative "moxie/application"
16
+ require_relative "moxie/environment"
17
+ require_relative "moxie/cli"
18
+
19
+ module Moxie
20
+ REDIS_NAMESPACE = 'moxie'
21
+
22
+ def self.redis
23
+ Redis::Namespace.new(REDIS_NAMESPACE, redis: Redis.current)
24
+ end
25
+ end
26
+
@@ -0,0 +1,43 @@
1
+ module Moxie
2
+ class Application < Hashie::Trash
3
+ extend Finders
4
+ include Hashie::Extensions::IndifferentAccess
5
+
6
+ key 'application'
7
+
8
+ property :name, required: true, transform_with: Transforms::Slug
9
+ property :repo, required: true
10
+
11
+ def id
12
+ name
13
+ end
14
+
15
+ def environment_ids
16
+ Store.set("application:#{id}:environments").to_a
17
+ end
18
+
19
+ def environments
20
+ Environment.find(environment_ids)
21
+ end
22
+
23
+ def self.create(options)
24
+ application = new(options)
25
+ raise Exists, "Application '#{application.name}' already exists" if exists?(application.name)
26
+ Store.object("application:#{application.name}").save(application.to_hash)
27
+ Store.set("applications").add(application.name)
28
+ application
29
+ end
30
+
31
+ def self.delete(name)
32
+ application = find(name)
33
+ Store.object("application:#{application.name}").delete
34
+ Store.set("applications").remove(application.name)
35
+ end
36
+
37
+ def self.exists?(id)
38
+ ids.include?(id)
39
+ end
40
+
41
+ end
42
+ end
43
+
data/lib/moxie/cli.rb ADDED
@@ -0,0 +1,102 @@
1
+ module Moxie
2
+ class Thor < ::Thor
3
+ no_commands do
4
+ def safely
5
+ begin
6
+ yield if block_given?
7
+ rescue Moxie::Error => e
8
+ puts e.message
9
+ exit 1
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module Subcommands
16
+ class App < Thor
17
+ default_command :info
18
+
19
+ desc "list", "List applications"
20
+ def list
21
+ puts Moxie::Application.all.sort_by(&:name)
22
+ end
23
+
24
+ desc "info <appname>", "Display an application"
25
+ def info(name=nil)
26
+ return list if name.nil?
27
+
28
+ safely do
29
+ application = Moxie::Application.find(name)
30
+ puts application
31
+ end
32
+ end
33
+
34
+ desc "create", "Create an application"
35
+ option :name, required: true
36
+ option :repo, required: true
37
+ def create
38
+ safely do
39
+ Moxie::Application.create({
40
+ name: options[:name],
41
+ repo: options[:repo]
42
+ })
43
+ end
44
+ end
45
+
46
+ desc "delete <appname>", "Delete an application"
47
+ def delete(name)
48
+ safely do
49
+ Moxie::Application.delete(name)
50
+ end
51
+ end
52
+ end
53
+
54
+ class Environment < Thor
55
+ default_command :info
56
+
57
+ desc "list", "List application environments"
58
+ def list
59
+ puts Moxie::Environment.all
60
+ end
61
+
62
+ desc "info <appname>", "Display an environment"
63
+ def info(id=nil)
64
+ return list if id.nil?
65
+
66
+ safely do
67
+ environment = Moxie::Environment.find(id)
68
+ puts environment
69
+ end
70
+ end
71
+
72
+ desc "create", "Create an application environment"
73
+ option :app, required: true
74
+ option :name, required: true
75
+ def create
76
+ safely do
77
+ Moxie::Environment.create({
78
+ app: options[:app],
79
+ name: options[:name]
80
+ })
81
+ end
82
+ end
83
+
84
+ desc "delete <appname>", "Delete an environment"
85
+ def delete(id)
86
+ safely do
87
+ Moxie::Environment.delete(id)
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+
94
+ class CLI < Thor
95
+ desc "app <subcommand> [<args>]", "Manage applications"
96
+ subcommand "app", Subcommands::App
97
+
98
+ desc "environment <subcommand> [<args>]", "Manage application environments"
99
+ subcommand "environment", Subcommands::Environment
100
+ end
101
+ end
102
+
@@ -0,0 +1,7 @@
1
+ module Moxie
2
+ class Environment < Hashie::Trash
3
+ extend Finders
4
+ key 'environment'
5
+ end
6
+ end
7
+
@@ -0,0 +1,6 @@
1
+ module Moxie
2
+ Error = Class.new(StandardError)
3
+ NotFound = Class.new(Error)
4
+ Exists = Class.new(Error)
5
+ end
6
+
@@ -0,0 +1,35 @@
1
+ module Moxie
2
+ module Finders
3
+ def key(k=nil)
4
+ @key = k unless k.nil?
5
+ return @key
6
+ end
7
+
8
+ def ids
9
+ Store.set("#{key}s").to_a
10
+ end
11
+
12
+ def all
13
+ ids.map { |id| find(id) }
14
+ end
15
+
16
+ def find(*args)
17
+ if args.first.is_a? Array
18
+ find_multiple(*args)
19
+ else
20
+ find_one(args.first)
21
+ end
22
+ end
23
+
24
+ def find_one(id)
25
+ hash = Store.object("#{key}:#{id}").to_hash
26
+ raise NotFound, "Could not find #{self.name.split(":").last.downcase} '#{id}'" if hash.empty?
27
+ new(hash)
28
+ end
29
+
30
+ def find_multiple(ids)
31
+ ids.map { |id| find_one(id) }
32
+ end
33
+ end
34
+ end
35
+
data/lib/moxie/id.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Moxie
2
+ class ID
3
+ def self.generate
4
+ SecureRandom.hex[0,8]
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,52 @@
1
+ module Moxie
2
+ class Store
3
+ def self.set(key)
4
+ Store::Set.new(key)
5
+ end
6
+
7
+ def self.object(key)
8
+ Store::Object.new(key)
9
+ end
10
+
11
+ attr_reader :key
12
+
13
+ def initialize(key)
14
+ @key = key
15
+ end
16
+
17
+ class Set < Store
18
+ def to_a
19
+ Moxie.redis.smembers(key)
20
+ end
21
+
22
+ def add(value)
23
+ Moxie.redis.sadd(key, value)
24
+ end
25
+
26
+ def remove(value)
27
+ Moxie.redis.srem(key, value)
28
+ end
29
+ end
30
+
31
+ class Object < Store
32
+ def to_hash
33
+ json = Moxie.redis.get(key)
34
+ begin
35
+ JSON.parse(json)
36
+ rescue
37
+ return {}
38
+ end
39
+ end
40
+
41
+ def save(hash={})
42
+ Moxie.redis.set(key, hash.to_json)
43
+ end
44
+
45
+ def delete
46
+ Moxie.redis.del(key)
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
@@ -0,0 +1,8 @@
1
+ module Moxie
2
+ module Transforms
3
+ Slug = lambda { |v|
4
+ v.to_s.strip.downcase.gsub(/\s+/, ' ').gsub(/[^a-z1-9.]+/, '-')
5
+ }
6
+ end
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ module Moxie
2
+ VERSION = "0.0.1"
3
+ end
data/moxie.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'moxie/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "moxie"
8
+ spec.version = Moxie::VERSION
9
+ spec.authors = ["Casey O'Hara"]
10
+ spec.email = ["casey@camber.io"]
11
+ spec.summary = "$ mox"
12
+ spec.homepage = "https://github.com/camber/moxie"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "bin"
17
+ spec.executables = ['moxie', 'mox']
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "hashie", "~> 3.4.1"
21
+ spec.add_dependency "redis", "~> 3.2.1"
22
+ spec.add_dependency "redis-namespace", "~> 1.5.2"
23
+ spec.add_dependency "thor", "~> 0.19.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.2.0"
28
+ spec.add_development_dependency "factory_girl", "~> 4.5.0"
29
+ spec.add_development_dependency "mock_redis", "~> 0.14.1"
30
+ end
31
+
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moxie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Casey O'Hara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.4.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis-namespace
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.19.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.19.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.2.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.2.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: factory_girl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 4.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 4.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: mock_redis
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.14.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.14.1
139
+ description:
140
+ email:
141
+ - casey@camber.io
142
+ executables:
143
+ - moxie
144
+ - mox
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".rspec"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - NOTES.md
154
+ - README.md
155
+ - Rakefile
156
+ - bin/mox
157
+ - bin/moxie
158
+ - lib/moxie.rb
159
+ - lib/moxie/application.rb
160
+ - lib/moxie/cli.rb
161
+ - lib/moxie/environment.rb
162
+ - lib/moxie/errors.rb
163
+ - lib/moxie/finders.rb
164
+ - lib/moxie/id.rb
165
+ - lib/moxie/store.rb
166
+ - lib/moxie/transforms.rb
167
+ - lib/moxie/version.rb
168
+ - moxie.gemspec
169
+ homepage: https://github.com/camber/moxie
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.4.2
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: "$ mox"
193
+ test_files: []