record_on_chain 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +172 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rochain +5 -0
- data/lib/record_on_chain/cli.rb +140 -0
- data/lib/record_on_chain/command_loader.rb +20 -0
- data/lib/record_on_chain/commands/abstract_command.rb +55 -0
- data/lib/record_on_chain/commands/help.rb +50 -0
- data/lib/record_on_chain/commands/init.rb +150 -0
- data/lib/record_on_chain/commands/mod_command.rb +38 -0
- data/lib/record_on_chain/commands/record.rb +163 -0
- data/lib/record_on_chain/commands/secret.rb +57 -0
- data/lib/record_on_chain/config.rb +12 -0
- data/lib/record_on_chain/constants.rb +21 -0
- data/lib/record_on_chain/crypto/aes.rb +51 -0
- data/lib/record_on_chain/crypto/cryptor.rb +60 -0
- data/lib/record_on_chain/crypto/default_cryptor.rb +12 -0
- data/lib/record_on_chain/datafile_base.rb +101 -0
- data/lib/record_on_chain/keyfile.rb +14 -0
- data/lib/record_on_chain/nem_controller.rb +113 -0
- data/lib/record_on_chain/utils.rb +44 -0
- data/lib/record_on_chain/version.rb +3 -0
- data/lib/record_on_chain.rb +21 -0
- data/lib/resources/preset_mainnet_nodes +45 -0
- data/lib/resources/preset_testnet_nodes +1 -0
- data/record_on_chain.gemspec +46 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a055bd220e515642030d9ead2e3b1eea3f0d14269f1cdb4618f1471742cae0d1
|
4
|
+
data.tar.gz: 6dd31036fb75b2bafebddacabf95c7b325d9e589fb3ef9020fc2cf4bff13408b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34c114a61d4aeab9c56694626d76d7b1633a59be22e82fe9d72af012f5cbe08b0f1d4f69014474116c0dff53bba62226d30dfff2f49767060fb25fb18a23aa87
|
7
|
+
data.tar.gz: 17d196217781e6849c6ad9ac6771afab1227cde1300bac97dcd77a506d08f9aee391c1e1af47421ba253719897261ecec0d442c75b68e8fd01558bbbb166ffa5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at mijinco1024+git@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
record_on_chain (0.1.0)
|
5
|
+
highline (= 2.0.0)
|
6
|
+
nem-ruby (~> 0.0.12)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.6.0)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
base32 (0.3.2)
|
14
|
+
crack (0.4.3)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
digest-sha3 (1.1.0)
|
18
|
+
faraday (0.15.4)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
faraday_middleware (0.13.0)
|
21
|
+
faraday (>= 0.7.4, < 1.0)
|
22
|
+
hashdiff (0.3.8)
|
23
|
+
highline (2.0.0)
|
24
|
+
multipart-post (2.0.0)
|
25
|
+
nem-ruby (0.0.12)
|
26
|
+
base32 (~> 0.3)
|
27
|
+
digest-sha3 (~> 1.1)
|
28
|
+
faraday (~> 0.11)
|
29
|
+
faraday_middleware (~> 0.11)
|
30
|
+
public_suffix (3.0.3)
|
31
|
+
rake (10.5.0)
|
32
|
+
rspec (3.8.0)
|
33
|
+
rspec-core (~> 3.8.0)
|
34
|
+
rspec-expectations (~> 3.8.0)
|
35
|
+
rspec-mocks (~> 3.8.0)
|
36
|
+
rspec-core (3.8.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-expectations (3.8.2)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-mocks (3.8.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.8.0)
|
44
|
+
rspec-support (3.8.0)
|
45
|
+
safe_yaml (1.0.4)
|
46
|
+
webmock (3.5.1)
|
47
|
+
addressable (>= 2.3.6)
|
48
|
+
crack (>= 0.3.2)
|
49
|
+
hashdiff
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
bundler (~> 2.0)
|
56
|
+
rake (~> 10.0)
|
57
|
+
record_on_chain!
|
58
|
+
rspec (~> 3.0)
|
59
|
+
webmock (~> 3.5.1)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 MIJ
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# RecordOnChain
|
2
|
+
|
3
|
+
You can record data on the **nem (NIS1)** chain by an operation like Git push.
|
4
|
+
|
5
|
+
To use this gem you need xem to be consumed as a fee.
|
6
|
+
|
7
|
+
**Data written by using this gem will be exposed without hiding it in the block chain.**
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem install record_on_chain
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
#### Procedure
|
16
|
+
|
17
|
+
1. init
|
18
|
+
2. record / secret
|
19
|
+
|
20
|
+
And you can use `help` command.
|
21
|
+
|
22
|
+
```
|
23
|
+
$ bundle exec rochain help
|
24
|
+
|
25
|
+
== Record on Chain HELP ==
|
26
|
+
|
27
|
+
descriptions
|
28
|
+
init : initialize RecordOnChain
|
29
|
+
record : record message on nem(ver-1) chain
|
30
|
+
secret : recover secret from keyfile
|
31
|
+
help : display usage
|
32
|
+
|
33
|
+
...
|
34
|
+
```
|
35
|
+
|
36
|
+
#### init
|
37
|
+
|
38
|
+
```
|
39
|
+
$ bundle exec rochain init
|
40
|
+
```
|
41
|
+
|
42
|
+
This command generates `keyfile` and `configfile`. By default, these files are generated in the `$HOME/.ro_chain` directory.
|
43
|
+
|
44
|
+
`default`
|
45
|
+
```
|
46
|
+
root
|
47
|
+
└ home
|
48
|
+
└ user_dir
|
49
|
+
└ .ro_chain
|
50
|
+
├ default_key.yml
|
51
|
+
└ default_config.yml
|
52
|
+
```
|
53
|
+
|
54
|
+
When you use `-p` option.
|
55
|
+
`-p /home/user_dir/my_dir`
|
56
|
+
|
57
|
+
```
|
58
|
+
root
|
59
|
+
└ home
|
60
|
+
└ user_dir
|
61
|
+
└ my_dir
|
62
|
+
└ .ro_chain
|
63
|
+
├ default_key.yml
|
64
|
+
└ default_config.yml
|
65
|
+
```
|
66
|
+
|
67
|
+
`keyfile`
|
68
|
+
Information such as encrypted secret key is written in the key file. **Please note that the private key is not encrypted if the password is empty.**
|
69
|
+
|
70
|
+
`configfile`
|
71
|
+
Information such as the destination of the data is written in the config file.
|
72
|
+
|
73
|
+
The meaning of each item of the config file is as follows.
|
74
|
+
|
75
|
+
- :keyfile_path: << path of keyfile >>
|
76
|
+
- :recipient: << recipient address >>
|
77
|
+
- :add_node: << additional node >>
|
78
|
+
|
79
|
+
`RecordOnChain` sends the transaction preferentially to the node at the address written in `add_node`.
|
80
|
+
|
81
|
+
**The format of the key file and config file is yaml.**
|
82
|
+
|
83
|
+
```
|
84
|
+
# sample
|
85
|
+
|
86
|
+
:keyfile_path: XXX
|
87
|
+
:recipient: XXX
|
88
|
+
:add_node:
|
89
|
+
- http://127.0.0.1:7890
|
90
|
+
```
|
91
|
+
|
92
|
+
#### record
|
93
|
+
|
94
|
+
```
|
95
|
+
$ bundle exec rochain record -m good_luck!
|
96
|
+
|
97
|
+
- Please enter your password
|
98
|
+
**************
|
99
|
+
!! confirm !!
|
100
|
+
sender : XXX
|
101
|
+
recipient : XXX
|
102
|
+
data : good_luck!
|
103
|
+
fee : XXX xem
|
104
|
+
|
105
|
+
Are you sure you want to record? (y)es or (n)o
|
106
|
+
y
|
107
|
+
Exit NOMAL : record command execution succeede.
|
108
|
+
tx_hash [ XXX ]
|
109
|
+
```
|
110
|
+
|
111
|
+
By default, this command reads the configuration file in `$HOME/.ro_chain/default_config.yml`.
|
112
|
+
|
113
|
+
If you want to use the specified file, you need to use the option.
|
114
|
+
|
115
|
+
e.g. `$HOME/user_dir/my_dir/.ro_chain/my_config.yml`
|
116
|
+
```
|
117
|
+
$ bundle exec rochain record -p $HOME/user_dir/my_dir -c my_config.yml -m good_luck!
|
118
|
+
```
|
119
|
+
|
120
|
+
#### secret
|
121
|
+
|
122
|
+
Restore the private key from the key file. You will need a password to restore.
|
123
|
+
|
124
|
+
```
|
125
|
+
$ bundle exec rochain secret
|
126
|
+
|
127
|
+
- Please enter your password
|
128
|
+
**************
|
129
|
+
Exit NOMAL : secret command execution succeede.
|
130
|
+
Secret [ XXX ]
|
131
|
+
```
|
132
|
+
|
133
|
+
By default, this command reads the configuration file in `$HOME/.ro_chain/default_key.yml`.
|
134
|
+
|
135
|
+
If you want to use the specified file, you need to use the option.
|
136
|
+
|
137
|
+
e.g. `$HOME/user_dir/my_dir/.ro_chain/my_key.yml`
|
138
|
+
```
|
139
|
+
$ bundle exec rochain secret -k $HOME/user_dir/my_dir/.ro_chain/my_key.yml
|
140
|
+
```
|
141
|
+
|
142
|
+
## Development
|
143
|
+
|
144
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
145
|
+
|
146
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
147
|
+
|
148
|
+
## Dependencies
|
149
|
+
|
150
|
+
**highline**
|
151
|
+
|
152
|
+
https://github.com/JEG2/highline
|
153
|
+
|
154
|
+
**nem-ruby**
|
155
|
+
|
156
|
+
https://github.com/44uk/nem-ruby
|
157
|
+
|
158
|
+
I also use the source code of the above repository for testing.
|
159
|
+
|
160
|
+
___Thank you your development!___
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/record_on_chain. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
165
|
+
|
166
|
+
## License
|
167
|
+
|
168
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
169
|
+
|
170
|
+
## Code of Conduct
|
171
|
+
|
172
|
+
Everyone interacting in the RecordOnChain project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/record_on_chain/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "record_on_chain"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/rochain
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require "highline"
|
2
|
+
|
3
|
+
module RecordOnChain
|
4
|
+
class Cli
|
5
|
+
def initialize( input=$stdin , output=$stdout )
|
6
|
+
@input = input
|
7
|
+
@output = output
|
8
|
+
end
|
9
|
+
|
10
|
+
def in ; return @input ; end
|
11
|
+
def out; return @output; end
|
12
|
+
|
13
|
+
ATTR_OFF = "\e[0m".freeze
|
14
|
+
|
15
|
+
ENHANCE = "\e[1m".freeze
|
16
|
+
# style : bold
|
17
|
+
|
18
|
+
UNDERLINE = "\e[4m".freeze
|
19
|
+
# style : underline
|
20
|
+
|
21
|
+
ERROR = "\e[31m\e[1m".freeze
|
22
|
+
# color : red
|
23
|
+
# style : bold
|
24
|
+
|
25
|
+
SUCCESS = "\e[32m\e[1m".freeze
|
26
|
+
# color : green
|
27
|
+
# style : bold
|
28
|
+
|
29
|
+
CAUTION = "\e[43m\e[30m\e[1m".freeze
|
30
|
+
# background : yellow
|
31
|
+
# color : black
|
32
|
+
# style : bold
|
33
|
+
|
34
|
+
ATTENTION = "\e[40m\e[36m\e[1m"
|
35
|
+
# background : black 40
|
36
|
+
# char : cyan 36
|
37
|
+
# others : bold 1
|
38
|
+
|
39
|
+
attributes = [ "enhance", "underline", "error", "success", "caution", "attention" ]
|
40
|
+
attributes.each do |attr|
|
41
|
+
const = self.const_get( attr.upcase )
|
42
|
+
# def enhance_str( str )
|
43
|
+
# ENHANCE + str + ATTR_OFF
|
44
|
+
# end
|
45
|
+
define_method( "#{attr}_str" ){ |str| const + str + ATTR_OFF }
|
46
|
+
# def puts_enhance_msg( msg )
|
47
|
+
# puts( enhance_str( msg ) )
|
48
|
+
# end
|
49
|
+
define_method( "puts_#{attr}_msg" ){ |msg| @output.puts( send( "#{attr}_str" , msg ) ) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def blank_line( size= 1 )
|
53
|
+
puts( "\n"*size )
|
54
|
+
end
|
55
|
+
|
56
|
+
def agree( what )
|
57
|
+
return get_highline.agree( "Are you sure you want to #{what}? (y)es or (n)o" )
|
58
|
+
end
|
59
|
+
|
60
|
+
def decide_password
|
61
|
+
user_password = password_operation_base( 5 )do |answer|
|
62
|
+
# Enter pass again to see if it is equal
|
63
|
+
conf_answer = get_highline.ask("- Please enter your password again (confirm)"){ |q| q.echo = "*" }
|
64
|
+
answer == conf_answer
|
65
|
+
end
|
66
|
+
return user_password
|
67
|
+
end
|
68
|
+
|
69
|
+
def encrypt_with_password( decrypt_func )
|
70
|
+
decrypted_secret = password_operation_base( 3 ) do |attempt|
|
71
|
+
decrypted = decrypt_func.call( attempt )
|
72
|
+
if decrypted.empty? then
|
73
|
+
false # failure
|
74
|
+
else
|
75
|
+
# you can get decrypted data from attempt after valid_process
|
76
|
+
attempt.replace( decrypted )
|
77
|
+
true # success
|
78
|
+
end
|
79
|
+
end
|
80
|
+
return decrypted_secret
|
81
|
+
end
|
82
|
+
|
83
|
+
def puts_hash( hash , attribute= nil, indent= 0 )
|
84
|
+
formatted = format_hash( hash , indent )
|
85
|
+
formatted = send( "#{attribute}_str" , formatted ) unless attribute.nil?
|
86
|
+
@output.puts( formatted )
|
87
|
+
end
|
88
|
+
|
89
|
+
# [ example ]
|
90
|
+
# {alice:"alice",bob:"bob",dylan:"dylan",carol:"carol"}
|
91
|
+
#
|
92
|
+
# alice : alice
|
93
|
+
# bob : bob
|
94
|
+
# dylan : dylan
|
95
|
+
# carol : carol
|
96
|
+
def format_hash( hash, indent= 0, split_word=" : " )
|
97
|
+
# get max :key word length
|
98
|
+
max_key_length = hash.map{ |pair| pair.first.size }.max{ |a,b| a <=> b }
|
99
|
+
# initialize output
|
100
|
+
output = ""
|
101
|
+
hash.each do |key,val|
|
102
|
+
output << " " * indent
|
103
|
+
output << padding( key.to_s , max_key_length )
|
104
|
+
output << split_word
|
105
|
+
output << val.to_s
|
106
|
+
output << "\n"
|
107
|
+
end
|
108
|
+
return output
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def get_highline
|
114
|
+
return HighLine.new( @input, @output )
|
115
|
+
end
|
116
|
+
|
117
|
+
# If you want to exit this method when password is valid,
|
118
|
+
# you should use "return" in valid_process block.
|
119
|
+
def password_operation_base( attempts_count, &valid_process )
|
120
|
+
1.step do |count|
|
121
|
+
# incorrect many times
|
122
|
+
return nil if count > attempts_count
|
123
|
+
# user enter pass here
|
124
|
+
answer = get_highline.ask("- Please enter your password"){ |q| q.echo = "*" }
|
125
|
+
# valid process
|
126
|
+
return answer if valid_process.call( answer )
|
127
|
+
# If it is empty, the attempt is incorrect.
|
128
|
+
puts_enhance_msg( "Your passwords don't match.Please try again." )
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def padding( word , padded_size , char=" " )
|
133
|
+
num_of_pad_required = padded_size - word.size
|
134
|
+
# no need padding
|
135
|
+
return word if num_of_pad_required <= 0
|
136
|
+
# padding exec
|
137
|
+
return word + (char * num_of_pad_required)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|