inline_data 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19ab31e371c89d1cf8900e2fbe12bc75c9e64e3a
4
+ data.tar.gz: aa85593d9368e14ce1de3e4602c407800eb225c1
5
+ SHA512:
6
+ metadata.gz: 286e70ccc4f8685833e54ba55e4d980c4d3c12847ca2ac932505633734d9f1a7f8ba788b09d9cde0b615ca4300e0bf457a7bc2ba15fa777ee58140ea8c5e31e5
7
+ data.tar.gz: b4848ffd845d1c74ebc49fa2e3b44c5f5cd7231af9d5dd3c4e723d3ac7159cf40cb0a7de966841b27df8567deeebdca2a3bf4a184de7fe90384bacbe61d4697b
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require './lib/inline_data/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'inline_data'
7
+ spec.version = InlineData::VERSION
8
+ spec.authors = ['Nathan Currier']
9
+ spec.email = ['nathan.currier@gmail.com']
10
+ spec.license = 'MPL-2.0'
11
+
12
+ spec.description = 'Manage program data stored in the program itself'
13
+ spec.summary = 'Manage program data'
14
+ spec.homepage = 'https://github.com/rideliner/inline_data'
15
+ spec.has_rdoc = 'yard'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.bindir = 'bin'
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+ end
@@ -0,0 +1 @@
1
+ require 'inline_data/version'
@@ -0,0 +1,62 @@
1
+
2
+ module InlineData
3
+ class DB
4
+ def file_lock
5
+ @file.flock(File::LOCK_NB | File::LOCK_EX)
6
+ end
7
+
8
+ def initialize(data_store)
9
+ @file = data_store
10
+ @db_pos = @file.pos
11
+ @existed = @db_pos != @file.size
12
+ @data = @existed ? load : nil
13
+ @file.rewind
14
+ @contents = @file.read @db_pos
15
+ end
16
+
17
+ def self.default(file)
18
+ if Kernel.const_defined? :DATA
19
+ new Kernel.const_get :DATA
20
+ else
21
+ from file
22
+ end
23
+ end
24
+
25
+ def self.from(filename)
26
+ f = File.new filename
27
+
28
+ loop do
29
+ line = f.gets
30
+ break if line.nil? || line.chomp == '__END__'
31
+ end
32
+
33
+ new f
34
+ end
35
+
36
+ attr_accessor :data
37
+
38
+ def save
39
+ db_str = dump
40
+
41
+ File.open @file.path, 'w+' do |f|
42
+ f.puts @contents
43
+ f.puts '__END__' unless @existed
44
+ f.puts db_str
45
+ end
46
+ end
47
+
48
+ def close
49
+ @file.close unless @file.nil? || @file.closed?
50
+ end
51
+
52
+ protected
53
+
54
+ def load
55
+ raise NotImplementedError
56
+ end
57
+
58
+ def dump
59
+ raise NotImplementedError
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require 'json'
3
+ require 'inline_data/db'
4
+
5
+ module InlineData
6
+ class JSON < DB
7
+ protected
8
+
9
+ def load
10
+ ::JSON.load @file
11
+ end
12
+
13
+ def dump
14
+ ::JSON.generate @data
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module InlineData
2
+ VERSION = '0.1.1'.freeze
3
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require 'yaml'
3
+ require 'inline_data/db'
4
+
5
+ module InlineData
6
+ class YAML < DB
7
+ protected
8
+
9
+ def load
10
+ ::YAML.load @file
11
+ end
12
+
13
+ def dump
14
+ ::YAML.dump @data
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inline_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Currier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Manage program data stored in the program itself
14
+ email:
15
+ - nathan.currier@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - inline_data.gemspec
21
+ - lib/inline_data.rb
22
+ - lib/inline_data/db.rb
23
+ - lib/inline_data/json.rb
24
+ - lib/inline_data/version.rb
25
+ - lib/inline_data/yaml.rb
26
+ homepage: https://github.com/rideliner/inline_data
27
+ licenses:
28
+ - MPL-2.0
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.6.2
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Manage program data
50
+ test_files: []