rash-command-shell 0.4.1 → 0.4.2
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/bin/rash +1 -1
- data/lib/rash/ext/filesystem.rb +49 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00dbd88cd56e1de80255ce40b9a061048ae8ec96b70cb0dc5c36a78589e73c68
|
4
|
+
data.tar.gz: f31d65ea147f7c3fa5516d51b38e70c28fa3cadb482427393887f9d42ef34321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4194630eb9dbe5b1c4ad8afb9eb09e232b801eab51d06560cc1c41404d4202ade769c22a4da4f878f9d95ca213566635b90472e6c507e66578ddd2f465921f0
|
7
|
+
data.tar.gz: 5a12911de5b15ed865d14773b34b2a51f0efea3a3159bf29821eda79cf0ba7459429c7e4b1d95290cf03701745b4c914e4d9b8745906985e82a113f7be8351ab
|
data/bin/rash
CHANGED
@@ -4,7 +4,7 @@ if ARGV.empty?
|
|
4
4
|
exec("irb", "-r", "rash", *ARGV)
|
5
5
|
elsif ARGV[0] =~ /(-)?-v(ersion)?/
|
6
6
|
puts "Rash (c) 2020 Kellen Watt"
|
7
|
-
puts "Version 0.4.
|
7
|
+
puts "Version 0.4.2" # I may forget to update this
|
8
8
|
elsif File.exists?(ARGV[0]) && !File.directory?(ARGV[0])
|
9
9
|
require "rash"
|
10
10
|
file = ARGV.shift
|
data/lib/rash/ext/filesystem.rb
CHANGED
@@ -101,22 +101,49 @@ class Environment
|
|
101
101
|
@path = Dir.new(dir)
|
102
102
|
@parent = parent
|
103
103
|
@children = []
|
104
|
-
@local_methods =
|
104
|
+
@local_methods = {}
|
105
105
|
@locked_methods = []
|
106
106
|
@local_variables = {}
|
107
107
|
@locked_variables = []
|
108
108
|
end
|
109
109
|
|
110
|
+
######################
|
111
|
+
# Local method methods
|
112
|
+
######################
|
113
|
+
|
110
114
|
def local_method(name)
|
111
|
-
|
115
|
+
name = name.to_sym
|
116
|
+
@local_methods[name] || @parent&.unlocked_local_method(name)
|
112
117
|
end
|
113
118
|
|
119
|
+
def local_method?(name)
|
120
|
+
name = name.to_sym
|
121
|
+
@local_methods.key?(name) || !!@parent&.unlocked_local_method?(name)
|
122
|
+
end
|
123
|
+
|
114
124
|
def local_methods
|
115
|
-
@local_methods.keys
|
125
|
+
@local_methods.keys + (@parent&.unlocked_local_methods).to_a
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_local_method(name, &block)
|
129
|
+
raise ArgumentError.new "no method body provided" unless block_given?
|
130
|
+
@local_methods[name.to_sym] = block # if name already exists, its function is overriden
|
131
|
+
name.to_sym
|
132
|
+
end
|
133
|
+
|
134
|
+
def unlocked_local_method(name)
|
135
|
+
name = name.to_sym
|
136
|
+
@local_methods[name] || @parent&.unlocked_local_method(name)
|
137
|
+
end
|
138
|
+
|
139
|
+
def unlocked_local_method?(name)
|
140
|
+
name = name.to_sym
|
141
|
+
@local_methods.filter{|k, v| !@locked_methods.include?(k)}.key?(name) ||
|
142
|
+
!!@parent&.unlocked_local_method?(name)
|
116
143
|
end
|
117
144
|
|
118
145
|
def unlocked_local_methods
|
119
|
-
@local_methods.filter{|k, v| !@locked_methods.include?(k)}
|
146
|
+
@local_methods.filter{|k, v| !@locked_methods.include?(k)}.keys + (@parent&.unlocked_local_methods).to_a
|
120
147
|
end
|
121
148
|
|
122
149
|
def lock_method(name)
|
@@ -126,10 +153,16 @@ class Environment
|
|
126
153
|
n
|
127
154
|
end
|
128
155
|
|
129
|
-
|
130
|
-
|
156
|
+
# might not be useful
|
157
|
+
def clear_local_method(name)
|
158
|
+
@local_methods.delete(name.to_sym)
|
159
|
+
name.to_sym
|
131
160
|
end
|
132
|
-
|
161
|
+
|
162
|
+
######################
|
163
|
+
# Local variable stuff
|
164
|
+
######################
|
165
|
+
|
133
166
|
def local_variable(name)
|
134
167
|
name = name.to_sym
|
135
168
|
@local_variables[name] || @parent&.unlocked_local_variable(name)
|
@@ -152,15 +185,15 @@ class Environment
|
|
152
185
|
end
|
153
186
|
end
|
154
187
|
|
155
|
-
def unlocked_local_variables
|
156
|
-
@local_variables.keys.filter{|k| !@locked_variables.include?(k)} + (@parent&.unlocked_local_variables).to_a
|
157
|
-
end
|
158
|
-
|
159
188
|
def unlocked_local_variable(name)
|
160
189
|
name = name.to_sym
|
161
190
|
@local_variables.filter{|k| !@locked_variables.include?(k)}[name] || @parent&.unlocked_local_variable(name)
|
162
191
|
end
|
163
192
|
|
193
|
+
def unlocked_local_variables
|
194
|
+
@local_variables.keys.filter{|k| !@locked_variables.include?(k)} + (@parent&.unlocked_local_variables).to_a
|
195
|
+
end
|
196
|
+
|
164
197
|
def unlocked_local_variable?(name)
|
165
198
|
name = name.to_sym
|
166
199
|
@local_variables.filter{|k,_v| !@locked_variables.include?(k)}.key?(name) ||
|
@@ -179,6 +212,10 @@ class Environment
|
|
179
212
|
name.to_sym
|
180
213
|
end
|
181
214
|
|
215
|
+
###########################
|
216
|
+
# Generic traversal methods
|
217
|
+
###########################
|
218
|
+
|
182
219
|
def root?
|
183
220
|
parent.nil?
|
184
221
|
end
|
@@ -201,18 +238,6 @@ class Environment
|
|
201
238
|
dir
|
202
239
|
end
|
203
240
|
|
204
|
-
def add_local_method(name, &block)
|
205
|
-
raise ArgumentError.new "no method body provided" unless block_given?
|
206
|
-
@local_methods[name.to_sym] = block # if name already exists, its function is overriden
|
207
|
-
name.to_sym
|
208
|
-
end
|
209
|
-
|
210
|
-
# might not be useful
|
211
|
-
def clear_local_method(name)
|
212
|
-
@local_methods.delete(name.to_sym)
|
213
|
-
name.to_sym
|
214
|
-
end
|
215
|
-
|
216
241
|
def to_s
|
217
242
|
@path.path
|
218
243
|
end
|
@@ -221,10 +246,9 @@ end
|
|
221
246
|
|
222
247
|
# still could absolutely be more cleaned up, but it works
|
223
248
|
def self.method_missing(m, *args, &block)
|
224
|
-
exe = which(m.to_s)
|
225
249
|
if $env.local_method?(m)
|
226
250
|
$env.local_call(m, *args, &block)
|
227
|
-
elsif
|
251
|
+
elsif which(m.to_s) || ($env.alias?(m) && !$env.aliasing_disabled)
|
228
252
|
$env.dispatch(m, *args)
|
229
253
|
else
|
230
254
|
super
|