ab_rules 1.0.0
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.
- checksums.yaml +7 -0
- data/lib/ab_rules.rb +32 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6855f19c66ad1d56db1b5b02129131946c2280f2
|
4
|
+
data.tar.gz: 46c3a7c0c327f6cd1b1117814f6372f4f5b63da2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 511855683a649057e9829c2eb53d3eafe071ae6769ed0580e8331380f85eb544720dfed65c0f51f157c7ccf7934504eb16e86dc3c80780d6beffb173873002a0
|
7
|
+
data.tar.gz: 70e26c7ea6441dea93d6f25668135a108e0648549f31ebfdeec974eeecd0e9012d6d7ac43b918ba731a81fd3b91b106575eb2d9c1a1fe621ebb79dec7b6ab206
|
data/lib/ab_rules.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module AbRules
|
2
|
+
class Rule
|
3
|
+
def initialize(content, &block)
|
4
|
+
@content = content
|
5
|
+
@block = block
|
6
|
+
end
|
7
|
+
|
8
|
+
def match?(subjects = {})
|
9
|
+
@block ? @block.call(subjects) : true
|
10
|
+
rescue NoMethodError
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def apply
|
15
|
+
@content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.rule(content, &block)
|
20
|
+
Rule.new(content, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.split_by_id(id, *alternatives)
|
24
|
+
content = alternatives.flatten[id % alternatives.size]
|
25
|
+
block_given? ? yield(content) : content
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.split_by_rule(subjects = {}, *rules)
|
29
|
+
content = rules.flatten.find { |r| r.match?(subjects) }.apply
|
30
|
+
block_given? ? yield(content) : content
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ab_rules
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jiazhen Xie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.3.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.3.0
|
27
|
+
description: A light weight ruby AB test library based on rules
|
28
|
+
email: fdf515@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/ab_rules.rb
|
34
|
+
homepage: http://rubygems.org/gems/ab_rules
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.4.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A light weight ruby AB test library based on rules
|
58
|
+
test_files: []
|