hitsuji 0.2.0 → 0.2.1

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hitsuji +44 -0
  3. data/lib/hitsuji.rb +8 -2
  4. data/lib/transfer.rb +11 -6
  5. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38c0f6feab71c738601bce1ff568e1b0890520dfd78885f3879268e572ad4a28
4
- data.tar.gz: 6fb893b80f070b0f3ccf4613ac2d0d57986392a83c02f30b0114e1a60e0f749b
3
+ metadata.gz: d3912e8f0e280fa4d52a32b4e0bca248effd6f2f4e40fffc204b34b33f848219
4
+ data.tar.gz: d74c445355211b3e8b391cb685b9d99cf6f3ce9d7f2c5b411239e115894b554c
5
5
  SHA512:
6
- metadata.gz: b8c0cfd160acff4a02eb0128c596d592d305c3614cf0b949fa59a5b51165044a6cccc742e9bba8fba928ae477d7413aa340206ea33ba6794b7760da67c98517e
7
- data.tar.gz: 3aa84897e872f6908b0e2806004b899fecb5833b4639b2d4e0e31ea11a0a0791951a117cde373bd4503e37f7184f96f3c7e192c32e89cb6c01f51255d1a27102
6
+ metadata.gz: 6fa911f19e45220bdee43a983b71b9c5af65b772facf572c053801c78e8500492e4f8007ab162ed79443684d2ce3f8ee37c4dd55410fbbac8382d6c57bde4388
7
+ data.tar.gz: cae1ac537c14570d5a674e62969d674694c6612ea590872f882ee6ecd6ddc925aebc637f381ccfb49767fed4f3c96004c241627d40ba9e407855930d3af14bc7
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ HELP = 'Usage: hitsuji <command>
5
+
6
+ where <command> is one of:
7
+ convert Converts Hitsuji file to YAML file or vice versa
8
+ metadata Displays the metadata of a Hitsuji file
9
+
10
+ hitsuji help <command> Display specific help for a command
11
+ hitsuji -h, --help Display this help page
12
+ hitsuji -v, --version Show the installed version number
13
+ '.freeze
14
+
15
+ spec = Gem::Specification.load('hitsuji.gemspec')
16
+ VERSION = "Hitsuji v#{spec.version} @ #{File.expand_path(__FILE__)}".freeze
17
+
18
+ def parse_commands
19
+ extra_args = ARGV[1..-1].join(' ') if ARGV[1..-1]
20
+
21
+ case ARGV[0]
22
+ when 'help'
23
+ command = "ruby -Ilib #{__dir__}/commands/help #{extra_args}"
24
+ when 'convert'
25
+ command = "ruby -Ilib #{__dir__}/commands/convert #{extra_args}"
26
+ when 'metadata'
27
+ command = "ruby -Ilib #{__dir__}/commands/metadata #{extra_args}"
28
+ end
29
+
30
+ exec command
31
+ end
32
+
33
+ def parse
34
+ case ARGV[0]
35
+ when '-h', '--help', nil
36
+ puts HELP
37
+ when '-v', '--version'
38
+ puts VERSION
39
+ else
40
+ parse_commands
41
+ end
42
+ end
43
+
44
+ parse
@@ -12,6 +12,10 @@ class Hitsuji
12
12
  # my_system = Hitsuji.new
13
13
  def initialize
14
14
  @struct = []
15
+ @metadata = {
16
+ date_created: `date`,
17
+ date_edited: `date`
18
+ }
15
19
  end
16
20
 
17
21
  # Creates a new item, the equivalent of a variable in the system.
@@ -118,7 +122,7 @@ class Hitsuji
118
122
  # my_system.bind(my_item) # binds item
119
123
  # my_system.export('newfile.hitsuji') # exports to 'newfile.txt'
120
124
  def export(directory)
121
- Transfer.export(directory, @struct)
125
+ Transfer.export(directory, @struct, @metadata)
122
126
  end
123
127
 
124
128
  # Imports a file into a system, *overwriting anything already bound to the
@@ -133,7 +137,7 @@ class Hitsuji
133
137
  # my_system = Hitsuji.new # a new system
134
138
  # my_system.import('oldfile.hitsuji') # imports 'oldfile.txt'
135
139
  def import(directory)
136
- @struct = Transfer.import(directory)
140
+ @struct, @metadata = Transfer.import(directory)
137
141
  update @struct
138
142
  end
139
143
 
@@ -212,6 +216,8 @@ class Hitsuji
212
216
  throw 'err' unless i.name.nil? || !names.include?(i.name)
213
217
  names << update(i.value) if i.class == Linker
214
218
  end
219
+
220
+ @metadata[:date_edited] = `date`
215
221
  names
216
222
  end
217
223
 
@@ -1,20 +1,25 @@
1
1
  require_relative 'subsystem.rb'
2
2
 
3
- # @private
3
+ # The Transfer class manages the importing and exporting of Hitsuji files. This
4
+ # functionality is normally accessed through Hitsuji#import and Hitsuji#export.
5
+ # Transfer.export also does not work independently, and must be used through the
6
+ # Hitsuji#export function.
4
7
  class Transfer
5
- def self.export(directory, struct)
8
+ def self.export(directory, struct, metadata)
6
9
  throw 'err' unless directory.end_with?('.hitsuji')
7
10
  File.open(directory, 'w') do |file|
8
- encoded = Marshal.dump(struct)
9
- file.write([encoded].pack('u'))
11
+ raw_data = { struct: struct, metadata: metadata }
12
+ serialized_data = [Marshal.dump(raw_data)].pack('u')
13
+ file.write serialized_data
10
14
  end
11
15
  end
12
16
 
13
17
  def self.import(directory)
14
18
  throw 'err' unless directory.end_with?('.hitsuji')
15
19
  File.open(directory, 'r') do |file|
16
- decoded = file.read.unpack('u')
17
- return Marshal.load(decoded.first)
20
+ serialized_data = file.read.unpack('u')
21
+ raw_data = Marshal.load(serialized_data.first)
22
+ return raw_data[:struct], raw_data[:metadata]
18
23
  end
19
24
  end
20
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hitsuji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Quail
@@ -16,10 +16,12 @@ description: |-
16
16
  databases to performance analysis all the way to complete content management
17
17
  systems (like Wordpress.com).
18
18
  email: josh@madbean.com
19
- executables: []
19
+ executables:
20
+ - hitsuji
20
21
  extensions: []
21
22
  extra_rdoc_files: []
22
23
  files:
24
+ - bin/hitsuji
23
25
  - lib/hitsuji.rb
24
26
  - lib/subsystem.rb
25
27
  - lib/transfer.rb
@@ -29,7 +31,7 @@ licenses:
29
31
  metadata:
30
32
  source_code_uri: https://github.com/realtable/hitsuji
31
33
  bug_tracker_uri: https://github.com/realtable/hitsuji/issues
32
- documentation_uri: https://www.rubydoc.info/gems/hitsuji/0.2.0
34
+ documentation_uri: https://www.rubydoc.info/gems/hitsuji/0.2.1
33
35
  post_install_message:
34
36
  rdoc_options: []
35
37
  require_paths: