splicer 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- splice
1
+ splicer
data/README.md CHANGED
@@ -3,22 +3,80 @@
3
3
  Allows for interactions with multiple DNS' through one abstract API. You can use
4
4
  this to talk to one or more DNS providers if you choose.
5
5
 
6
+ > splice: join or connect (a rope or ropes) by interweaving the strands.
7
+
8
+ You are joining multiple DNS providers together. This can be used to transfer
9
+ records from one to the other without breaking the primary provider.
10
+
6
11
 
7
12
  ## Installation
8
13
 
9
14
  Add this line to your application's Gemfile:
10
15
 
11
- gem 'splicer'
16
+ ```rb
17
+ gem 'splicer'
18
+ ```
12
19
 
13
20
 
14
21
  ## Configuring
15
22
 
16
- TODO: Write this
23
+ ```rb
24
+ Splicer.configure do |config|
25
+ config.register(Splicer::Dynect.new('company','user','pass')) # gem 'splicer-dynect'
26
+ config.register(Splicer::DNSMadeEasy.new('user','pass')) # gem 'splicer-dns_made_easy'
27
+ end
28
+ ```
29
+
30
+ This library does rely on 3rd party sources, so it can and will take time to
31
+ publish the zones. It would be wise to put this into a background job.
32
+
33
+
34
+ ## Under The Hood
35
+
36
+ Splicer is a simple abstract data structure that allows you to put together DNS
37
+ zones and records quickly. The providers are what take this abstract DNS model
38
+ and turn it into the concrete model in some external API.
39
+
40
+
41
+ ### Records
42
+
43
+ All records are relative to a zone.
44
+
45
+ ```rb
46
+ record = Splicer::Records::ARecord('example.com', '127.0.0.1')
47
+ ```
48
+
49
+ ### Zones
50
+
51
+ Is a collection of records.
52
+
53
+ ```rb
54
+ zone = Splicer::Zone.new('example.com')
55
+ zone.add_record(record)
56
+ zone.publish
57
+ ```
58
+
59
+ When `Splicer::Zone#publish` is called, the provider can be passed to only push
60
+ the updates to that zone in the DNS.
61
+
62
+
63
+ ## Provider
17
64
 
65
+ Providers are adapters to a 3rd party API, such as Dynect or DNSMadeEasy. Both
66
+ API's are very different but similar in many respects.
18
67
 
19
- ## Using
68
+ If you write a provider you **MUST** follow a few rules:
20
69
 
21
- TODO: Write this
70
+ * A provider must utilize the abstract model.
71
+ * Do **NOT** monkey patch the abstract model. This can cause problems with
72
+ other provider gems, and cause the library to be unstable.
73
+ * Provide a way to build an abstract model from the concrete (3rd party)
74
+ model. This will allow for easier export to other DNS providers.
75
+ * If a provider does not have an ability to use/create a record such as a KEY
76
+ record, then ignore it.
77
+ * When publishing the zone, there should be ways to completely overwrite the
78
+ zone and merge existing records with that zone.
79
+ * Tests must be written.
22
80
 
23
81
 
24
82
  ## Contributions
@@ -0,0 +1,21 @@
1
+ module Splicer
2
+
3
+ class Configuration
4
+ def initialize
5
+ @configs = []
6
+ end
7
+
8
+ # @param [Object] config the configuration for a provider
9
+ # @return [void]
10
+ def register(config)
11
+ @configs << config
12
+ end
13
+
14
+ # Returns a list of providers.
15
+ # @return [Array] an array of providers
16
+ def providers
17
+ @configs.collect { |config| config.provider }
18
+ end
19
+ end
20
+
21
+ end
@@ -4,5 +4,11 @@ module Splicer
4
4
  class Error < StandardError
5
5
  end
6
6
 
7
+ class NotImplemented < Error
8
+ end
9
+
10
+ class RequestError < Error
11
+ end
12
+
7
13
  end
8
14
  end
@@ -1,3 +1,3 @@
1
1
  module Splicer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/splicer/zone.rb CHANGED
@@ -22,6 +22,15 @@ module Splicer
22
22
  def add_records(records)
