universum 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +4 -0
- data/README.md +1 -1
- data/lib/universum.rb +9 -0
- data/lib/universum/enum.rb +83 -0
- data/lib/universum/event.rb +60 -0
- data/lib/universum/universum.rb +0 -35
- data/lib/universum/version.rb +1 -1
- data/test/contracts/mytoken.rb +1 -1
- data/test/test_enum.rb +30 -0
- data/test/test_event.rb +38 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2c8f33d68ea490e3785c31d1cca9977af498602
|
4
|
+
data.tar.gz: d7ac8121bc501b8339954fdc0c23111c4c5d60d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbcfc8ea96b55f557636649078b665554464b5009f411cc6208890a4b4f558a633198321d796093b0b1e0cfa31bd58154064d2112576258ffdbf4ed97b065687
|
7
|
+
data.tar.gz: 03a36a8c12c2ff2e88789028b4c978c1ed3d60d909d773b1fb79592a9212b819e2712ce3e2dd82682b250d80b608c3d6cc61880ecadd589a1d14722c63f8c36d
|
data/Manifest.txt
CHANGED
@@ -4,10 +4,14 @@ Manifest.txt
|
|
4
4
|
README.md
|
5
5
|
Rakefile
|
6
6
|
lib/universum.rb
|
7
|
+
lib/universum/enum.rb
|
8
|
+
lib/universum/event.rb
|
7
9
|
lib/universum/universum.rb
|
8
10
|
lib/universum/version.rb
|
9
11
|
test/contracts/greeter.rb
|
10
12
|
test/contracts/mytoken.rb
|
11
13
|
test/helper.rb
|
14
|
+
test/test_enum.rb
|
15
|
+
test/test_event.rb
|
12
16
|
test/test_greeter.rb
|
13
17
|
test/test_version.rb
|
data/README.md
CHANGED
data/lib/universum.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
|
4
|
+
## stdlibs
|
5
|
+
require 'pp' ## pretty print (pp)
|
6
|
+
require 'digest'
|
7
|
+
|
8
|
+
|
4
9
|
## our own code
|
5
10
|
require 'universum/version' # note: let version always go first
|
6
11
|
|
12
|
+
require 'universum/enum'
|
13
|
+
require 'universum/event'
|
14
|
+
|
7
15
|
require 'universum/universum'
|
8
16
|
|
9
17
|
|
18
|
+
|
10
19
|
puts Universum.banner ## say hello
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
##################################
|
4
|
+
## auto-create/builds enum class.
|
5
|
+
##
|
6
|
+
## Example:
|
7
|
+
## State = Enum.new( :fundraising, :expired_refund, :successful)
|
8
|
+
## auto-creates/builds:
|
9
|
+
##
|
10
|
+
## class Enum
|
11
|
+
## def initialize( key, value )
|
12
|
+
## @key = key
|
13
|
+
## @value = value
|
14
|
+
## end
|
15
|
+
## end
|
16
|
+
##
|
17
|
+
## class State < Enum
|
18
|
+
##
|
19
|
+
## FUNDRAISING = new(:fundraising, 0)
|
20
|
+
## EXPIRED_REFUND = new(:expired_refund, 1)
|
21
|
+
## SUCCESSFUL = new(:successful, 2)
|
22
|
+
##
|
23
|
+
## def self.fundraising() FUNDRAISING; end
|
24
|
+
## def self.expired_refund() EXPIRED_REFUND; end
|
25
|
+
## def self.successful() SUCCESSFUL; end
|
26
|
+
##
|
27
|
+
## def fundraising?() self == FUNDRAISING; end
|
28
|
+
## def expired_refund?() self == EXPIRED_REFUND; end
|
29
|
+
## def successful?() self == SUCCESSFUL; end
|
30
|
+
## end
|
31
|
+
##
|
32
|
+
## pp state = State.fundraising #=> #<State @key=:fundraising, @value=0>
|
33
|
+
## pp state.fundraising? #=> true
|
34
|
+
## pp state.expired_refund? #=> false
|
35
|
+
## pp state.successful? #=> false
|
36
|
+
## pp state = State.expired_refund #=> #<State @key=:expired_refund, @value=1>
|
37
|
+
## pp state.fundraising? #=> false
|
38
|
+
## pp state.expired_refund? #=> true
|
39
|
+
## pp state.successful? #=> false
|
40
|
+
|
41
|
+
|
42
|
+
## base class for enum
|
43
|
+
class Enum
|
44
|
+
## return a new Enum read-only class
|
45
|
+
|
46
|
+
def initialize( key, value )
|
47
|
+
@key = key
|
48
|
+
@value = value
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
###################
|
53
|
+
## meta-programming "macro" - build class (on the fly)
|
54
|
+
def self.build_class( *keys )
|
55
|
+
klass = Class.new( Enum )
|
56
|
+
|
57
|
+
## add self.new too - note: call/forward to "old" orginal self.new of Event (base) class
|
58
|
+
klass.define_singleton_method( :new ) do |*args|
|
59
|
+
old_new( *args )
|
60
|
+
end
|
61
|
+
|
62
|
+
keys.each_with_index do |key,index|
|
63
|
+
klass.class_eval( <<RUBY )
|
64
|
+
#{key.upcase} = new( :#{key}, #{index} )
|
65
|
+
|
66
|
+
def #{key}?
|
67
|
+
self == #{key.upcase}
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.#{key}
|
71
|
+
#{key.upcase}
|
72
|
+
end
|
73
|
+
RUBY
|
74
|
+
end
|
75
|
+
|
76
|
+
klass
|
77
|
+
end
|
78
|
+
|
79
|
+
class << self
|
80
|
+
alias_method :old_new, :new # note: store "old" orginal version of new
|
81
|
+
alias_method :new, :build_class # replace original version with create
|
82
|
+
end
|
83
|
+
end # class Enum
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
##################################
|
4
|
+
## auto-create/builds struct-like class.
|
5
|
+
##
|
6
|
+
## Example:
|
7
|
+
## Roll = Event.new( :id, :rolled )
|
8
|
+
## auto-creates/builds:
|
9
|
+
##
|
10
|
+
## class Event; end
|
11
|
+
## class Roll < Event
|
12
|
+
## def initialize( id, rolled )
|
13
|
+
## @id = id
|
14
|
+
## @rolled = rolled
|
15
|
+
## end
|
16
|
+
##
|
17
|
+
## def id() @id; end
|
18
|
+
## def rolled() @rolled; end
|
19
|
+
## end
|
20
|
+
##
|
21
|
+
## pp roll = Roll.new( 1, 2345 ) #=> #<Roll @id=1, @rolled=2345>
|
22
|
+
## pp roll.id #=> 1
|
23
|
+
## pp roll.rolled #=> 2345
|
24
|
+
|
25
|
+
|
26
|
+
## base class for events
|
27
|
+
class Event
|
28
|
+
## return a new Struct-like read-only class
|
29
|
+
|
30
|
+
###################
|
31
|
+
## meta-programming "macro" - build class (on the fly)
|
32
|
+
##
|
33
|
+
def self.build_class( *fields )
|
34
|
+
klass = Class.new( Event ) do
|
35
|
+
define_method( :initialize ) do |*args|
|
36
|
+
fields.zip( args ).each do |field, arg|
|
37
|
+
instance_variable_set( "@#{field}", arg )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
fields.each do |field|
|
42
|
+
define_method( field ) do
|
43
|
+
instance_variable_get( "@#{field}" )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
## add self.new too - note: call/forward to "old" orginal self.new of Event (base) class
|
49
|
+
klass.define_singleton_method( :new ) do |*args|
|
50
|
+
old_new( *args )
|
51
|
+
end
|
52
|
+
|
53
|
+
klass
|
54
|
+
end
|
55
|
+
|
56
|
+
class << self
|
57
|
+
alias_method :old_new, :new # note: store "old" orginal version of new
|
58
|
+
alias_method :new, :build_class # replace original version with create
|
59
|
+
end
|
60
|
+
end # class Event
|
data/lib/universum/universum.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
|
4
|
-
## stdlibs
|
5
|
-
require 'pp' ## pretty print (pp)
|
6
|
-
require 'digest'
|
7
|
-
|
8
4
|
|
9
5
|
def sha256( str )
|
10
6
|
Digest::SHA256.hexdigest( str )
|
@@ -420,37 +416,6 @@ class Receipt ## transaction receipt
|
|
420
416
|
end
|
421
417
|
|
422
418
|
|
423
|
-
## base class for events
|
424
|
-
class Event
|
425
|
-
## return a new Struct-like read-only class
|
426
|
-
def self.build_class( *fields )
|
427
|
-
klass = Class.new( Event ) do
|
428
|
-
define_method( :initialize ) do |*args|
|
429
|
-
fields.zip( args ).each do |field, arg|
|
430
|
-
instance_variable_set( "@#{field}", arg )
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
fields.each do |field|
|
435
|
-
define_method( field ) do
|
436
|
-
instance_variable_get( "@#{field}" )
|
437
|
-
end
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
## add self.new too - note: call/forward to "old" orginal self.new of Event (base) class
|
442
|
-
klass.define_singleton_method( :new ) do |*args|
|
443
|
-
old_new( *args )
|
444
|
-
end
|
445
|
-
|
446
|
-
klass
|
447
|
-
end
|
448
|
-
|
449
|
-
class << self
|
450
|
-
alias_method :old_new, :new # note: store "old" orginal version of new
|
451
|
-
alias_method :new, :build_class # replace original version with create
|
452
|
-
end
|
453
|
-
end # class Event
|
454
419
|
|
455
420
|
|
456
421
|
class Universum ## Uni short for Universum
|
data/lib/universum/version.rb
CHANGED
data/test/contracts/mytoken.rb
CHANGED
data/test/test_enum.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_enum.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestEnum < MiniTest::Test
|
12
|
+
|
13
|
+
State = Enum.new( :fundraising, :expired_refund, :successful )
|
14
|
+
|
15
|
+
def test_state
|
16
|
+
pp State
|
17
|
+
|
18
|
+
state = State.fundraising
|
19
|
+
assert state.is_a?( Enum )
|
20
|
+
|
21
|
+
assert_equal true, state.fundraising?
|
22
|
+
assert_equal false, state.expired_refund?
|
23
|
+
assert_equal false, state.successful?
|
24
|
+
|
25
|
+
state = State.expired_refund
|
26
|
+
assert_equal false, state.fundraising?
|
27
|
+
assert_equal true, state.expired_refund?
|
28
|
+
assert_equal false, state.successful?
|
29
|
+
end
|
30
|
+
end # class TestEnum
|
data/test/test_event.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_event.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestEvent < MiniTest::Test
|
12
|
+
|
13
|
+
BetPlaced = Event.new( :id, :user, :cap, :amount )
|
14
|
+
Roll = Event.new( :id, :rolled )
|
15
|
+
|
16
|
+
|
17
|
+
def test_bet_placed
|
18
|
+
pp BetPlaced
|
19
|
+
|
20
|
+
bet = BetPlaced.new( 1, '0xaaaa', 2000, 100 )
|
21
|
+
|
22
|
+
assert bet.is_a?( Event )
|
23
|
+
assert_equal 1, bet.id
|
24
|
+
assert_equal '0xaaaa', bet.user
|
25
|
+
assert_equal 2000, bet.cap
|
26
|
+
assert_equal 100, bet.amount
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_roll
|
30
|
+
pp Roll
|
31
|
+
|
32
|
+
roll = Roll.new( 1, 2345 )
|
33
|
+
assert roll.is_a?( Event )
|
34
|
+
assert_equal 1, roll.id
|
35
|
+
assert_equal 2345, roll.rolled
|
36
|
+
end
|
37
|
+
|
38
|
+
end # class TestEvent
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: universum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -57,11 +57,15 @@ files:
|
|
57
57
|
- README.md
|
58
58
|
- Rakefile
|
59
59
|
- lib/universum.rb
|
60
|
+
- lib/universum/enum.rb
|
61
|
+
- lib/universum/event.rb
|
60
62
|
- lib/universum/universum.rb
|
61
63
|
- lib/universum/version.rb
|
62
64
|
- test/contracts/greeter.rb
|
63
65
|
- test/contracts/mytoken.rb
|
64
66
|
- test/helper.rb
|
67
|
+
- test/test_enum.rb
|
68
|
+
- test/test_event.rb
|
65
69
|
- test/test_greeter.rb
|
66
70
|
- test/test_version.rb
|
67
71
|
homepage: https://github.com/openblockchains/universum
|