interchangeable 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cda8cd912331c11bd0ae9b3d202e2a5f351c89a4
4
+ data.tar.gz: 92d11defc20ae888d9752fc2a0c9d6c84d5af735
5
+ SHA512:
6
+ metadata.gz: 91252026af2d9053a4b3afedb6c059ed9e978f4e30787c2fcb7b826bdec6bbb88ca64152c7f2441b0c27da9adc8cec9c2e957b81ed6138a5ccc02c7b715882a5
7
+ data.tar.gz: 49bfa7e108b444af8b4849dbfa36b17ed7cff4f4b65df58a47482d245e3833cf9effdd43c81426e82625a9b2ee77f2d9c443b6a92b991a1fe7b8058079ed682c
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in interchangeable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Darren Cauthon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/MIT-license.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Scott Bellware
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Interchangeable
2
+
3
+ Create and maintain interchangeable components in Ruby.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ class MyApi
9
+ def api_key
10
+ "abc"
11
+ end
12
+ end
13
+ ```
14
+
15
+ can become
16
+
17
+ ```ruby
18
+ class MyApi
19
+ interchangeable_instance_method :api_key
20
+ end
21
+ ```
22
+
23
+ Elsewhere in your application, you can define the method like so:
24
+
25
+ ```ruby
26
+ Interchangeable.define MyApi, :api_key { 'anything' }
27
+ ```
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ gem 'interchangeable'
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install interchangeable
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'interchangeable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "interchangeable"
8
+ spec.version = Interchangeable::VERSION
9
+ spec.authors = ["Darren Cauthon"]
10
+ spec.email = ["darren@cauthon.com"]
11
+ spec.summary = %q{Create and describe interchangeable components.}
12
+ spec.description = %q{Extract interchangeable components in your application. Identify them, describe them, and allow others to swap them out easily.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Interchangeable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ require "interchangeable/version"
2
+
3
+ class Class
4
+ def interchangeable_instance_method *args, &block
5
+ Interchangeable.entries << Struct.new(:method_name, :target, :level)
6
+ .new(args[0], self, :instance)
7
+ Interchangeable.define(self, args[0], &block) if block
8
+ end
9
+ end
10
+
11
+ module Interchangeable
12
+
13
+ class << self
14
+
15
+ attr_accessor :entries
16
+ def entries
17
+ @settings ||= []
18
+ end
19
+
20
+ def define the_class, method_name, &block
21
+ the_class.instance_eval do
22
+ define_method method_name, &block
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,125 @@
1
+ require_relative 'minitest_spec'
2
+
3
+ describe Interchangeable do
4
+
5
+ before do
6
+ Interchangeable.instance_eval { @settings = nil }
7
+ end
8
+
9
+ describe "defining an instance-level method on a class" do
10
+
11
+ [
12
+ ["Blah", "something"],
13
+ ["Yawn", "applesauce"],
14
+ ].map { |x| Struct.new(:class_name, :method_name).new(*x) }.each do |example|
15
+
16
+ describe "noting the method on a class" do
17
+
18
+ before do
19
+ eval("class #{example.class_name}
20
+ interchangeable_instance_method :#{example.method_name}
21
+ end")
22
+ end
23
+
24
+ describe "entries" do
25
+
26
+ it "should create an entry" do
27
+ Interchangeable.entries.count.must_equal 1
28
+ end
29
+
30
+ it "should include the method name" do
31
+ Interchangeable.entries.first.method_name.must_equal example.method_name.to_sym
32
+ end
33
+
34
+ it "should return the target" do
35
+ Interchangeable.entries.first.target.must_equal eval(example.class_name)
36
+ end
37
+
38
+ it "should say that it's an instance method" do
39
+ Interchangeable.entries.first.level.must_equal :instance
40
+ end
41
+
42
+ end
43
+
44
+ describe "defining the method later" do
45
+
46
+ let(:the_return_value) { Object.new }
47
+
48
+ before do
49
+ object = the_return_value
50
+ Interchangeable.define(eval(example.class_name), eval(":#{example.method_name}")) { object }
51
+ end
52
+
53
+ it "should stamp the method on the object" do
54
+ instance = eval(example.class_name).new
55
+ instance.send(example.method_name.to_sym).must_be_same_as the_return_value
56
+ end
57
+
58
+ end
59
+
60
+ describe "accessing private members of the class" do
61
+
62
+ before { Interchangeable.define(eval(example.class_name), eval(":#{example.method_name}")) { @something } }
63
+
64
+ it "should be able to access the private member" do
65
+ object = Object.new
66
+
67
+ instance = eval(example.class_name).new
68
+ instance.instance_eval { @something = object }
69
+ instance.send(example.method_name.to_sym).must_be_same_as object
70
+ end
71
+
72
+ end
73
+
74
+ describe "defining the client-specific method, but with arguments" do
75
+
76
+ let(:apple) { Object.new }
77
+ let(:orange) { Object.new }
78
+
79
+ before do
80
+ Interchangeable.define(eval(example.class_name), eval(":#{example.method_name}")) do |a, b|
81
+ [a, b]
82
+ end
83
+ end
84
+
85
+ it "should allow me to call the method with arguments" do
86
+ instance = eval(example.class_name).new
87
+
88
+ result = instance.send(example.method_name.to_sym, apple, orange)
89
+ result.must_equal [apple, orange]
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ describe "noting the method on a class with a default implementation" do
97
+
98
+ ['potato', 'tomato'].each do |default_value|
99
+
100
+ describe "multiple examples" do
101
+
102
+ before do
103
+ eval("class #{example.class_name}
104
+ interchangeable_instance_method(:#{example.method_name}) { \"#{default_value}\" }
105
+ end")
106
+ end
107
+
108
+ it "should return the default value if called" do
109
+ instance = eval(example.class_name).new
110
+
111
+ result = instance.send(example.method_name.to_sym)
112
+ result.must_equal default_value
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require_relative '../lib/interchangeable'
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interchangeable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Darren Cauthon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-08 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Extract interchangeable components in your application. Identify them,
42
+ describe them, and allow others to swap them out easily.
43
+ email:
44
+ - darren@cauthon.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - MIT-license.txt
53
+ - README.md
54
+ - Rakefile
55
+ - interchangeable.gemspec
56
+ - lib/interchangeable.rb
57
+ - lib/interchangeable/version.rb
58
+ - spec/interchangeable_spec.rb
59
+ - spec/minitest_spec.rb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Create and describe interchangeable components.
84
+ test_files:
85
+ - spec/interchangeable_spec.rb
86
+ - spec/minitest_spec.rb