23
23
  @records.concat(records)
24
24
  end
25
+
26
+ # @param [Symbol] method the method by which you want to publish
27
+ # @return [void]
28
+ def publish(method)
29
+ Splicer.providers.each do |provider|
30
+ provider.publish(self, method)
31
+ end
32
+ true
33
+ end
25
34
  end
26
35
 
27
36
  end
data/lib/splicer.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'splicer/version'
2
2
  require 'splicer/errors'
3
+ require 'splicer/configuration'
3
4
  require 'splicer/records'
4
5
  require 'splicer/zone'
5
- require 'splicer/provider'
6
6
 
7
7
  # Splicer is a simple DNS data structure that allows you to publish changes to
8
8
  # one or more dns services if desired.
@@ -18,46 +18,29 @@ require 'splicer/provider'
18
18
  #
19
19
  # * splicer-dynect
20
20
  # * splicer-dns_made_easy
21
+ # * splicer-no_op_provider
21
22
  #
22
23
  # == Example Configureation
23
24
  #
24
25
  # Splicer.configure do |config|
25
- # config.add_provider Splicer::Dynect('company','user','password')
26
- # config.add_provider Splicer::DNSMadeEasy('user','password')
26
+ # config.register Splicer::Dynect::Config.new('company','user','password')
27
+ # config.register Splicer::DNSMadeEasy::Config.new('user','password')
27
28
  # end
28
29
  #
29
30
  # @see Splicer::Provider for more information
30
31
  #
31
32
  # @author Matthew A. Johnston <warmwaffles@gmail.com>
32
33
  module Splicer
33
- class << self
34
- # All of the available providers
35
- @@providers = {}
34
+ @@configuration = nil
36
35
 
37
- # Configure Splicer
38
- def configure
39
- yield self
40
- end
41
- end
42
-
43
- # Add a DNS provider to your
44
- #
45
- # @raise [ArgumentError]
46
- # @param [Splicer::Provider] provider the provider you want to add
47
- # @return [Splicer::Provider]
48
- def self.register(provider)
49
- providers[provider.name] = provider
50
- end
51
-
52
- # Get a provider from the providers hash. If the provider is not found `nil`
53
- # will be returned
54
- #
55
- # @return [Splicer::Provider]
56
- def self.provider(name)
57
- providers[name]
36
+ def self.configure &block
37
+ @@configuration = Configuration.new
38
+ yield(@@configuration)
58
39
  end
59
40
 
60
41
  def self.providers
61
- @@providers ||= {}
42
+ @@configuration ||= Configuration.new
43
+ @@configuration.providers
62
44
  end
45
+
63
46
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splicer::Configuration do
4
+ let(:config) { Splicer::Configuration.new }
5
+
6
+ describe 'fields' do
7
+ it { should respond_to :providers }
8
+ end
9
+
10
+ describe '#initialize' do
11
+ subject { config }
12
+ its(:providers) { should eq([]) }
13
+ end
14
+
15
+ describe '#register' do
16
+ let(:provider) { double('Splicer::SomeProvider') }
17
+ subject { config.register(provider) }
18
+ it { should eq([provider]) }
19
+ end
20
+
21
+ describe '#providers' do
22
+ let(:one_provider) { double('Splicer::OneDNS::Provider')}
23
+ let(:two_provider) { double('Splicer::TwoDNS::Provider')}
24
+ let(:one_dns) { double('Splicer::OneDNS', provider: one_provider) }
25
+ let(:two_dns) { double('Splicer::TwoDNS', provider: two_provider) }
26
+ before do
27
+ config.register(one_dns)
28
+ config.register(two_dns)
29
+ end
30
+ subject { config.providers }
31
+ it { should eq([one_provider, two_provider])}
32
+ end
33
+ end
@@ -9,6 +9,7 @@ describe Splicer::Zone do
9
9
  it { should respond_to :name= }
10
10
  it { should respond_to :records }
11
11
  end
12
+
12
13
  describe '#initialize' do
13
14
  subject { zone }
14
15
  its(:name) { should eq('example.com') }
@@ -32,4 +33,9 @@ describe Splicer::Zone do
32
33
  end
