unionvalue 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29ad9b35c9f8aaea27e10cc6b51a73156ba68c53
4
+ data.tar.gz: 62c24bd969deb6dabd3626daf3bd811fd99f515c
5
+ SHA512:
6
+ metadata.gz: 7f4c84e397495cce2b60fa91146a8d625c150b3e7904b0f6290367c7dc861214e8fedd04b4350f9750c1487b5b2830f5b9464d97ecb3ff2a63241da87dfe2b71
7
+ data.tar.gz: ebc6be91d6bbfaaf057730eaf83f9bd5c000bfaa1ce6df5b4ec70c578f3bb20f5d8bf4827640f28e69a47bafd935f11fe355b38360efe52a67fd8c52148b421c
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rake"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "rspec", "~> 2.11.0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.8)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.1.3)
9
+ faraday (0.9.1)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.2.9.1)
12
+ github_api (0.12.3)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.4)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 3.3)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.3)
19
+ oauth2
20
+ hashie (3.4.1)
21
+ highline (1.7.2)
22
+ jeweler (2.0.1)
23
+ builder
24
+ bundler (>= 1.0)
25
+ git (>= 1.2.5)
26
+ github_api
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.5.10)
29
+ rake
30
+ rdoc
31
+ json (1.8.2)
32
+ jwt (1.4.1)
33
+ mini_portile (0.6.2)
34
+ multi_json (1.11.0)
35
+ multi_xml (0.5.5)
36
+ multipart-post (2.0.0)
37
+ nokogiri (1.6.6.2)
38
+ mini_portile (~> 0.6.0)
39
+ oauth2 (1.0.0)
40
+ faraday (>= 0.8, < 0.10)
41
+ jwt (~> 1.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ rack (1.6.0)
46
+ rake (10.4.2)
47
+ rdoc (3.12.2)
48
+ json (~> 1.4)
49
+ rspec (2.11.0)
50
+ rspec-core (~> 2.11.0)
51
+ rspec-expectations (~> 2.11.0)
52
+ rspec-mocks (~> 2.11.0)
53
+ rspec-core (2.11.1)
54
+ rspec-expectations (2.11.3)
55
+ diff-lcs (~> 1.1.3)
56
+ rspec-mocks (2.11.3)
57
+ thread_safe (0.3.5)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.0)
64
+ jeweler (~> 2.0.1)
65
+ rake
66
+ rdoc (~> 3.12)
67
+ rspec (~> 2.11.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Axis Sivitz
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,20 @@
1
+ # unionvalue
2
+
3
+ Allows easy creation of immutable union values, a.k.a. sum-types.
4
+
5
+ Example:
6
+
7
+ ```
8
+ APICallResult = UnionValue.new(:success, :failure, :timeout)
9
+ APICallResult.failure.is_failure? #=> true
10
+ APICallResult.timeout.is_success? #=> false
11
+ APICallResult.success(12345).data #=> 12345
12
+ ```
13
+
14
+ Read more about sum-types here: https://en.wikipedia.org/wiki/Sum_type
15
+
16
+ ## Copyright
17
+
18
+ Copyright (c) 2015 Axis Sivitz. See LICENSE.txt for
19
+ further details.
20
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "unionvalue"
18
+ gem.homepage = "http://github.com/asivitz/unionvalue"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Immutable union values}
21
+ gem.description = <<HERE
22
+ Allows easy creation of immutable union values, a.k.a. sum-types.
23
+
24
+ Example:
25
+ APICallResult = UnionValue.new(:success, :failure, :timeout)
26
+ APICallResult.failure.is_failure? #=> true
27
+ APICallResult.timeout.is_success? #=> false
28
+ APICallResult.success(12345).data #=> 12345
29
+ HERE
30
+ gem.email = "aosivitz@gmail.com"
31
+ gem.authors = ["Axis Sivitz"]
32
+ # dependencies defined in Gemfile
33
+ end
34
+ Jeweler::RubygemsDotOrgTasks.new
35
+
36
+ require 'rspec/core/rake_task'
37
+ RSpec::Core::RakeTask.new(:spec)
38
+ task :default => :spec
39
+
40
+ require 'rdoc/task'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "unionvalue #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/unionvalue.rb ADDED
@@ -0,0 +1,38 @@
1
+ class UnionValue
2
+ def self.new(*values, &block)
3
+
4
+ Class.new do
5
+ attr_accessor(:type, :data, *values)
6
+
7
+ values.each do |value|
8
+ define_singleton_method(value) do |*val|
9
+ a = self.new
10
+ a.data = val.first if val
11
+ a.type = value
12
+ a.freeze
13
+ a
14
+ end
15
+
16
+ define_method(:"is_#{value}?") do
17
+ type == value
18
+ end
19
+ end
20
+
21
+ const_set :VALUES, values
22
+
23
+ def ==(other)
24
+ eql?(other)
25
+ end
26
+
27
+ def eql?(other)
28
+ self.class == other.class && self.type == other.type && self.data == other.data
29
+ end
30
+
31
+ def inspect
32
+ "#<#{self.class.name} #{self.type}:#{self.data}>"
33
+ end
34
+
35
+ class_eval &block if block
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'unionvalues'
5
+ # Requires supporting files with custom matchers and macros, etc,
6
+ # in ./support/ and its subdirectories.
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+ RSpec.configure do |config|
9
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/unionvalue')
2
+ describe 'unionvalues' do
3
+
4
+ Thing = UnionValue.new(:one, :two, :three)
5
+ val = 12345
6
+ one = Thing.one
7
+ two = Thing.two
8
+ three = Thing.three(val)
9
+
10
+ it 'defines constructors' do
11
+ one.is_one?.should == true
12
+ two.is_one?.should == false
13
+ three.is_three?.should == true
14
+ three.data.should == val
15
+ end
16
+
17
+ it 'allows equality' do
18
+ one.should == Thing.one
19
+ three.should == Thing.three(val)
20
+ one.should_not == two
21
+ three.should_not == Thing.three(23819)
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unionvalue
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Axis Sivitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.11.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.11.0
83
+ description: "Allows easy creation of immutable union values, a.k.a. sum-types.\n\nExample:
84
+ \nAPICallResult = UnionValue.new(:success, :failure, :timeout)\nAPICallResult.failure.is_failure?
85
+ #=> true\nAPICallResult.timeout.is_success? #=> false\nAPICallResult.success(12345).data
86
+ #=> 12345\n"
87
+ email: aosivitz@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files:
91
+ - LICENSE.txt
92
+ - README.md
93
+ files:
94
+ - .document
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - VERSION
101
+ - lib/unionvalue.rb
102
+ - spec/spec_helper.rb
103
+ - spec/unionvalue_spec.rb
104
+ homepage: http://github.com/asivitz/unionvalue
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Immutable union values
128
+ test_files: []