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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rash +1 -1
  3. data/lib/rash/ext/filesystem.rb +49 -25
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f799801cf8b57a584f090320cbd63d7b2e54dbc0e7c66fbac9943d7b75e35417
4
- data.tar.gz: 34b945f7da8b07813f405417c99d091466215b087fb709e71394ad3b551044a0
3
+ metadata.gz: 00dbd88cd56e1de80255ce40b9a061048ae8ec96b70cb0dc5c36a78589e73c68
4
+ data.tar.gz: f31d65ea147f7c3fa5516d51b38e70c28fa3cadb482427393887f9d42ef34321
5
5
  SHA512:
6
- metadata.gz: baa2bc0af9d01199949370a1fbea1b4682962842bab8618cdbc2c0fe4a3f30352daa3c7661da1989a21ee82b589f937ddd702b5a7ab139ecd791827e8192bdd7
7
- data.tar.gz: b05cc5985f22f293f5574057217c33641db8b409b50ecfb13861b332653c4d67e617ed19980abc50af0467934f41cb8e05d50ea51aa0ba1f9f806fb028645d6e
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.1" # I may forget to update this
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
@@ -101,22 +101,49 @@ class Environment
101
101
  @path = Dir.new(dir)
102
102
  @parent = parent
103
103
  @children = []
104
- @local_methods = parent&.unlocked_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
- @local_methods[name.to_sym]
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
- def local_method?(name)
130
- @local_methods.key?(name.to_sym)
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 exe || ($env.alias?(m) && !$env.aliasing_disabled)
251
+ elsif which(m.to_s) || ($env.alias?(m) && !$env.aliasing_disabled)
228
252
  $env.dispatch(m, *args)
229
253
  else
230
254
  super
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rash-command-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kellen Watt