33
34
  end
34
35
 
36
+ describe '#publish' do
37
+ subject { zone.publish(:merge) }
38
+ it { should eq(true) }
39
+ end
40
+
35
41
  end
data/spec/splicer_spec.rb CHANGED
@@ -1,31 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Splicer do
4
- let(:provider) { double('Splicer::Provider', name: 'someone') }
5
- let(:another) { double('Splicer::Provider', name: 'another') }
4
+ let(:provider) { double('Splicer::Provider', name: :someone) }
5
+ let(:another) { double('Splicer::Another', name: :another) }
6
6
 
7
7
  describe '.configure' do
8
8
  it "should accept a block" do
9
- expect {
10
- Splicer.configure do |config|
11
- end
12
- }.to_not raise_error(StandardError)
9
+ Splicer.configure do |config|
10
+ @config = config
11
+ end
12
+ expect(@config).to be_a(Splicer::Configuration)
13
+ @config = nil
13
14
  end
14
15
  end
15
16
 
16
- describe '.register' do
17
- it "should register a provider" do
18
- Splicer.register(provider)
19
- expect(Splicer.providers.count).to eq(1)
20
- end
21
- it "should register more than one provider" do
22
- Splicer.register(provider)
23
- Splicer.register(another)
24
- expect(Splicer.providers.count).to eq(2)
17
+ describe '.configuration' do
18
+ subject { Splicer.providers }
19
+
20
+ context 'when no configurations are present' do
21
+ before do
22
+ Splicer.configure do |config|
23
+ end
24
+ end
25
+ it { should eq([]) }
25
26
  end
26
- end
27
27
 
28
- describe '.provider' do
28
+ context 'when a configuration is present' do
29
+ let(:one_provider) { double('Splicer::OneDNS::Provider')}
30
+ let(:one_dns) { double('Splicer::OneDNS', provider: one_provider) }
31
+ before do
32
+ Splicer.configure do |config|
33
+ config.register(one_dns)
34
+ end
35
+ end
36
+ it { should eq([one_provider]) }
37
+ end
29
38
  end
30
39
 
31
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -75,8 +75,8 @@ files:
75
75
  - README.md
76
76
  - Rakefile
77
77
  - lib/splicer.rb
78
+ - lib/splicer/configuration.rb
78
79
  - lib/splicer/errors.rb
79
- - lib/splicer/provider.rb
80
80
  - lib/splicer/records.rb
81
81
  - lib/splicer/records/a_record.rb
82
82
  - lib/splicer/records/aaaa_record.rb
@@ -91,6 +91,7 @@ files:
91
91
  - lib/splicer/version.rb
92
92
  - lib/splicer/zone.rb
93
93
  - spec/spec_helper.rb
94
+ - spec/splicer/configuration_spec.rb
94
95
  - spec/splicer/records/a_record_spec.rb
95
96
  - spec/splicer/records/aaaa_record_spec.rb
96
97
  - spec/splicer/records/cname_record_spec.rb
@@ -119,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  segments:
121
122
  - 0
122
- hash: -20106687361328625
123
+ hash: 3236930637488513078
123
124
  required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  none: false
125
126
  requirements:
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  version: '0'
129
130
  segments:
130
131
  - 0
131
- hash: -20106687361328625
132
+ hash: 3236930637488513078
132
133
  requirements: []
133
134
  rubyforge_project:
134
135
  rubygems_version: 1.8.25
@@ -137,6 +138,7 @@ specification_version: 3
137
138
  summary: Splicer allows communication with one or more dns providers
138
139
  test_files:
139
140
  - spec/spec_helper.rb
141
+ - spec/splicer/configuration_spec.rb
140
142
  - spec/splicer/records/a_record_spec.rb
141
143
  - spec/splicer/records/aaaa_record_spec.rb
142
144
  - spec/splicer/records/cname_record_spec.rb
@@ -1,11 +0,0 @@
1
- module Splicer
2
-
3
- class Provider
4
- attr_reader :name
5
-
6
- def initialize(name)
7
- @name = name
8
- end
9
- end
10
-
11
- end