consensus 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDVjNDRhNGQwNTQ1YjBlNWJiZTU1YmNmOTYyNWJlYjUxNjhiYmQ0Mg==
5
+ data.tar.gz: !binary |-
6
+ MDY2NzRlZjMyMGU2YmNhNjYyYTQ3YjIzMTYyYjQ2NzNlNzdkZWVlMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDYyYWM0ZGRjMzE1YzExMDZiMTlkNzM3YTcyZGY4YzY2NTE2MDYzMGU3MjM0
10
+ NTI3OGYzMGI4MGQyMDgwMmY1ZTE2YjYyNTI0Y2IyMWE1OTcwZDQ4NDZiNDJm
11
+ ODVlZjBmMjJlNzc5MDlmMDBlMDVlMWRlNjczODBiM2I0Y2JlZGI=
12
+ data.tar.gz: !binary |-
13
+ Nzc5MmMwYjI4ZjAzYjc2NGM2ZGVlMTZlNzU5Y2NmMTUwMmUyYTI5MTIxYjhh
14
+ Nzc2OWRkMWUzODlhM2Q4NGY5NTI1NWI5MTQyYTcyMGU5NTFmYWI4YTI4ZGI3
15
+ MzI0NDdkODE2OGQ3YzkxMTM5NDBmMGVjZjU3YTdlMmE1NmRhMWQ=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .ruby-version
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in consensus.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Steve Jorgensen
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/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Consensus
2
+
3
+ The purpose of this gem is to facilitate the construction of Ruby
4
+ programs with robust, high-value tests through the creation of
5
+ data classes with specific APIs that are used both in production
6
+ and as test doubles in tests.
7
+
8
+ A problem that frequently arises when testing code in a dynamic
9
+ language such as Ruby is that there is nothing to ensure that
10
+ the APIs of test double objects (mocks and stubs) implemnt the
11
+ same APIs as the objects that will be given to the code under test
12
+ and that this remains true as the code changes over time.
13
+
14
+ That situation can be improved through the use of simple struct-
15
+ like objects to pass data around, but those objects can be a poor
16
+ fit in many cases such as a view model that exposes data that will
17
+ not necessarily be consumed and is costly to produce.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'consensus'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install consensus
32
+
33
+ ## Usage
34
+
35
+ Declare a new class that extends Consensus::Portrayal and define
36
+ one or more portrayal attributes using the "attribute" class
37
+ method.
38
+
39
+ class Data < Consensus::Portrayal
40
+ attribute :name, :points, :admin?
41
+ end
42
+
43
+ Assign simple values or callable objects to attributes of an
44
+ instance of the class.
45
+
46
+ class UserFetcher
47
+ attr_reader :name
48
+
49
+ def initialize(name)
50
+ @name = name
51
+ end
52
+
53
+ def user_data
54
+ data = Data.new
55
+ data.name = name
56
+ data.points = ->{ user_record.points }
57
+ admin = ->{ user_record.admin? }
58
+ return data
59
+ end
60
+
61
+ private
62
+
63
+ def user_record
64
+ User.where(name: name).first
65
+ end
66
+ end
67
+
68
+ TODO: Write usage instructions here
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( http://github.com/<my-github-username>/consensus/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -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
data/consensus.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'consensus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "consensus"
8
+ spec.version = Consensus::VERSION
9
+ spec.authors = ["Steve Jorgensen"]
10
+ spec.email = ["stevej@stevej.name"]
11
+ spec.summary = %q{A data transfer object that can have lazy attributes.}
12
+ spec.description = %q{A data transfer object that can have lazy attributes.}
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.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,30 @@
1
+ module Consensus
2
+ class Portrayal
3
+
4
+ class << self
5
+
6
+ def attribute(*names)
7
+ names.each do |n| ; define_attribute(n) ; end
8
+ end
9
+
10
+ private
11
+
12
+ def define_attribute name
13
+ base_name = name.to_s.sub(/\?$/, '')
14
+ attr_writer base_name
15
+
16
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
17
+ def #{name}
18
+ if @#{base_name}.respond_to?(:call)
19
+ @#{base_name} = @#{base_name}.call
20
+ else
21
+ @#{base_name}
22
+ end
23
+ end
24
+ EOS
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Consensus
2
+ VERSION = "0.0.1"
3
+ end
data/lib/consensus.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "consensus/version"
2
+ require "consensus/portrayal"
3
+
4
+ module Consensus
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Consensus::Portrayal do
4
+ describe '.attribute' do
5
+ let(:instance){ klass.new }
6
+
7
+ describe "given a simple attribute name" do
8
+ let(:klass){ Class.new(described_class) do
9
+ attribute :the_attribute
10
+ end }
11
+
12
+ it "defines the named settable/gettable attribute" do
13
+ instance.the_attribute = :some_value
14
+ expect( instance.the_attribute ).to eq(:some_value)
15
+ end
16
+ end
17
+
18
+ describe "given a name ending in \"?\"" do
19
+ let(:klass){ Class.new(described_class) do
20
+ attribute :ya_think?
21
+ end }
22
+
23
+ it "defines a non-\"?\" setter with a \"?\" getter" do
24
+ instance.ya_think = :yes_i_do
25
+ expect( instance.ya_think? ).to eq(:yes_i_do)
26
+ end
27
+ end
28
+
29
+ describe "given multiple attribute names" do
30
+ let(:klass){ Class.new(described_class) do
31
+ attribute :a1, :a2, :a3
32
+ end }
33
+
34
+ it "defines all of the named attributes" do
35
+ i = instance
36
+ i.a1, i.a2, i.a3 = 1, 2, 3
37
+ expect( [i.a1, i.a2, i.a3] ).to eq( [1, 2, 3] )
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "an instance attribute defined using .attribute" do
43
+ subject{ klass.new }
44
+ let(:klass){ Class.new(described_class) do
45
+ attribute :an_attribute
46
+ end }
47
+
48
+ describe "when assigned a callable object" do
49
+ let(:callable){ double(:callable) }
50
+
51
+ before do
52
+ subject.an_attribute = callable
53
+ end
54
+
55
+ it "gets the result of #call on the assigned object" do
56
+ allow( callable ).to receive(:call).and_return :call_result
57
+ expect( subject.an_attribute ).to eq( :call_result )
58
+ end
59
+
60
+ it "reuses the previous #call result for subsequent gets" do
61
+ expect( callable ).to receive(:call).once.and_return :call_result
62
+ expect( subject.an_attribute ).to eq( :call_result )
63
+ expect( subject.an_attribute ).to eq( :call_result )
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Consensus do
4
+ it 'should have a version number' do
5
+ Consensus::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'consensus'
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: consensus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steve Jorgensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-11 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ description: A data transfer object that can have lazy attributes.
56
+ email:
57
+ - stevej@stevej.name
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - consensus.gemspec
70
+ - lib/consensus.rb
71
+ - lib/consensus/portrayal.rb
72
+ - lib/consensus/version.rb
73
+ - spec/consensus/portrayal_spec.rb
74
+ - spec/consensus_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A data transfer object that can have lazy attributes.
100
+ test_files:
101
+ - spec/consensus/portrayal_spec.rb
102
+ - spec/consensus_spec.rb
103
+ - spec/spec_helper.rb