argumenta 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70964aabded06f2363085ef1ce7620d8940a7215
4
+ data.tar.gz: 3af9f7935288a1eb391426e521baadbb23dd40af
5
+ SHA512:
6
+ metadata.gz: 94bd56c3c0a2159fd0fbc215f975e6a3401f7604d0fbb679152b4d82afecfe6d9469e614b196ced5745291b8d7d91679df521332eee7fcd5455b428f00d7a22f
7
+ data.tar.gz: fd6c2ad24514da4d4eccbb48853e808844a8cd0ffca248e02b43feae39f48c80609cb78e52c9cd71f7f4682472cefe17f1b94116505da3a6143137c0479836c1
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'dht', '>= 0.0.1'
4
+
5
+ gemspec
@@ -0,0 +1,10 @@
1
+
2
+ task :default => [:test]
3
+
4
+ task :test do |t|
5
+ $LOAD_PATH.unshift 'lib', 'test'
6
+ files = Dir.glob './test/**/test*.rb'
7
+ files.each do |f|
8
+ require f
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ require './lib/argumenta/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "argumenta"
5
+ s.version = Argumenta::VERSION
6
+ s.summary = "Social argument collaboration ~ A Ruby implementation of Argumenta's core library."
7
+ s.description = ""
8
+ s.authors = ["Tyler Florez"]
9
+ s.email = ["qualiabyte@gmail.com"]
10
+ s.homepage = "https://github.com/argumenta/argumenta"
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files`.split($/)
14
+ s.executables = `git ls-files -- bin/*`.split($/).map { |f| File.basename(f) }
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split($/)
16
+
17
+ s.add_runtime_dependency "celluloid", "= 0.14.1"
18
+ s.add_runtime_dependency "celluloid-zmq", "= 0.14.0"
19
+ s.add_runtime_dependency "dcell", "= 0.14.0"
20
+ s.add_runtime_dependency "http", "= 0.4.0"
21
+ s.add_development_dependency "bundler", "~> 1.5"
22
+ s.add_development_dependency "minitest", "~> 4.7.5"
23
+ s.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'argumenta/objects'
2
+ require 'argumenta/storage/dht'
3
+ require 'argumenta/version'
4
+
5
+ module Argumenta
6
+ include Argumenta::Objects
7
+
8
+ # Raised on failure to retrieve stored objects
9
+ class RetrievalError < Exception; end
10
+
11
+ # Raised for invalid objects during validation
12
+ class ValidationError < Exception; end
13
+
14
+ class App
15
+ def initialize
16
+ puts "Argumenta " + Argumenta::VERSION
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'argumenta/objects/argument'
2
+ require 'argumenta/objects/proposition'
3
+
4
+ module Argumenta
5
+ module Objects
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'digest'
2
+
3
+ module Argumenta
4
+ module Objects
5
+ # An argument includes a title, premises, and conclusion. It has an
6
+ # associated object record and SHA-1 hash. The object record is
7
+ # similar to Git's tree. The SHA-1 identifies the argument.
8
+ class Argument
9
+ attr_accessor :title, :premises, :conclusion
10
+
11
+ # Initializes a new argument.
12
+ #
13
+ # title = "My Argument ^_^"
14
+ # premises = [
15
+ # "The first premise!",
16
+ # "The second premise!"
17
+ # ]
18
+ # conclusion = "The conclusion."
19
+ # argument = Argument.new title, premises, conclusion
20
+ #
21
+ def initialize(title, premises, conclusion)
22
+ @title = title
23
+ @premises = premises.map { |p| Proposition.new p }
24
+ @conclusion = Proposition.new conclusion
25
+ end
26
+
27
+ # Gets the argument's object record.
28
+ #
29
+ # record = argument.record
30
+ #
31
+ def record
32
+ head = "argument\n\n"
33
+ body = "title #{@title}\n"
34
+ @premises.each do |p|
35
+ body += "premise #{p.sha1}\n"
36
+ end
37
+ body += "conclusion #{@conclusion.sha1}\n"
38
+ record = head + body
39
+ end
40
+
41
+ # Gets the argument's SHA-1.
42
+ #
43
+ # sha1 = argument.sha1
44
+ #
45
+ def sha1
46
+ Digest::SHA1.hexdigest self.record
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,85 @@
1
+ require 'digest'
2
+
3
+ module Argumenta
4
+ module Objects
5
+ # A proposition models an assertion as a string of text. It has an
6
+ # associated object record and SHA-1 hash. The object record is
7
+ # similar to Git's blob. The SHA-1 identifies the proposition.
8
+ class Proposition
9
+ attr_accessor :text, :error
10
+
11
+ # Initializes a new proposition.
12
+ #
13
+ # text = "My proposition!"
14
+ # proposition = Proposition.new text
15
+ #
16
+ def initialize(text)
17
+ @text = text
18
+ end
19
+
20
+ # Gets the proposition's object record.
21
+ #
22
+ # record = proposition.record
23
+ #
24
+ def record
25
+ "proposition " + @text
26
+ end
27
+
28
+ # Gets the proposition's SHA-1.
29
+ #
30
+ # sha1 = proposition.sha1
31
+ #
32
+ def sha1
33
+ Digest::SHA1.hexdigest self.record
34
+ end
35
+
36
+ # Validates an object as a proposition.
37
+ #
38
+ # valid = Proposition.validate object
39
+ #
40
+ # @raise [ValidationError] On failure.
41
+ def self.validate(object)
42
+ unless object.is_a? self
43
+ raise ValidationError "Object must be a proposition."
44
+ end
45
+ object.validate
46
+ end
47
+
48
+ # Validates the proposition.
49
+ #
50
+ # begin
51
+ # proposition.validate
52
+ # rescue Argumenta::ValidationError => err
53
+ # puts "Validation failed: ", err.message
54
+ # end
55
+ #
56
+ # @raise [ValidationError] On validation failure.
57
+ def validate
58
+ unless @text.is_a? String
59
+ raise ValidationError, "Proposition text must be a string."
60
+ end
61
+ unless @text.length > 0 and text.match /\S+/
62
+ raise ValidationError, "Proposition text must not be empty."
63
+ end
64
+ unless @text.length <= 240
65
+ raise ValidationError, "Proposition text must be 240 characters or less."
66
+ end
67
+ end
68
+
69
+ # Checks whether proposition is valid.
70
+ #
71
+ # valid = proposition.valid?
72
+ #
73
+ # @return [Boolean] The validation status.
74
+ def valid?
75
+ begin
76
+ self.validate
77
+ return true
78
+ rescue ValidationError => err
79
+ @error = err
80
+ return false
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,28 @@
1
+ require 'dht/hash'
2
+
3
+ module Argumenta
4
+ module Storage
5
+ # A DHT data store for Argumenta objects.
6
+ class DHT
7
+ attr_accessor :hash
8
+
9
+ def initialize(options = {})
10
+ @hash = ::DHT::Hash.new options
11
+ end
12
+
13
+ def add_proposition(proposition)
14
+ Argumenta::Proposition.validate proposition
15
+ sha1 = proposition.sha1()
16
+ @hash[sha1] = proposition.text
17
+ end
18
+
19
+ def get_proposition(sha1)
20
+ text = @hash[sha1]
21
+ unless text
22
+ raise RetrievalError, "No proposition found for '#{sha1}'."
23
+ end
24
+ proposition = Argumenta::Proposition.new text
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Argumenta
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'argumenta'
2
+ require 'test_helper'
3
+
4
+ describe Argumenta::Argument do
5
+ before do
6
+ @title = "My Argument ^_^"
7
+ @premises = [
8
+ "The first premise!",
9
+ "The second premise!"
10
+ ]
11
+ @conclusion = "The conclusion."
12
+ @argument = Argumenta::Argument.new @title, @premises, @conclusion
13
+ end
14
+
15
+ describe "initialize" do
16
+ it "should create a new argument instance" do
17
+ @argument.must_be_instance_of Argumenta::Argument
18
+ @argument.title.must_equal "My Argument ^_^"
19
+ @argument.premises.length.must_equal 2
20
+ @argument.premises[0].text.must_equal "The first premise!"
21
+ @argument.premises[1].text.must_equal "The second premise!"
22
+ @argument.conclusion.text.must_equal "The conclusion."
23
+ end
24
+ end
25
+
26
+ describe "record" do
27
+ it "should get the argument's object record" do
28
+ record = @argument.record
29
+ record.must_equal <<-END.gsub(/^ +/, '')
30
+ argument
31
+
32
+ title My Argument ^_^
33
+ premise 37ca8beaaac1d1b8412c9fb1fd73e524c9862ebe
34
+ premise 29da59119a5c3cec4f7b339433e8931ea99771cf
35
+ conclusion 3940b2a6a3d5778297f0e37a06109f9d3dcffe6d
36
+ END
37
+ end
38
+ end
39
+
40
+ describe "sha1" do
41
+ it "should get the argument's SHA-1" do
42
+ sha1 = @argument.sha1
43
+ sha1.must_equal "50250211801dabf9cbf0e574af270ba2c3fe83cb"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ require 'argumenta'
2
+ require 'test_helper'
3
+
4
+ describe Argumenta::Proposition do
5
+ before do
6
+ @text = "My proposition!"
7
+ @proposition = Argumenta::Proposition.new @text
8
+ end
9
+
10
+ describe "initialize" do
11
+ it "should create a new proposition instance" do
12
+ @proposition.must_be_instance_of Argumenta::Proposition
13
+ @proposition.text.must_equal "My proposition!"
14
+ end
15
+ end
16
+
17
+ describe "record" do
18
+ it "should get the proposition's object record" do
19
+ record = @proposition.record
20
+ record.must_equal "proposition My proposition!"
21
+ end
22
+ end
23
+
24
+ describe "sha1" do
25
+ it "should get the proposition's SHA-1" do
26
+ sha1 = @proposition.sha1
27
+ sha1.must_equal "fe1d2c8da97cd63ff28f9a1a3598fe29def216dd"
28
+ end
29
+ end
30
+
31
+ describe "valid?" do
32
+ it "should return true when valid" do
33
+ @proposition.valid?.must_equal true
34
+ end
35
+
36
+ it "should return false when not a string" do
37
+ proposition = Argumenta::Proposition.new 1
38
+ proposition.valid?.must_equal false
39
+ end
40
+
41
+ it "should return false when empty" do
42
+ proposition = Argumenta::Proposition.new ""
43
+ proposition.valid?.must_equal false
44
+ end
45
+
46
+ it "should return false when over max length" do
47
+ text = "a" * 241
48
+ proposition = Argumenta::Proposition.new text
49
+ proposition.valid?.must_equal false
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ require 'argumenta'
2
+ require 'test_helper'
3
+
4
+ describe Argumenta::Storage::DHT do
5
+ options = {
6
+ host: "127.0.0.1",
7
+ port: 3033,
8
+ name: "test"
9
+ }
10
+ store = Argumenta::Storage::DHT.new options
11
+
12
+ before do
13
+ @store = store
14
+ @text = "My proposition!"
15
+ @proposition = Argumenta::Proposition.new @text
16
+ end
17
+
18
+ describe "initialize" do
19
+ it "should create a new dht storage instance" do
20
+ @store.must_be_instance_of Argumenta::Storage::DHT
21
+ end
22
+ end
23
+
24
+ describe "add_proposition" do
25
+ it "should add a proposition to the store" do
26
+ @store.add_proposition @proposition
27
+ retrieved = @store.get_proposition @proposition.sha1
28
+ retrieved.text.must_equal @proposition.text
29
+ end
30
+ end
31
+
32
+ describe "get_proposition" do
33
+ it "should get a proposition from the store by sha1" do
34
+ @store.add_proposition @proposition
35
+ sha1 = @proposition.sha1
36
+ retrieved = @store.get_proposition sha1
37
+ retrieved.text.must_equal @proposition.text
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ require 'argumenta'
2
+ require 'test_helper'
3
+
4
+ describe Argumenta do
5
+ it "should have a version string" do
6
+ Argumenta::VERSION.must_match /^\d+.\d+.\d+$/
7
+ end
8
+ end
9
+
10
+ describe Argumenta::App do
11
+ before do
12
+ @app = Argumenta::App.new
13
+ end
14
+
15
+ describe "initialize" do
16
+ it "should create a new argumenta instance" do
17
+ @app.must_be_instance_of Argumenta::App
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'celluloid'
4
+
5
+ Celluloid.logger = ::Logger.new("test.log")
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: argumenta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Florez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: celluloid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.14.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: celluloid-zmq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.14.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dcell
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.14.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.14.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 4.7.5
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 4.7.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ''
112
+ email:
113
+ - qualiabyte@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - Rakefile
121
+ - argumenta.gemspec
122
+ - lib/argumenta.rb
123
+ - lib/argumenta/objects.rb
124
+ - lib/argumenta/objects/argument.rb
125
+ - lib/argumenta/objects/proposition.rb
126
+ - lib/argumenta/storage/dht.rb
127
+ - lib/argumenta/version.rb
128
+ - test/objects/test_argument.rb
129
+ - test/objects/test_proposition.rb
130
+ - test/storage/test_dht.rb
131
+ - test/test_argumenta.rb
132
+ - test/test_helper.rb
133
+ homepage: https://github.com/argumenta/argumenta
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.0.3
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Social argument collaboration ~ A Ruby implementation of Argumenta's core
157
+ library.
158
+ test_files: []