split-cli 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3580a667862fc558263ba9d5e281d476b814b22e
4
+ data.tar.gz: 80ed1f8f7ee2e67d56e9f08aab79cbbf80878b01
5
+ SHA512:
6
+ metadata.gz: f1581a3662141d8530e9efe3c6077dc35c991661cfd8d876bc88d29041dd2271d44855cb79e7870e97ff406c510f0b993cc358f7406c0504aaf7356e73ce5bdf
7
+ data.tar.gz: 5e89a3bf458112627021a1fc9de2369d752bc77baf3415ed860bd14e8d62a3c95527df2579343e7ce5863cfcc78cab822bb80de086d084d7c67e02f08b73e563
@@ -0,0 +1,10 @@
1
+ split-cli*.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ services: redis-server
3
+ rvm:
4
+ - 2.1.5
5
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in split-cli.gemspec
4
+ gemspec
5
+
6
+ gem 'autotest'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Craig McNamara
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.
@@ -0,0 +1,57 @@
1
+ # Split::Cli
2
+
3
+ [![Build Status](https://travis-ci.org/craigmcnamara/split-cli.svg)](https://travis-ci.org/craigmcnamara/split-cli)
4
+
5
+ Add a CLI so Split can be used in unfamiliar situations and bad circumstances. I'm looking at you PHP.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'split-cli'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install split-cli
22
+
23
+ ## Usage
24
+
25
+ Supported environment variables
26
+ ```shell
27
+ REDIS_URL # default 'localhost:6379'
28
+ SPLIT_YAML_CONFIG # required
29
+ SPLIT_MULTI_EXPERIMENT # default true
30
+ REDIS_NAMESPACE # optional
31
+ ```
32
+
33
+ Basic Usage
34
+
35
+ ```shell
36
+ $ split-cli
37
+ Usage: split-cli [ab_test|finished] session_id experiment_name
38
+ -c, --config [path] Path to Split YAML config
39
+ -m, --multi Participate in multiple experiments. Default: true
40
+ -r, --redis [url] Redis URL
41
+ -n, --namespace [namespace] Redis namespace
42
+
43
+ $ split-cli ab_test session_id experiment_name
44
+ variant_x # ab_test command returns the string of the variant chosen
45
+
46
+ $ split-cli finished session_id experiment_name # no output and zero return is success
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/craigmcnamara/split-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://github.com/craigmcnamara/split-cli/blob/master/CODE_OF_CONDUCT.md) code of conduct.
52
+
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
57
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "split/cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "split/cli"
5
+
6
+ require 'optparse'
7
+
8
+ options = {}
9
+
10
+ parser = OptionParser.new do |opts|
11
+ opts.banner = "Usage: split-cli [ab_test|finished] session_id experiment_name"
12
+
13
+ opts.on("-c", "--config [path]", "Path to Split YAML config") do |c|
14
+ options[:config_path] = c
15
+ end
16
+
17
+ opts.on("-m", "--multi", "Participate in multiple experiments. Default: true") do |m|
18
+ options[:allow_multiple_experiments] = m
19
+ end
20
+
21
+ opts.on("-r", "--redis [url]", "Redis URL") do |r|
22
+ options[:redis_url] = r
23
+ end
24
+
25
+ opts.on("-n", "--namespace [namespace]", "Redis namespace") do |n|
26
+ options[:redis_namespace] = n
27
+ end
28
+ end
29
+
30
+ parser.parse!
31
+
32
+ if ARGV.empty?
33
+ puts parser
34
+ exit 1
35
+ else
36
+ args = ARGV.dup
37
+ command = args.shift.to_sym
38
+
39
+ begin
40
+ raise(Split::Cli::CommandError, "No session_id") unless session_id = args.shift
41
+ result = Split::Cli::Session.new(session_id, options).method(command).call(*args)
42
+ puts result if result.is_a?(String)
43
+ rescue Split::Cli::CommandError => e
44
+ puts e.message
45
+ puts parser
46
+ exit 1
47
+ rescue NameError => e
48
+ puts 'Invalid split-cli operation'
49
+ puts parser
50
+ exit 1
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ require 'split'
2
+ require 'split/cli/session'
3
+ require 'split/cli/version'
4
+
5
+ module Split
6
+ module Cli
7
+ CommandError = Class.new(StandardError)
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ require 'yaml'
2
+
3
+ module Split
4
+ module Cli
5
+ class Session
6
+ include Split::Helper
7
+
8
+ attr_accessor :session_id, :options
9
+
10
+ CONFIG_ERROR_MESSAGE = 'Set SPLIT_YAML_CONFIG to a valid path.'.freeze
11
+
12
+ def initialize(session_id, options = {})
13
+ @session_id = session_id
14
+ @options = options
15
+ config_split!
16
+ end
17
+
18
+ def ab_test(*args)
19
+ raise(Split::Cli::CommandError, 'No experiment name provided') unless args.any?
20
+ super
21
+ end
22
+
23
+ def finished(*args)
24
+ raise(Split::Cli::CommandError, 'No experiment name provided') unless args.any?
25
+ super
26
+ end
27
+
28
+ private
29
+
30
+ def config_split!
31
+ Split.redis = options.fetch :redis_url, ENV.fetch('REDIS_URL', 'localhost:6379')
32
+ Split.redis.namespace = options.fetch :redis_namespace, ENV['REDIS_NAMESPACE']
33
+
34
+ Split.configure do |config|
35
+ config.persistence = Split::Persistence::RedisAdapter.with_config(lookup_by: -> (cli) { cli.session_id })
36
+ config.allow_multiple_experiments = options.fetch(:allow_multiple_experiments, ENV.fetch('SPLIT_MULTI_EXPERIMENT', true))
37
+ config.experiments = YAML.load_file yaml_config_path
38
+ end
39
+ end
40
+
41
+ def yaml_config_path
42
+ options.fetch(:config_path, ENV['SPLIT_YAML_CONFIG']) || raise(CommandError, CONFIG_ERROR_MESSAGE)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Split
2
+ module Cli
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'split/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "split-cli"
8
+ spec.version = Split::Cli::VERSION
9
+ spec.authors = ["Craig McNamara"]
10
+ spec.email = ["craig@caring.com"]
11
+
12
+ spec.summary = %q{A CLI for the Split gem}
13
+ spec.description = %q{It's a bit odd, but I had my reasons.}
14
+ spec.homepage = "https://github.com/craigmcnamara/split-cli"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'bin'
21
+ spec.executables = 'split-cli'
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rspec-autotest", '~> 1'
28
+
29
+ spec.add_dependency "split", "~> 1.3"
30
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: split-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Craig McNamara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-autotest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: split
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ description: It's a bit odd, but I had my reasons.
84
+ email:
85
+ - craig@caring.com
86
+ executables:
87
+ - split-cli
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - bin/split-cli
102
+ - lib/split/cli.rb
103
+ - lib/split/cli/session.rb
104
+ - lib/split/cli/version.rb
105
+ - split-cli.gemspec
106
+ homepage: https://github.com/craigmcnamara/split-cli
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ allowed_push_host: https://rubygems.org
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A CLI for the Split gem
131
+ test_files: []
132
+ has_rdoc: