gloo-lang 1.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2fef4d21ce7b2ba45d4598fa24282c703581bbe1e40ea07f8e8063bf66a4b1b
4
- data.tar.gz: dbd1b3b25f998023baa7c93044618f33bdca46de5ff068b2efd2093d156c5393
3
+ metadata.gz: f902743811fec6c55772cbf3db6a20dc6d41702334f4089e1c35a05d780ffadc
4
+ data.tar.gz: 529e7168fcf0e59d2a90b3bee49c70776763a5019016fa7dec3a77b291360660
5
5
  SHA512:
6
- metadata.gz: 9b859bb73c0b74b901ca5aaf2fba754c70d9b567c8725afa1ed20260f547b68264a9af8e96f391e94edd955a002de01417fbacc154f850309a2134b7f2d6ee81
7
- data.tar.gz: b5cc88f9740a6766051579ea185b94b308f6628a61e13a1259871bd49350bb90acd9544ee47e3085c53daf33911ed312acc682373b244bd6b361e307b987be75
6
+ metadata.gz: cee004bc20d2fdfd6dafed5bdbd75f17da5883db081236604c9fc64be63d215adad0fd69c5fce71cf387bca5953774ede38bcb2e5f9fd7a92d9bc02a80510921
7
+ data.tar.gz: a874636b58d09345512247e2b9d7caf505720b264715122f4e4ec8b1752571eefebe16aebb29df623da77707b0c054031d5aebe19017d5a44e63871f4123868b
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.2
@@ -70,6 +70,14 @@ module GlooLang
70
70
  def cols
71
71
  return 80
72
72
  end
73
+
74
+ #
75
+ # Get the file mechanism for this platform.
76
+ #
77
+ def getFileMech( engine )
78
+ return GlooLang::Persist::DiscMech.new( engine )
79
+ end
80
+
73
81
  end
74
82
  end
75
83
  end
@@ -138,6 +138,46 @@ module GlooLang
138
138
  end
139
139
  end
140
140
 
141
+ # ---------------------------------------------------------------------
142
+ # Register after start up
143
+ # ---------------------------------------------------------------------
144
+
145
+ #
146
+ # Register a verb after start up.
147
+ #
148
+ def register_verb_post_start( verb_class )
149
+ add_verb verb_class
150
+ end
151
+
152
+ #
153
+ # Register an object type after start up.
154
+ #
155
+ def register_obj_post_start( obj_class )
156
+ add_object obj_class
157
+ end
158
+
159
+ #
160
+ # Un-Register a verb.
161
+ #
162
+ def unregister_verb( verb_class )
163
+ @verbs.delete( verb_class.keyword )
164
+ @verbs.delete( verb_class.keyword_shortcut )
165
+
166
+ @keywords.delete( verb_class.keyword )
167
+ @keywords.delete( verb_class.keyword_shortcut )
168
+ end
169
+
170
+ #
171
+ # Un-Register an object.
172
+ #
173
+ def unregister_obj( obj_class )
174
+ @objs.delete( obj_class.typename )
175
+ @objs.delete( obj_class.short_typename )
176
+
177
+ @keywords.delete( obj_class.typename )
178
+ @keywords.delete( obj_class.short_typename )
179
+ end
180
+
141
181
  # ---------------------------------------------------------------------
142
182
  # Private
143
183
  # ---------------------------------------------------------------------
@@ -163,11 +203,7 @@ module GlooLang
163
203
  def init_objs
164
204
  # @engine.log.debug "initializing #{@obj_references.count} objects"
165
205
  @obj_references.each do |o|
166
- # @engine.log.debug o
167
- @objs[ o.typename ] = o
168
- @objs[ o.short_typename ] = o
169
- add_key o.typename
170
- add_key o.short_typename if o.typename != o.short_typename
206
+ add_object o
171
207
  end
172
208
  end
173
209
 
@@ -177,15 +213,33 @@ module GlooLang
177
213
  def init_verbs
178
214
  # @engine.log.debug "initializing #{@verb_references.count} verbs"
179
215
  @verb_references.each do |v|
180
- # @engine.log.debug v
181
- @verbs[ v.keyword ] = v
182
- @verbs[ v.keyword_shortcut ] = v
183
- # v.send( :new ).run
184
- add_key v.keyword
185
- add_key v.keyword_shortcut if v.keyword != v.keyword_shortcut
216
+ add_verb v
186
217
  end
187
218
  end
188
219
 
220
+ #
221
+ # Add an object to the dictionary
222
+ #
223
+ def add_object o
224
+ # @engine.log.debug o
225
+ @objs[ o.typename ] = o
226
+ @objs[ o.short_typename ] = o
227
+ add_key o.typename
228
+ add_key o.short_typename if o.typename != o.short_typename
229
+ end
230
+
231
+ #
232
+ # Add a verb to the dictionary
233
+ #
234
+ def add_verb v
235
+ # @engine.log.debug v
236
+ @verbs[ v.keyword ] = v
237
+ @verbs[ v.keyword_shortcut ] = v
238
+ # v.send( :new ).run
239
+ add_key v.keyword
240
+ add_key v.keyword_shortcut if v.keyword != v.keyword_shortcut
241
+ end
242
+
189
243
  end
190
244
  end
191
245
  end
@@ -0,0 +1,87 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2022 Eric Crane. All rights reserved.
3
+ #
4
+ # Disc based mechanism for files.
5
+ # Provides interaction between the persistance classes and the OS
6
+ # file and folder system.
7
+ # This class might be overiden elsewhere to provide other mechanism.
8
+ # For example, in gloo-web, there will be a db based mechanism.
9
+ #
10
+
11
+ module GlooLang
12
+ module Persist
13
+ class DiscMech
14
+
15
+ #
16
+ # Set up a disc based file mechanism.
17
+ #
18
+ def initialize( engine )
19
+ @engine = engine
20
+ end
21
+
22
+ #
23
+ # Get the default file extention.
24
+ #
25
+ def file_ext
26
+ return '.gloo'
27
+ end
28
+
29
+ #
30
+ # Get all the gloo files in the folder (partial path).
31
+ #
32
+ def get_all_files_in( folder )
33
+ pns = []
34
+ dir = File.join( @engine.settings.project_path, folder )
35
+ Dir.glob( "#{dir}*.gloo" ).each do |f|
36
+ pns << f
37
+ end
38
+ return pns
39
+ end
40
+
41
+ #
42
+ # Check if a file exists.
43
+ #
44
+ def exist?( file )
45
+ File.exist?( file )
46
+ end
47
+
48
+ #
49
+ # Check to see if the file is valid.
50
+ #
51
+ def valid?( file )
52
+ return false unless file
53
+ return false unless File.exist?( file )
54
+ return false unless File.file?( file )
55
+ return false unless file.end_with?( self.file_ext )
56
+
57
+ return true
58
+ end
59
+
60
+ #
61
+ # Expand a single file path.
62
+ #
63
+ def expand( name )
64
+ ext_path = File.expand_path( name )
65
+ return [ ext_path ] if self.valid?( ext_path )
66
+
67
+ full_name = "#{name}#{file_ext}"
68
+ return [ File.join( @engine.settings.project_path, full_name ) ]
69
+ end
70
+
71
+ #
72
+ # Read in the contents of a single file.
73
+ #
74
+ def read( file )
75
+ return File.read( file )
76
+ end
77
+
78
+ #
79
+ # Write data to the file.
80
+ #
81
+ def write( pn, data )
82
+ File.write( pn, data )
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -19,6 +19,7 @@ module GlooLang
19
19
  #
20
20
  def initialize( engine, pn )
21
21
  @engine = engine
22
+ @mech = @engine.platform.getFileMech( @engine )
22
23
  @pn = pn
