iodized 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: c309c1ee645f26063201e510730a597155afea53
4
+ data.tar.gz: b0a68cb1765b57d065b48973a99792a8ad1f73e5
5
+ SHA512:
6
+ metadata.gz: de938a2f4544befec5faeaabb89cd54d0a28110a8f04e37e327f5666ee0b8efcf553dbd7ff8cf3b154ac57dfcc41bbb4193832d99e7f5c02b7c3eabf242b6be5
7
+ data.tar.gz: 153f61850b5c6432564202750252202bda92fdd9d4fbeb30d960a24151f37b4f3e682df6149af48bd375b266d8691923d7dcc40d33c409c0d3dd877d4998c488
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in solid_octane.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ iodized (0.0.1)
5
+ rack
6
+ thin
7
+ thrift (~> 0.9.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ daemons (1.1.9)
13
+ diff-lcs (1.2.5)
14
+ eventmachine (1.0.3)
15
+ rack (1.5.2)
16
+ rack-protection (1.5.3)
17
+ rack
18
+ rake (10.3.2)
19
+ rspec (3.0.0)
20
+ rspec-core (~> 3.0.0)
21
+ rspec-expectations (~> 3.0.0)
22
+ rspec-mocks (~> 3.0.0)
23
+ rspec-core (3.0.1)
24
+ rspec-support (~> 3.0.0)
25
+ rspec-expectations (3.0.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.0.0)
28
+ rspec-mocks (3.0.1)
29
+ rspec-support (~> 3.0.0)
30
+ rspec-support (3.0.0)
31
+ sinatra (1.4.5)
32
+ rack (~> 1.4)
33
+ rack-protection (~> 1.4)
34
+ tilt (~> 1.3, >= 1.3.4)
35
+ thin (1.6.2)
36
+ daemons (>= 1.0.9)
37
+ eventmachine (>= 1.0.0)
38
+ rack (>= 1.0.0)
39
+ thrift (0.9.1)
40
+ tilt (1.4.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.3)
47
+ iodized!
48
+ rake
49
+ rspec (>= 2.12.0)
50
+ sinatra
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Iodized
2
+ ### Iodine rich feature toggling. Lack of iodine can lead to development delays, and stunted growth.
3
+
4
+ Ruby client for [iodized](https://github.com/envato/iodized)
5
+
6
+ ## Usage
7
+
8
+ TODO
9
+
10
+ see examples for now
11
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir["tasks/**/*.rake"].each{|f| load f}
Binary file
Binary file
@@ -0,0 +1,12 @@
1
+ require 'sinatra'
2
+ require 'iodized'
3
+ require 'json'
4
+
5
+ Iodized.client = Iodized::Client.new('localhost', 5353)
6
+ use Iodized::Middleware
7
+
8
+ get '/cool_story' do
9
+ @joe = Iodized.do?(:cool_story_joe, params)
10
+ @features = Thread.current[:iodized_feature_set]
11
+ erb :cool_story
12
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <h1>COOL STORY, <%= @joe ? "JOE!" : "BRO!" %></h2>
7
+ <% if @joe %>
8
+ <img src="/cool_story_joe.jpg" width="500">
9
+ <% else %>
10
+ <img src="/cool_story_bro.jpg" width="500">
11
+ <% end %>
12
+
13
+ <h2>all the features:</h2>
14
+ <pre><%= JSON.pretty_generate @features %></pre>
15
+ </body>
16
+ </html>
data/iodized.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ #encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'iodized/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "iodized"
9
+ spec.version = Iodized::VERSION
10
+ spec.authors = ["Julian Doherty"]
11
+ spec.email = ["julian@envato.com"]
12
+ spec.description = %q{Iodine rich feature toggling. Lack of iodine can lead to development delays, and stunted growth.}
13
+ spec.summary = %q{iodized Ruby Client}
14
+ spec.homepage = "https://github.com/envato/iodized_ruby_client"
15
+ spec.license = "Copyright Envato - All rights reserved."
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rspec", ">= 2.12.0"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "sinatra"
26
+
27
+ spec.add_dependency "thrift", "~> 0.9.1"
28
+ spec.add_dependency "rack"
29
+ spec.add_dependency "thin"
30
+ end
data/lib/iodized.rb ADDED
@@ -0,0 +1,42 @@
1
+ #encoding: utf-8
2
+ require 'iodized/client'
3
+ require 'iodized/config'
4
+ require 'iodized/features'
5
+ require 'iodized/middleware'
6
+ require 'iodized/version'
7
+
8
+ module Iodized
9
+
10
+ def self.do?(feature, state)
11
+ feature_set = if Thread.current[:iodized_feature_set]
12
+ Thread.current[:iodized_feature_set]
13
+ else
14
+ Thread.current[:iodized_feature_set] = client.feature_set(state)
15
+ end
16
+ feature_set[feature.to_s] || false
17
+ end
18
+
19
+ def self.reset_feature_set!
20
+ Thread.current[:iodized_feature_set] = nil
21
+ end
22
+
23
+ def self.client
24
+ @client ||= Iodized::Client.new
25
+ end
26
+
27
+ def self.client=(client)
28
+ @client = client
29
+ end
30
+
31
+ def self.config
32
+ @config ||= Iodized::Config.new
33
+ end
34
+
35
+ if defined? Rails
36
+ class IodizedRailtie < Rails::Railtie
37
+ initializer "iodized_railtie.configure_rails_initialization" do |app|
38
+ app.middleware.use Iodized::Middleware
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,67 @@
1
+ #encoding: utf-8
2
+
3
+ module Iodized
4
+ class Client
5
+
6
+ def initialize(host='localhost', port=5353)
7
+ @host = host
8
+ @port = port
9
+ end
10
+
11
+ def close
12
+ @transport.close
13
+ end
14
+
15
+ def ping()
16
+ thrift_client.ping
17
+ end
18
+
19
+ def feature_set(state)
20
+ retries = 5
21
+ begin
22
+ thrift_client.feature_set(state.merge(request_state))
23
+ rescue Thrift::TransportException => e
24
+ if (retries -= 1) > 0
25
+ retry
26
+ else
27
+ raise e
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+ def thrift_client
34
+ if @client && @transport && @transport.open?
35
+ @client
36
+ else
37
+ @transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port))
38
+ @protocol = Thrift::BinaryProtocol.new(@transport)
39
+ @client = Iodized::Features::Client.new(@protocol)
40
+
41
+ @transport.open
42
+
43
+ @client
44
+ end
45
+ end
46
+
47
+ def request_state
48
+ state = {}
49
+ if rack_available? && !request.nil?
50
+ state = state.merge({
51
+ "session_id" => request.session_options[:id] || "",
52
+ "host_name" => request.host || "",
53
+ "client_ip" => request.ip || "",
54
+ })
55
+ end
56
+ state
57
+ end
58
+
59
+ def request
60
+ Thread.current[:iodized_request]
61
+ end
62
+
63
+ def rack_available?
64
+ (defined? Rack) != nil
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,11 @@
1
+ #encoding: utf-8
2
+
3
+ module Iodized
4
+ class Config
5
+ attr_accessor :url
6
+
7
+ def initialize
8
+ @url = 'http://localhost:8080'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.1)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require_relative 'feature_types'
9
+
10
+ module Iodized
11
+ end
@@ -0,0 +1,10 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.1)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+
9
+ module Iodized
10
+ end
@@ -0,0 +1,133 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.1)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require_relative 'feature_types'
9
+
10
+ module Iodized
11
+ module Features
12
+ class Client
13
+ include ::Thrift::Client
14
+
15
+ def ping()
16
+ send_ping()
17
+ return recv_ping()
18
+ end
19
+
20
+ def send_ping()
21
+ send_message('ping', Ping_args)
22
+ end
23
+
24
+ def recv_ping()
25
+ result = receive_message(Ping_result)
26
+ return result.success unless result.success.nil?
27
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'ping failed: unknown result')
28
+ end
29
+
30
+ def feature_set(state)
31
+ send_feature_set(state)
32
+ return recv_feature_set()
33
+ end
34
+
35
+ def send_feature_set(state)
36
+ send_message('feature_set', Feature_set_args, :state => state)
37
+ end
38
+
39
+ def recv_feature_set()
40
+ result = receive_message(Feature_set_result)
41
+ return result.success unless result.success.nil?
42
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'feature_set failed: unknown result')
43
+ end
44
+
45
+ end
46
+
47
+ class Processor
48
+ include ::Thrift::Processor
49
+
50
+ def process_ping(seqid, iprot, oprot)
51
+ args = read_args(iprot, Ping_args)
52
+ result = Ping_result.new()
53
+ result.success = @handler.ping()
54
+ write_result(result, oprot, 'ping', seqid)
55
+ end
56
+
57
+ def process_feature_set(seqid, iprot, oprot)
58
+ args = read_args(iprot, Feature_set_args)
59
+ result = Feature_set_result.new()
60
+ result.success = @handler.feature_set(args.state)
61
+ write_result(result, oprot, 'feature_set', seqid)
62
+ end
63
+
64
+ end
65
+
66
+ # HELPER FUNCTIONS AND STRUCTURES
67
+
68
+ class Ping_args
69
+ include ::Thrift::Struct, ::Thrift::Struct_Union
70
+
71
+ FIELDS = {
72
+
73
+ }
74
+
75
+ def struct_fields; FIELDS; end
76
+
77
+ def validate
78
+ end
79
+
80
+ ::Thrift::Struct.generate_accessors self
81
+ end
82
+
83
+ class Ping_result
84
+ include ::Thrift::Struct, ::Thrift::Struct_Union
85
+ SUCCESS = 0
86
+
87
+ FIELDS = {
88
+ SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'}
89
+ }
90
+
91
+ def struct_fields; FIELDS; end
92
+
93
+ def validate
94
+ end
95
+
96
+ ::Thrift::Struct.generate_accessors self
97
+ end
98
+
99
+ class Feature_set_args
100
+ include ::Thrift::Struct, ::Thrift::Struct_Union
101
+ STATE = 1
102
+
103
+ FIELDS = {
104
+ STATE => {:type => ::Thrift::Types::MAP, :name => 'state', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}}
105
+ }
106
+
107
+ def struct_fields; FIELDS; end
108
+
109
+ def validate
110
+ end
111
+
112
+ ::Thrift::Struct.generate_accessors self
113
+ end
114
+
115
+ class Feature_set_result
116
+ include ::Thrift::Struct, ::Thrift::Struct_Union
117
+ SUCCESS = 0
118
+
119
+ FIELDS = {
120
+ SUCCESS => {:type => ::Thrift::Types::MAP, :name => 'success', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::BOOL}}
121
+ }
122
+
123
+ def struct_fields; FIELDS; end
124
+
125
+ def validate
126
+ end
127
+
128
+ ::Thrift::Struct.generate_accessors self
129
+ end
130
+
131
+ end
132
+
133
+ end
@@ -0,0 +1,21 @@
1
+ #encoding utf-8
2
+
3
+ module Iodized
4
+ class Middleware
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ req = Rack::Request.new(env)
12
+ Thread.current[:iodized_request] = req
13
+ begin
14
+ @app.call(env)
15
+ ensure
16
+ Thread.current[:yoadado_request] = nil
17
+ Thread.current[:iodized_feature_set] = nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ #encoding: utf-8
2
+
3
+ module Iodized
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iodized::Client do
4
+ # TODO this stuff needs to be rewritten now we use thrift
5
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib/")
2
+
3
+ require 'iodized'
data/tasks/thrift.rake ADDED
@@ -0,0 +1,7 @@
1
+ namespace :thrift do
2
+ desc "generate thrift boilerplate"
3
+ task :generate do
4
+ puts exec("thrift -out lib/iodized -gen rb -verbose thrift/feature.thrift")
5
+ end
6
+ end
7
+
@@ -0,0 +1,9 @@
1
+ namespace erl iodized
2
+ namespace rb Iodized
3
+
4
+ service Features {
5
+ string ping(),
6
+
7
+ map<string,bool> feature_set(1:map<string,string> state)
8
+
9
+ }
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iodized
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julian Doherty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-19 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.12.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thrift
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thin
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Iodine rich feature toggling. Lack of iodine can lead to development
112
+ delays, and stunted growth.
113
+ email:
114
+ - julian@envato.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - README.md
123
+ - Rakefile
124
+ - example/public/cool_story_bro.jpg
125
+ - example/public/cool_story_joe.jpg
126
+ - example/sinatra_iodized.rb
127
+ - example/views/cool_story.erb
128
+ - iodized.gemspec
129
+ - lib/iodized.rb
130
+ - lib/iodized/client.rb
131
+ - lib/iodized/config.rb
132
+ - lib/iodized/feature_constants.rb
133
+ - lib/iodized/feature_types.rb
134
+ - lib/iodized/features.rb
135
+ - lib/iodized/middleware.rb
136
+ - lib/iodized/version.rb
137
+ - spec/iodized/client_spec.rb
138
+ - spec/spec_helper.rb
139
+ - tasks/thrift.rake
140
+ - thrift/feature.thrift
141
+ homepage: https://github.com/envato/iodized_ruby_client
142
+ licenses:
143
+ - Copyright Envato - All rights reserved.
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.2.2
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: iodized Ruby Client
165
+ test_files:
166
+ - spec/iodized/client_spec.rb
167
+ - spec/spec_helper.rb