rubyment 0.0.25412377 → 0.1.25418433
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 +4 -4
- data/lib/rubyment.rb +423 -55
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030c9c7237fb007e9f744d737dedf00ac2e5abcb
|
4
|
+
data.tar.gz: 4906be12ab5b5613215ca77c869a1acf1aef0860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 634dcb867e05e001370b2c9cbaec0181d3a5d10e52534d9c4f68a0bb91cf16e6e0d6274631cbc9b8587847d7d64b83975c8435b17d620a389fa3461d57dea5cb
|
7
|
+
data.tar.gz: 86bfd87c415c3164e672c8928563403b56f9b3bb7f2193a26a9b4e53c876d495823ec730ab8cbc9cc8801d8f5cf4bed6f191ccacd1c462a70168a70b1270b702
|
data/lib/rubyment.rb
CHANGED
@@ -9,9 +9,25 @@
|
|
9
9
|
# to output something
|
10
10
|
class Rubyment
|
11
11
|
|
12
|
+
# this class very often needs to split
|
13
|
+
# first argument and remaining elements.
|
14
|
+
# args:
|
15
|
+
# args
|
16
|
+
# default:
|
17
|
+
# ARGV
|
18
|
+
# returns:
|
19
|
+
# [ args[0], args[1..-1] ]
|
20
|
+
def array_first_remainder args=ARGV
|
21
|
+
[ args[0], args[1..-1] ]
|
22
|
+
end
|
23
|
+
|
24
|
+
|
12
25
|
# invoke first arg with following args
|
13
26
|
# used by initialize
|
14
27
|
def invoke args=ARGV
|
28
|
+
stderr = @memory[:stderr]
|
29
|
+
method_name, arg_list = array_first_remainder args
|
30
|
+
!method_name && (return true)
|
15
31
|
begin
|
16
32
|
# this condition could become ambiguous only when
|
17
33
|
# a function has only one argument (if it has
|
@@ -23,9 +39,17 @@ class Rubyment
|
|
23
39
|
# functions taking only one argument can't be
|
24
40
|
# called from the command line (an array will
|
25
41
|
# be given to them)
|
26
|
-
self.method(
|
42
|
+
self.method(method_name).call (arg_list)
|
27
43
|
rescue ArgumentError => e
|
28
|
-
|
44
|
+
begin
|
45
|
+
self.method(method_name).call *(arg_list)
|
46
|
+
rescue ArgumentError => e2
|
47
|
+
# it didn't work -- the arguments given can't
|
48
|
+
# be fit. better just try to let the caller
|
49
|
+
# figure out when it first called the function.
|
50
|
+
stderr.puts e2
|
51
|
+
raise e
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
31
55
|
|
@@ -36,6 +60,7 @@ class Rubyment
|
|
36
60
|
:stdout => STDOUT,
|
37
61
|
:stdin => STDIN,
|
38
62
|
:time => Time.now,
|
63
|
+
:major_version => "0.1",
|
39
64
|
:basic_version => (Time.now.to_i / 60), # new one every minute
|
40
65
|
:filepath => __FILE__,
|
41
66
|
:running_dir => Dir.pwd,
|
@@ -45,11 +70,30 @@ class Rubyment
|
|
45
70
|
:static_separator_key => "strings_having_this_string_not_guaranteed_to_work",
|
46
71
|
:static_end_key => "strings_havinng_this_string_also_not_guaranteed_to_work",
|
47
72
|
}
|
48
|
-
@memory.update memory
|
73
|
+
@memory.update memory.to_h
|
49
74
|
invoke @memory[:invoke].to_a
|
50
75
|
end
|
51
76
|
|
52
77
|
|
78
|
+
# returns a version number comprised
|
79
|
+
# of a major and a minor number
|
80
|
+
# args:
|
81
|
+
# [major_version (String or nil), minor_version (String or nil) ]
|
82
|
+
# defaults:
|
83
|
+
# [@memory[:major_version]], @memory[:basic_version]]
|
84
|
+
# returns:
|
85
|
+
# "#{major}.#{minor}"
|
86
|
+
def version args=ARGV
|
87
|
+
memory = @memory
|
88
|
+
major_version = memory[:major_version]
|
89
|
+
basic_version = memory[:basic_version]
|
90
|
+
major, minor = args
|
91
|
+
major ||= major_version
|
92
|
+
minor ||= basic_version
|
93
|
+
"#{major}.#{minor}"
|
94
|
+
end
|
95
|
+
|
96
|
+
|
53
97
|
# enables the possibility to inkove a second method with
|
54
98
|
# the results of a first one. eg, the results of a method
|
55
99
|
# called file_permissions_octal which returns without output
|
@@ -62,6 +106,14 @@ class Rubyment
|
|
62
106
|
invoke [second_invokation] + [first_invokation_result].flatten(1)
|
63
107
|
end
|
64
108
|
|
109
|
+
|
110
|
+
# returns a Class object out of class_name (or itself if it is already
|
111
|
+
# a class)
|
112
|
+
def containerize args=ARGV
|
113
|
+
[args].flatten 1
|
114
|
+
end
|
115
|
+
|
116
|
+
|
65
117
|
# if file is a nonexisting filepath, or by any reason
|
66
118
|
# throws any exception, it will be treated as contents
|
67
119
|
# instead, and the filename will treated as ""
|
@@ -85,6 +137,65 @@ class Rubyment
|
|
85
137
|
end
|
86
138
|
|
87
139
|
|
140
|
+
# returns a Class object out of class_name (or itself if it is already
|
141
|
+
# a class)
|
142
|
+
def to_class args=ARGV
|
143
|
+
class_name, future_arg = containerize args
|
144
|
+
begin
|
145
|
+
class_object = ( class_name.is_a? Class ) && class_name || (Object.const_get class_name.to_s)
|
146
|
+
rescue NameError => nameErrorE
|
147
|
+
nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# returns a Method (object.method if object is
|
153
|
+
# given). give self as object to look up
|
154
|
+
# at the current context
|
155
|
+
# args:
|
156
|
+
# [ name (String), object (Object) ]
|
157
|
+
# returns:
|
158
|
+
# method_object (Method)
|
159
|
+
def to_method args=ARGV
|
160
|
+
stderr = @memory[:stderr]
|
161
|
+
name, object = containerize args
|
162
|
+
begin
|
163
|
+
method = object.method("method").call(name)
|
164
|
+
rescue NameError => nameError
|
165
|
+
# every object (even nil) has :method,
|
166
|
+
# and every Method has :call: exception
|
167
|
+
# is thrown in call
|
168
|
+
stderr.puts nameError
|
169
|
+
nil
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# calls object.method call_args
|
174
|
+
# note: function closed for extension.
|
175
|
+
# a new extension if ever made, will
|
176
|
+
# be created with a new function.
|
177
|
+
# args:
|
178
|
+
# [method (Method or String), object (Object), call_args (Array)]
|
179
|
+
# returns:
|
180
|
+
#
|
181
|
+
def object_method_args_call args=ARGV
|
182
|
+
stderr = @memory[:stderr]
|
183
|
+
method, object, *call_args = containerize args
|
184
|
+
object ||= self
|
185
|
+
method = to_method [method, object]
|
186
|
+
call_args = call_args && (containerize call_args)
|
187
|
+
begin
|
188
|
+
call_args && (method.call *call_args) || method.call
|
189
|
+
rescue NameError => nameError
|
190
|
+
# every object (even nil) has :method,
|
191
|
+
# and every Method has :call: exception
|
192
|
+
# is thrown in call
|
193
|
+
stderr.puts nameError
|
194
|
+
nil
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
|
88
199
|
# args:
|
89
200
|
# path (String)
|
90
201
|
# returns:
|
@@ -432,7 +543,6 @@ class Rubyment
|
|
432
543
|
base64_key = metadata["base64_key" ]
|
433
544
|
ending = nil
|
434
545
|
pw_plain = dec [password, base64_iv, base64_encrypted, ending, base64_salt, base64_iter]
|
435
|
-
# p pw_plain
|
436
546
|
shell_dec_output [pw_plain]
|
437
547
|
end
|
438
548
|
|
@@ -654,17 +764,7 @@ class Rubyment
|
|
654
764
|
# as the same.
|
655
765
|
def test__enc_dec_nil args=ARGV
|
656
766
|
nil_case = dec [nil, "ltUQIxgRAeUNXPNTTps8FQ==\n", "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\n", nil, "TU4o3IKiFWki3rZ3lMchLQ==\n", "MjAwMDA=\n"]
|
657
|
-
# args inspect in enc
|
658
|
-
p output_array_to_shell [nil, "ltUQIxgRAeUNXPNTTps8FQ==\n", "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\n", nil, "TU4o3IKiFWki3rZ3lMchLQ==\n", "MjAwMDA=\n"]
|
659
|
-
p "--"
|
660
|
-
puts output_array_to_shell [nil, "ltUQIxgRAeUNXPNTTps8FQ==\n", "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\n", nil, "TU4o3IKiFWki3rZ3lMchLQ==\n", "MjAwMDA=\n"]
|
661
|
-
return
|
662
|
-
# [nil, "ltUQIxgRAeUNXPNTTps8FQ==\n", "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\n", nil, "TU4o3IKiFWki3rZ3lMchLQ==\n", "MjAwMDA=\n"]
|
663
767
|
empty = dec ["", "ltUQIxgRAeUNXPNTTps8FQ==\n", "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\n", "", "TU4o3IKiFWki3rZ3lMchLQ==\n", "MjAwMDA=\n"]
|
664
|
-
# /rubyment.rb dec "" "ltUQIxgRAeUNXPNTTps8FQ==\n" "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\n" "" "TU4o3IKiFWki3rZ3lMchLQ==\n" "MjAwMDA=\n"
|
665
|
-
# args inpect in dec:
|
666
|
-
# ["", "ltUQIxgRAeUNXPNTTps8FQ==\\n", "xyeqxw/TzkyXtOxpDqAl58SNAvXPyNZ89B5JGtwDkcbjo0vObgPsh5FrgZJs\\nHPjofsyXnljnTrHpDoQeDVezo9wBZ74NU+TSi/GssX605oE=\\n", "", "TU4o3IKiFWki3rZ3lMchLQ==\\n", "MjAwMDA=\\n"]
|
667
|
-
|
668
768
|
judgement =
|
669
769
|
[
|
670
770
|
[nil_case, empty, "empty_nil_equality"]
|
@@ -712,30 +812,55 @@ class Rubyment
|
|
712
812
|
end
|
713
813
|
|
714
814
|
|
715
|
-
#
|
716
|
-
# args
|
717
|
-
# returns: a gem spec string
|
718
|
-
def
|
815
|
+
# gem_spec
|
816
|
+
# args (Array like the one returned by rubyment_gem_defaults)
|
817
|
+
# returns: a gem spec string accordingly to args
|
818
|
+
def gem_spec args=ARGV
|
719
819
|
memory = @memory
|
720
|
-
|
820
|
+
gem_name,
|
821
|
+
gem_version,
|
822
|
+
gem_dir,
|
823
|
+
gem_ext,
|
824
|
+
gem_hifen,
|
825
|
+
gem_date,
|
826
|
+
gem_summary,
|
827
|
+
gem_description,
|
828
|
+
gem_authors,
|
829
|
+
gem_email,
|
830
|
+
gem_files,
|
831
|
+
gem_homepage,
|
832
|
+
gem_license,
|
833
|
+
gem_validate_class,
|
834
|
+
gem_validate_class_args,
|
835
|
+
gem_validate_class_method = args
|
836
|
+
|
721
837
|
contents =<<-ENDHEREDOC
|
722
838
|
Gem::Specification.new do |s|
|
723
|
-
s.name = '
|
724
|
-
s.version = '
|
725
|
-
s.date = '
|
726
|
-
s.summary =
|
727
|
-
s.description =
|
728
|
-
s.authors =
|
729
|
-
s.email = '
|
730
|
-
s.files =
|
731
|
-
s.homepage =
|
732
|
-
|
733
|
-
s.license = 'GPL-3.0'
|
839
|
+
s.name = '#{gem_name}'
|
840
|
+
s.version = '#{gem_version}'
|
841
|
+
s.date = '#{gem_date}'
|
842
|
+
s.summary = '#{gem_summary}'
|
843
|
+
s.description = '#{gem_description}'
|
844
|
+
s.authors = #{gem_authors.inspect}
|
845
|
+
s.email = '#{gem_email}'
|
846
|
+
s.files = #{gem_files.inspect}
|
847
|
+
s.homepage = '#{gem_homepage}'
|
848
|
+
s.license = '#{gem_license}'
|
734
849
|
end
|
735
850
|
ENDHEREDOC
|
736
851
|
contents
|
737
852
|
end
|
738
853
|
|
854
|
+
|
855
|
+
# rubyment_gem_spec
|
856
|
+
# args (Array, forwarded and transfomed by rubyment_gem_defaults)
|
857
|
+
# returns: a gem spec string for Rubyment
|
858
|
+
def rubyment_gem_spec args=ARGV
|
859
|
+
memory = @memory
|
860
|
+
gem_spec rubyment_gem_defaults args
|
861
|
+
end
|
862
|
+
|
863
|
+
|
739
864
|
# test for rubyment_gem_spec. outputs the contents
|
740
865
|
# returned by that function.
|
741
866
|
# args: none
|
@@ -744,19 +869,122 @@ end
|
|
744
869
|
puts rubyment_gem_spec
|
745
870
|
end
|
746
871
|
|
872
|
+
|
873
|
+
|
874
|
+
# defaults for the rubyment gem
|
875
|
+
# args:
|
876
|
+
# [gem_name, gem_version, gem_dir, gem_ext, gem_hifen]
|
877
|
+
# all Strings.
|
878
|
+
# defaults:
|
879
|
+
# ["rubyment", version [], memory[:running_dir],
|
880
|
+
# ".gem", "-"]
|
881
|
+
# returns:
|
882
|
+
# [gem_name, gem_version, gem_dir, gem_ext, gem_hifen]
|
883
|
+
#
|
884
|
+
def rubyment_gem_defaults args=ARGV
|
885
|
+
memory = @memory
|
886
|
+
running_dir = memory[:running_dir]
|
887
|
+
basic_version = memory[:basic_version]
|
888
|
+
major_version = memory[:major_version]
|
889
|
+
|
890
|
+
gem_name,
|
891
|
+
gem_version,
|
892
|
+
gem_dir,
|
893
|
+
gem_ext,
|
894
|
+
gem_hifen,
|
895
|
+
gem_date,
|
896
|
+
gem_summary,
|
897
|
+
gem_description,
|
898
|
+
gem_authors,
|
899
|
+
gem_email,
|
900
|
+
gem_files,
|
901
|
+
gem_homepage,
|
902
|
+
gem_license,
|
903
|
+
gem_validate_class,
|
904
|
+
gem_validate_class_args,
|
905
|
+
gem_validate_class_method,
|
906
|
+
gem_is_current_file = args
|
907
|
+
|
908
|
+
gem_name ||= "rubyment"
|
909
|
+
gem_version ||= (version [])
|
910
|
+
gem_dir ||= running_dir
|
911
|
+
gem_ext ||= ".gem"
|
912
|
+
gem_hifen ||= "-"
|
913
|
+
gem_ext ||= "date"
|
914
|
+
gem_date ||= "2018-04-23"
|
915
|
+
gem_summary ||= "a set of ruby helpers"
|
916
|
+
gem_description ||= "a gem for keeping Rubyment, a set of ruby helpers"
|
917
|
+
gem_authors ||= ["Ribamar Santarosa"]
|
918
|
+
gem_email ||= 'ribamar@gmail.com'
|
919
|
+
gem_files ||= ["lib/rubyment.rb"]
|
920
|
+
gem_homepage ||=
|
921
|
+
"http://rubygems.org/gems/#{gem_name}"
|
922
|
+
gem_license ||= 'GPL-3.0'
|
923
|
+
gem_validate_class ||= "Rubyment"
|
924
|
+
gem_validate_class_args ||= {:invoke => ["p", "installed and validated"] }
|
925
|
+
gem_validate_class_method ||= "new"
|
926
|
+
gem_is_current_file = true # this enables the possibility of building
|
927
|
+
# a gem for the calling file itself, but be aware that lib/gem_file.rb
|
928
|
+
# is supposed to be overriden later.
|
929
|
+
[
|
930
|
+
gem_name,
|
931
|
+
gem_version,
|
932
|
+
gem_dir,
|
933
|
+
gem_ext,
|
934
|
+
gem_hifen,
|
935
|
+
gem_date,
|
936
|
+
gem_summary,
|
937
|
+
gem_description,
|
938
|
+
gem_authors,
|
939
|
+
gem_email,
|
940
|
+
gem_files,
|
941
|
+
gem_homepage,
|
942
|
+
gem_license,
|
943
|
+
gem_validate_class,
|
944
|
+
gem_validate_class_args,
|
945
|
+
gem_validate_class_method,
|
946
|
+
gem_is_current_file,
|
947
|
+
]
|
948
|
+
end
|
949
|
+
|
950
|
+
|
951
|
+
# returns the gem path given the params.
|
952
|
+
# args:
|
953
|
+
# [gem_name, gem_version, gem_dir, gem_ext, gem_hifen]
|
954
|
+
# all Strings.
|
955
|
+
# defaults:
|
956
|
+
# ["rubyment", version [], memory[:running_dir],
|
957
|
+
# ".gem", "-"]
|
958
|
+
def gem_path args=ARGV
|
959
|
+
gem_name, gem_version, gem_dir, gem_ext, gem_hifen = rubyment_gem_defaults args
|
960
|
+
"#{gem_dir}/#{gem_name}#{gem_hifen}#{gem_version}#{gem_ext}"
|
961
|
+
end
|
962
|
+
|
963
|
+
|
747
964
|
# gem_build
|
748
965
|
# args:
|
749
|
-
# [gem_spec_path (String), gem_spec_contents (String)]
|
966
|
+
# [gem_spec_path (String), gem_spec_contents (String), gem_is_current_file, gem_name]
|
750
967
|
# returns:
|
751
968
|
# console output of gem build (String)
|
752
969
|
def gem_build args=ARGV
|
753
|
-
gem_spec_path, gem_spec_contents = args
|
970
|
+
gem_spec_path, gem_spec_contents, gem_is_current_file, gem_name = args
|
754
971
|
require 'fileutils'
|
972
|
+
|
973
|
+
# this supposes that the current file is listed by the
|
974
|
+
# s.files
|
975
|
+
# field of the specification. it is not currently checked.
|
976
|
+
gem_is_current_file && (
|
977
|
+
FileUtils.mkdir_p 'lib'
|
978
|
+
file_backup "lib/#{gem_name}.rb", "lib/"
|
979
|
+
save_file __FILE__, "lib/#{gem_name}.rb"
|
980
|
+
)
|
981
|
+
|
755
982
|
FileUtils.mkdir_p File.dirname gem_spec_path
|
756
983
|
File.write gem_spec_path, gem_spec_contents || (File.read gem_spec_path)
|
757
984
|
`gem build #{gem_spec_path}`
|
758
985
|
end
|
759
986
|
|
987
|
+
|
760
988
|
# test for gem_build: builds gem for this rubyment file
|
761
989
|
# after it, these commands will install/uninstall it:
|
762
990
|
# sudo gem install $PWD/rubyment-0.0.#{@memory[:basic_version]} ; gem list | grep -i rubyment ; sudo gem uninstall rubyment
|
@@ -770,7 +998,7 @@ end
|
|
770
998
|
require 'fileutils'
|
771
999
|
FileUtils.mkdir_p 'lib'
|
772
1000
|
save_file __FILE__, 'lib/rubyment.rb'
|
773
|
-
puts gem_build ["rubyment.spec", rubyment_gem_spec ]
|
1001
|
+
puts gem_build ["rubyment.spec", rubyment_gem_spec(args) ]
|
774
1002
|
end
|
775
1003
|
|
776
1004
|
# gem_install
|
@@ -792,10 +1020,8 @@ end
|
|
792
1020
|
# console output of gem push (String)
|
793
1021
|
def gem_push args=ARGV
|
794
1022
|
gem_spec, future_arg = args
|
795
|
-
|
796
|
-
|
797
|
-
stderr.puts `ls -lh #{gem_spec}`
|
798
|
-
`gem push #{gem_spec}`
|
1023
|
+
p "gem push #{gem_spec}`"
|
1024
|
+
p `gem push #{gem_spec}`
|
799
1025
|
end
|
800
1026
|
|
801
1027
|
# gem_uninstall
|
@@ -820,6 +1046,34 @@ end
|
|
820
1046
|
`gem list | grep #{gem_spec}`
|
821
1047
|
end
|
822
1048
|
|
1049
|
+
# validate_require
|
1050
|
+
# requires a file/gem in the system
|
1051
|
+
# returns nil if not found
|
1052
|
+
# args:
|
1053
|
+
# [requirement (String), validator_class (Class or String or nil),
|
1054
|
+
# validator_args (Array), validator_method (Method or String)]
|
1055
|
+
# returns:
|
1056
|
+
# Rubyment, true or false
|
1057
|
+
def validate_require args=ARGV
|
1058
|
+
p "{"
|
1059
|
+
p args
|
1060
|
+
p "}"
|
1061
|
+
stderr = @memory[:stderr]
|
1062
|
+
requirement, validator_class, validator_args, validator_method = containerize args
|
1063
|
+
validate_call = validator_class && true
|
1064
|
+
validator_class = to_class validator_class
|
1065
|
+
validator_method ||= "new"
|
1066
|
+
x= begin
|
1067
|
+
require requirement
|
1068
|
+
xy = validate_call && (object_method_args_call [validator_method, validator_class, validator_args]) || (!validate_call) && true
|
1069
|
+
xy
|
1070
|
+
rescue LoadError => e
|
1071
|
+
stderr.puts e
|
1072
|
+
nil
|
1073
|
+
end
|
1074
|
+
x
|
1075
|
+
end
|
1076
|
+
|
823
1077
|
# system_rubyment
|
824
1078
|
# requires a system's Rubyment and invoke it using args
|
825
1079
|
# args:
|
@@ -827,14 +1081,66 @@ end
|
|
827
1081
|
# returns:
|
828
1082
|
# Rubyment or false
|
829
1083
|
def system_rubyment args=ARGV
|
830
|
-
|
831
|
-
require 'rubyment'
|
832
|
-
Rubyment.new({:invoke => args })
|
833
|
-
rescue LoadError
|
834
|
-
nil
|
835
|
-
end
|
1084
|
+
validate_require ['rubyment', 'Rubyment', {:invoke => args }]
|
836
1085
|
end
|
837
1086
|
|
1087
|
+
|
1088
|
+
# extract only the arguments referring to files
|
1089
|
+
# from args
|
1090
|
+
def gem_files_args args=ARGV
|
1091
|
+
gem_name,
|
1092
|
+
gem_version,
|
1093
|
+
gem_dir,
|
1094
|
+
gem_ext,
|
1095
|
+
gem_hifen,
|
1096
|
+
gem_date,
|
1097
|
+
gem_summary,
|
1098
|
+
gem_description,
|
1099
|
+
gem_authors,
|
1100
|
+
gem_email,
|
1101
|
+
gem_files,
|
1102
|
+
gem_homepage,
|
1103
|
+
gem_license,
|
1104
|
+
gem_validate_class,
|
1105
|
+
gem_validate_class_args,
|
1106
|
+
gem_validate_class_method,
|
1107
|
+
gem_is_current_file = args
|
1108
|
+
[
|
1109
|
+
gem_files,
|
1110
|
+
gem_is_current_file,
|
1111
|
+
]
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
|
1115
|
+
# extract only the arguments for validation
|
1116
|
+
# from args
|
1117
|
+
def gem_validate_args args=ARGV
|
1118
|
+
gem_name,
|
1119
|
+
gem_version,
|
1120
|
+
gem_dir,
|
1121
|
+
gem_ext,
|
1122
|
+
gem_hifen,
|
1123
|
+
gem_date,
|
1124
|
+
gem_summary,
|
1125
|
+
gem_description,
|
1126
|
+
gem_authors,
|
1127
|
+
gem_email,
|
1128
|
+
gem_files,
|
1129
|
+
gem_homepage,
|
1130
|
+
gem_license,
|
1131
|
+
gem_validate_class,
|
1132
|
+
gem_validate_class_args,
|
1133
|
+
gem_validate_class_method,
|
1134
|
+
gem_is_current_file = args
|
1135
|
+
[
|
1136
|
+
gem_name,
|
1137
|
+
gem_validate_class,
|
1138
|
+
gem_validate_class_args,
|
1139
|
+
gem_validate_class_method,
|
1140
|
+
]
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
|
838
1144
|
# test for system_rubyment
|
839
1145
|
# dependee:
|
840
1146
|
# test__gem_install_validate_uninstall
|
@@ -844,12 +1150,52 @@ end
|
|
844
1150
|
# Rubyment or false
|
845
1151
|
def test__system_rubyment args=ARGV
|
846
1152
|
rubyment_args = (args.to_a.size > 0 && args) || ["main", "tested system_rubyment"]
|
847
|
-
p
|
1153
|
+
p validate_require ['rubyment', 'Rubyment', {:invoke => rubyment_args }]
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
|
1157
|
+
# validate the installation of a gem
|
1158
|
+
# args rubyment_gem_defaults
|
1159
|
+
# but planned to change.
|
1160
|
+
# bug detected: require x won't reload the gem.
|
1161
|
+
# args (Array just like the one
|
1162
|
+
# returned by rubyment_gem_defaults)
|
1163
|
+
# returns:
|
1164
|
+
# true or false
|
1165
|
+
def gem_validate args=ARGV
|
1166
|
+
memory = @memory
|
1167
|
+
gem_defaults = rubyment_gem_defaults args
|
1168
|
+
gem_name, gem_version = gem_defaults
|
1169
|
+
gem_files, gem_is_current_file = gem_files_args gem_defaults
|
1170
|
+
puts gem_build [
|
1171
|
+
"#{gem_name}.spec",
|
1172
|
+
gem_spec(gem_defaults),
|
1173
|
+
gem_is_current_file,
|
1174
|
+
gem_name
|
1175
|
+
]
|
1176
|
+
already_installed = (
|
1177
|
+
validate_require gem_validate_args gem_defaults
|
1178
|
+
)
|
1179
|
+
sleep 1
|
1180
|
+
already_installed && (gem_uninstall [gem_name])
|
1181
|
+
puts gem_list [gem_name]
|
1182
|
+
p (gem_path [gem_name, gem_version])
|
1183
|
+
gem_install [(gem_path [gem_name, gem_version])]
|
1184
|
+
puts gem_list [gem_name]
|
1185
|
+
v = (
|
1186
|
+
validate_require gem_validate_args gem_defaults
|
1187
|
+
)
|
1188
|
+
gem_uninstall [gem_name]
|
1189
|
+
already_installed && (gem_install [gem_name])
|
1190
|
+
v
|
848
1191
|
end
|
849
1192
|
|
850
1193
|
|
851
1194
|
# test for gem_build, gem_install, gem_list
|
852
1195
|
# system_rubyment, gem_uninstall
|
1196
|
+
# note that, if there is a "rubyment" gem
|
1197
|
+
# already installed, it will be temporarily
|
1198
|
+
# unavailable.
|
853
1199
|
# args:
|
854
1200
|
# args (Array or nil)
|
855
1201
|
# returns:
|
@@ -857,14 +1203,18 @@ end
|
|
857
1203
|
def test__gem_build_install_validate_uninstall args=ARGV
|
858
1204
|
memory = @memory
|
859
1205
|
basic_version = memory[:basic_version]
|
1206
|
+
major_version = memory[:major_version]
|
860
1207
|
running_dir = memory[:running_dir]
|
861
1208
|
test__gem_build []
|
1209
|
+
already_installed = (system_rubyment ["p", "already installed"])
|
1210
|
+
sleep 1
|
862
1211
|
gem_uninstall ["rubyment"]
|
863
1212
|
puts gem_list ["rubyment"]
|
864
|
-
gem_install ["#{running_dir}/rubyment
|
1213
|
+
gem_install ["#{running_dir}/rubyment-#{major_version}.#{basic_version}.gem"]
|
865
1214
|
puts gem_list ["rubyment"]
|
866
1215
|
v = test__system_rubyment []
|
867
1216
|
gem_uninstall ["rubyment"]
|
1217
|
+
already_installed && (gem_install ["rubyment"])
|
868
1218
|
v
|
869
1219
|
end
|
870
1220
|
|
@@ -886,7 +1236,7 @@ end
|
|
886
1236
|
FileUtils.mkdir_p File.dirname file_destination
|
887
1237
|
key_contents = save_file "https://rubygems.org/api/v1/api_key.yaml",
|
888
1238
|
file_destination, 0, {:username => username, :password => password }
|
889
|
-
(File.chmod 0600, file_destination)
|
1239
|
+
(File.chmod 0600, file_destination)
|
890
1240
|
key_contents
|
891
1241
|
end
|
892
1242
|
|
@@ -900,28 +1250,46 @@ end
|
|
900
1250
|
puts gem_get_api_key args
|
901
1251
|
end
|
902
1252
|
|
903
|
-
|
904
|
-
#
|
1253
|
+
|
1254
|
+
# builds, validates and push a gem accordingly
|
1255
|
+
# to the arguments. if arguments not given,
|
1256
|
+
# will do for the defaults (see rubyment_gem_defaults)
|
905
1257
|
# args:
|
906
1258
|
# args (Array or nil)
|
907
1259
|
# returns:
|
908
|
-
#
|
909
|
-
def
|
1260
|
+
# ignore (will change)
|
1261
|
+
def gem_build_push args=ARGV
|
910
1262
|
memory = @memory
|
911
1263
|
running_dir = memory[:running_dir]
|
912
1264
|
home_dir = memory[:home_dir]
|
913
|
-
|
914
|
-
|
1265
|
+
gem_username, gem_password, gem_api_key_file, gem_defaults = args
|
1266
|
+
gem_password = gem_password.to_s.split("\0").first
|
1267
|
+
gem_defaults ||= rubyment_gem_defaults []
|
1268
|
+
gem_api_key_file ||= "#{home_dir}/.gem/credentials"
|
915
1269
|
permissions = file_permissions_octal gem_api_key_file
|
916
1270
|
credentials_contents = url_to_str gem_api_key_file, ""
|
917
|
-
gem_get_api_key [
|
918
|
-
validated =
|
919
|
-
|
1271
|
+
(gem_get_api_key [gem_username, gem_password, gem_api_key_file]) rescue nil
|
1272
|
+
validated = (
|
1273
|
+
gem_validate gem_defaults
|
1274
|
+
)
|
1275
|
+
puts validated && (gem_push gem_path gem_defaults )
|
920
1276
|
File.write gem_api_key_file, credentials_contents
|
921
1277
|
File.chmod permissions, gem_api_key_file
|
922
1278
|
end
|
923
1279
|
|
924
1280
|
|
1281
|
+
# test for gem_build, gem_install, gem_list
|
1282
|
+
# system_rubyment, gem_uninstall
|
1283
|
+
# args:
|
1284
|
+
# args (Array or nil)
|
1285
|
+
# returns:
|
1286
|
+
# ignore
|
1287
|
+
def test__gem_complete_flow args=ARGV
|
1288
|
+
memory = @memory
|
1289
|
+
gem_build_push args
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
|
925
1293
|
end
|
926
1294
|
|
927
1295
|
(__FILE__ == $0) && Rubyment.new({:invoke => ARGV})
|