23
24
  @tabs = 0
24
25
  @obj = nil
@@ -33,7 +34,7 @@ module GlooLang
33
34
  # Load the objects from the file.
34
35
  #
35
36
  def load
36
- unless File.exist?( @pn )
37
+ unless @mech.exist?( @pn )
37
38
  @engine.log.error "File '#{@pn}' does not exist."
38
39
  return
39
40
  end
@@ -43,7 +44,7 @@ module GlooLang
43
44
  @parent_stack = []
44
45
  @parent = @engine.heap.root
45
46
  @parent_stack.push @parent
46
- f = File.open( @pn, 'r' )
47
+ f = @mech.read( @pn )
47
48
  f.each_line do |line|
48
49
  next if skip_line? line
49
50
 
@@ -13,6 +13,7 @@ module GlooLang
13
13
  #
14
14
  def initialize( engine, pn, obj )
15
15
  @engine = engine
16
+ @mech = @engine.platform.getFileMech( @engine )
16
17
  @pn = pn
17
18
  @obj = obj
18
19
  end
@@ -22,7 +23,7 @@ module GlooLang
22
23
  #
23
24
  def save
24
25
  data = get_obj( @obj )
25
- File.write( @pn, data )
26
+ @mech.write( @pn, data )
26
27
  end
27
28
 
28
29
  #
@@ -10,7 +10,7 @@ module GlooLang
10
10
  module Persist
11
11
  class PersistMan
12
12
 
13
- attr_reader :maps
13
+ attr_reader :maps, :mech
14
14
 
15
15
  #
16
16
  # Contructor for the persistence manager.
@@ -18,6 +18,7 @@ module GlooLang
18
18
  def initialize( engine )
19
19
  @engine = engine
20
20
  @maps = []
21
+ @mech = @engine.platform.getFileMech( @engine )
21
22
  end
22
23
 
23
24
  #
@@ -72,18 +73,9 @@ module GlooLang
72
73
  return nil if name.strip.empty?
73
74
 
74
75
  if name.strip[ -1 ] == '*'
75
- pns = []
76
- dir = File.join( @engine.settings.project_path, name[ 0..-2 ] )
77
- Dir.glob( "#{dir}*.gloo" ).each do |f|
78
- pns << f
79
- end
80
- return pns
76
+ return @mech.get_all_files_in( name[ 0..-2 ] )
81
77
  else
82
- ext_path = File.expand_path( name )
83
- return [ ext_path ] if self.gloo_file?( ext_path )
84
-
85
- full_name = "#{name}#{file_ext}"
86
- return [ File.join( @engine.settings.project_path, full_name ) ]
78
+ return @mech.expand( name )
87
79
  end
88
80
  end
89
81
 
@@ -91,19 +83,14 @@ module GlooLang
91
83
  # Check to see if a given path name refers to a gloo object file.
92
84
  #
93
85
  def gloo_file?( name )
94
- return false unless name
95
- return false unless File.exist?( name )
96
- return false unless File.file?( name )
97
- return false unless name.end_with?( self.file_ext )
98
-
99
- return true
86
+ return @mech.valid?( name )
100
87
  end
101
88
 
102
89
  #
103
90
  # Get the default file extention.
104
91
  #
105
92
  def file_ext
106
- return '.gloo'
93
+ return @mech.file_ext
107
94
  end
108
95
 
109
96
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo-lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-04 00:00:00.000000000 Z
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -274,6 +274,7 @@ files:
274
274
  - lib/gloo_lang/objs/web/slack.rb
275
275
  - lib/gloo_lang/objs/web/teams.rb
276
276
  - lib/gloo_lang/objs/web/uri.rb
277
+ - lib/gloo_lang/persist/disc_mech.rb
277
278
  - lib/gloo_lang/persist/file_loader.rb
278
279
  - lib/gloo_lang/persist/file_saver.rb
279
280
  - lib/gloo_lang/persist/file_storage.rb