awesome-cheeba 1.0.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.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-04-20
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,96 @@
1
+ .cheeba.gemspec.swp
2
+ .git/COMMIT_EDITMSG
3
+ .git/HEAD
4
+ .git/config
5
+ .git/description
6
+ .git/hooks/applypatch-msg.sample
7
+ .git/hooks/commit-msg.sample
8
+ .git/hooks/post-commit.sample
9
+ .git/hooks/post-receive.sample
10
+ .git/hooks/post-update.sample
11
+ .git/hooks/pre-applypatch.sample
12
+ .git/hooks/pre-commit.sample
13
+ .git/hooks/pre-rebase.sample
14
+ .git/hooks/prepare-commit-msg.sample
15
+ .git/hooks/update.sample
16
+ .git/index
17
+ .git/info/exclude
18
+ .git/logs/HEAD
19
+ .git/logs/refs/heads/master
20
+ .git/logs/refs/remotes/origin/master
21
+ .git/objects/02/38dae53aee5cb4ea157a3f036b93868ede9593
22
+ .git/objects/02/9cafaafb83e528381f0f2f02c6f23799bd1942
23
+ .git/objects/07/c654f9ff6c65626369b061c595be42ccdd6cd7
24
+ .git/objects/07/dbbace3b24b2d635d2fb637581931d573fc75c
25
+ .git/objects/08/ce1195151ff5a51573a871947ecd913fb5aa0f
26
+ .git/objects/0c/ad63d44505490e1a30ad075099a25020d7a7c5
27
+ .git/objects/12/215629eba6a8f0fcd849923e98a471984521e1
28
+ .git/objects/18/60fee2fadb59a6cbcb7f7dd0a6f6dc3b56ac79
29
+ .git/objects/1e/1800628b80bef5a8043e4adacd6ebc6bab9aa1
30
+ .git/objects/27/97bc2b3d72dc6d77b7bd07f1cca96f7e06b4ed
31
+ .git/objects/28/41d3f97c8aa8c942a613e1c69ed4280d78cf0a
32
+ .git/objects/29/f0c4074f9ecc894edd7ed507a1a92499838a6d
33
+ .git/objects/2a/8948661c63f2bef24f330638d239c88d5d0c2e
34
+ .git/objects/3f/7142cf3878c65e71b54d3572d82837d20f2aa7
35
+ .git/objects/40/8c36a3103bc77e90db86dc06b1598e3baa4c2d
36
+ .git/objects/42/eb5558727a2144e7c5e997d3e6aea5486eaf37
37
+ .git/objects/4c/6098fe05db7126c8a3c97f463910e5cc398630
38
+ .git/objects/51/6902dffff8d29fa2f89979b9cd81ab275e1c67
39
+ .git/objects/5b/502f8e20a0556c22727b504108a2dc36d7cbed
40
+ .git/objects/67/c3fb20cfae5320d83c9ebf2b85c1a3ef9b706b
41
+ .git/objects/72/7df703ac52c4ff97aa452feee27b9990430a11
42
+ .git/objects/74/bc14252b2148d11877025d7f445d2fa686e7e9
43
+ .git/objects/78/9ac5e1ca6a70ec3b8a11344e6f4a03e440f309
44
+ .git/objects/7a/46bd1887d1a793094da678ded3b53b0208b826
45
+ .git/objects/8d/77306c0d13e98da74ddf48002674fced7e1618
46
+ .git/objects/94/36859cb89dd0bbddab77ed0810860e979b1c05
47
+ .git/objects/ab/454c9537f329aecaedae0586c6d61146a7f819
48
+ .git/objects/b9/3b5dde3104bb495dc0d2970bbe617dafb2f084
49
+ .git/objects/be/197d3b2c14a52300cc4553bf2004ef3c45a45b
50
+ .git/objects/be/8e3e0ab878ffcb0456ae4cf66861888d933bf5
51
+ .git/objects/c5/4c515f4bff81e08b01176b1a5743fd773a9740
52
+ .git/objects/d4/a471f188d32adfa9dc2ff22c53b95319a162ed
53
+ .git/objects/d7/83399b37ca769b5b5bc2b33727fc47acfa5e4c
54
+ .git/objects/d7/a544fc5715014ef027875545ef0145e9f694fe
55
+ .git/objects/de/eef72f84f60beab439c58d84acc42d3e5a1279
56
+ .git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
57
+ .git/objects/e9/9c40e89cb90f8067f99d7051c3bebf2b145ec7
58
+ .git/objects/f3/89737a46e7cad94deb222e238e8f926767637e
59
+ .git/objects/fa/4f98b2fe387e262f9c28011e53f1b8fb920401
60
+ .git/objects/fb/72047097c38625f3598fb348b3fbe75afd6d2d
61
+ .git/objects/ff/7aefe3472c61b77f58669ec4b8208412156930
62
+ .git/refs/heads/master
63
+ .git/refs/remotes/origin/master
64
+ History.txt
65
+ Manifest.txt
66
+ README.txt
67
+ Rakefile
68
+ bin/cheeba
69
+ cheeba.gemspec
70
+ lib/cheeba.rb
71
+ lib/cheeba/defaults.rb
72
+ lib/cheeba/errors.rb
73
+ lib/cheeba/indicators.rb
74
+ lib/cheeba/reader.rb
75
+ lib/cheeba/reader/builder.rb
76
+ lib/cheeba/reader/format.rb
77
+ lib/cheeba/reader/node.rb
78
+ lib/cheeba/reader/parser.rb
79
+ lib/cheeba/version.rb
80
+ lib/cheeba/writer.rb
81
+ lib/cheeba/writer/builder.rb
82
+ test/.test_writer.rb.swp
83
+ test/files/arrays.cash
84
+ test/files/blank.cash
85
+ test/files/comments.cash
86
+ test/files/hashes.cash
87
+ test/files/malformed.cash
88
+ test/files/mixed.cash
89
+ test/files/split.cash
90
+ test/test_cheeba.rb
91
+ test/test_reader.rb
92
+ test/test_reader_builder.rb
93
+ test/test_reader_format.rb
94
+ test/test_reader_parser.rb
95
+ test/test_writer.rb
96
+ test/test_writer_builder.rb
data/README.txt ADDED
@@ -0,0 +1,33 @@
1
+ = Cheeba
2
+
3
+ * http://github.com/awesome/cheeba/tree/master
4
+ * http://wiki.github.com/awesome/cheeba
5
+ * http://awesomelicense.com
6
+
7
+ == DESCRIPTION:
8
+
9
+ Simple data serialization serialization for only the Ruby Programming Language.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * FIX (list of features or problems)
14
+
15
+ == SYNOPSIS:
16
+
17
+ * FIX (code sample of usage)
18
+
19
+ == REQUIREMENTS:
20
+
21
+ * FIX (list of requirements)
22
+
23
+ == INSTALL:
24
+
25
+ sudo gem install cheeba
26
+
27
+ == LICENSE:
28
+
29
+ (The Awesome License)
30
+
31
+ Copyright (c) 2008 So Awesome Man
32
+
33
+ Awesome License (Open Source) goes here!
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
6
+ require 'cheeba'
7
+
8
+ require './lib/cheeba.rb'
9
+ Hoe.new('cheeba', Cheeba::VERSION) do |p|
10
+ p.developer('So Awesome Man', 'callme@1800AWESO.ME')
11
+ end
12
+
13
+ # vim: syntax=Ruby
data/bin/cheeba ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+ require 'pp'
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'cheeba'
8
+
9
+ module CheebaOpt
10
+ DESC = Cheeba::Defaults.descriptions
11
+ def self.command
12
+ hsh = {}
13
+ hsh[:opt] = {}
14
+ ops = nil
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Cheeba #{Cheeba::VERSION}"
17
+ opts.on("-r", "--read FILENAME", String, String, ".cash file to Ruby Hash or Array") do |x|
18
+ hsh[:cmd] = 1
19
+ hsh[:arg] = [x]
20
+ end
21
+
22
+ opts.on("-w", "--write FILENAME,FILENAME", Array, "Hash or Array => .cash file") do |x|
23
+ hsh[:cmd] = 2
24
+ hsh[:arg] = x
25
+ end
26
+
27
+ opts.on("-d", "--dotfile [HOME]", String, "Create .cheeba dotfile") do |x|
28
+ x.nil? ? (y = Cheeba.dotfile) : (y = Cheeba.dotfile(x))
29
+ z = "#{File.dirname(y).chomp("/")}/.cheeba"
30
+ puts "existed: #{z}, moved to: #{y}" if File.basename(y) != ".cheeba"
31
+ puts "created: #{z}"
32
+ return
33
+ end
34
+
35
+ opts.on("-v", "--version", "Display verison number") do
36
+ STDOUT.write("Cheeba #{Cheeba::VERSION}\n\r")
37
+ return
38
+ end
39
+
40
+ opts.on("-h", "--help", "Show this message") do
41
+ puts opts
42
+ return
43
+ end
44
+
45
+ Cheeba::Defaults.constants.sort.each do |x|
46
+ next if x == "DOTFILE"
47
+ opts.on("--[no-]#{x.downcase}", DESC[x.downcase]) do |y|
48
+ hsh[:opt]["#{x.downcase}".to_sym] = y
49
+ puts "use options with --read or --write" && return if hsh[:cmd].nil?
50
+ end
51
+ end
52
+ ops = opts
53
+ end.parse!
54
+ puts ops unless hsh.has_key?(:cmd)
55
+ return unless hsh.has_key?(:cmd)
56
+ self.run(hsh[:cmd], hsh[:arg], hsh[:opt])
57
+ end
58
+
59
+ def self.run(cmd, arg, opt)
60
+ x = Cheeba.read(arg[0], opt)
61
+ case cmd
62
+ when 1: pp x
63
+ when 2: Cheeba.write(arg[0], arg[1], opt)
64
+ end
65
+ end
66
+ end
67
+
68
+ CheebaOpt.command
data/cheeba.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{cheeba}
5
+ s.version = "1.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["So Awesome Man"]
9
+ s.date = %q{2009-04-20}
10
+ s.default_executable = %q{cheeba}
11
+ s.description = %q{Simple data serialization serialization for only the Ruby Programming Language.}
12
+ s.email = ["callme@1800AWESO.ME"]
13
+ s.executables = ["cheeba"]
14
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
15
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/cheeba", "cheeba.gemspec", "lib/cheeba.rb", "lib/cheeba/defaults.rb", "lib/cheeba/errors.rb", "lib/cheeba/indicators.rb", "lib/cheeba/reader.rb", "lib/cheeba/reader/builder.rb", "lib/cheeba/reader/format.rb", "lib/cheeba/reader/node.rb", "lib/cheeba/reader/parser.rb", "lib/cheeba/version.rb", "lib/cheeba/writer.rb", "lib/cheeba/writer/builder.rb", "test/files/arrays.cash", "test/files/blank.cash", "test/files/comments.cash", "test/files/hashes.cash", "test/files/malformed.cash", "test/files/mixed.cash", "test/files/split.cash", "test/test_cheeba.rb", "test/test_reader.rb", "test/test_reader_builder.rb", "test/test_reader_format.rb", "test/test_reader_parser.rb", "test/test_writer.rb", "test/test_writer_builder.rb"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://awesomebrandname.com}
18
+ s.rdoc_options = ["--main", "README.txt"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{cheeba}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{Simple data serialization serialization for only the Ruby Programming Language.}
23
+ s.test_files = ["test/test_cheeba.rb", "test/test_reader.rb", "test/test_reader_builder.rb", "test/test_reader_format.rb", "test/test_reader_parser.rb", "test/test_writer.rb", "test/test_writer_builder.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
31
+ else
32
+ s.add_dependency(%q<hoe>, [">= 1.8.2"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<hoe>, [">= 1.8.2"])
36
+ end
37
+ end
data/lib/cheeba.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'cheeba/version'
2
+ require 'cheeba/reader'
3
+ require 'cheeba/writer'
4
+ require 'cheeba/indicators'
5
+ require 'cheeba/defaults'
6
+
7
+ module Cheeba
8
+ DOTFILE = "#{ENV['HOME']}/.cheeba"
9
+ #
10
+ # File to Hash or Array
11
+ #
12
+ def self.read(input, options = {})
13
+ Cheeba::Reader.read(input, self.options(options))
14
+ end
15
+
16
+ #
17
+ # Hash or Array to .cash Array
18
+ #
19
+ def self.parse(object, options = {})
20
+ Cheeba::Writer.build(object, self.options(options))
21
+ end
22
+
23
+ #
24
+ # Hash or Array to .cash-file, e.g. filename.cash
25
+ #
26
+ def self.write(object, filename, options = {})
27
+ Cheeba::Writer.write(object, filename, self.options(options))
28
+ end
29
+
30
+ #
31
+ # writes a .cheeba file HOME, merges with options if :dot is true
32
+ #
33
+ def self.dotfile(home = ENV['HOME'])
34
+ Cheeba::Writer.dotfile(Cheeba::Defaults.options, home)
35
+ end
36
+
37
+ private
38
+
39
+ #
40
+ # options
41
+ #
42
+ def self.options(options = {})
43
+ opt = Cheeba::Defaults.options.merge(Cheeba::Indicators.options.merge(options))
44
+ dot_opt = File.exists?(DOTFILE) ? Cheeba::Reader.read(DOTFILE, opt.merge({:symbolize_keys => true})) : nil
45
+ unless opt[:dot]
46
+ opt = opt.merge(dot_opt) if (dot_opt && dot_opt[:dot])
47
+ end
48
+ opt
49
+ end
50
+ end
@@ -0,0 +1,69 @@
1
+ module Cheeba
2
+ module Defaults
3
+ INT = true
4
+ INT_KEYS = false
5
+ INT_VALS = false
6
+ SYMBOLIZE = false
7
+ SYMBOLIZE_KEYS = false
8
+ SYMBOLIZE_VALS = false
9
+ AUTO_SYM = true
10
+ AUTO_SYM_KEYS = false
11
+ AUTO_SYM_VALS = false
12
+ AUTO_TRUE = true
13
+ AUTO_TRUE_KEYS = false
14
+ AUTO_TRUE_VALS = false
15
+ STRIP = true
16
+ STRIP_KEYS = false
17
+ STRIP_VALS = false
18
+ LIST = false
19
+ DOT = true
20
+ DOTFILE = "#{ENV['HOME']}/.cheeba"
21
+ YAML = false
22
+ DOCS = false
23
+
24
+ def self.descriptions
25
+ { "auto_sym" => "conv keys & vals: \":both\" => :both",
26
+ "auto_sym_keys" => "conv keys: \":key\" => :key",
27
+ "auto_sym_vals" => "conv vals: \":val\" => :val",
28
+ "auto_true" => "conv keys & vals: \"true\" => true",
29
+ "auto_true_keys" => "conv keys: \"true\" => true",
30
+ "auto_true_vals" => "conv vals: \"true\" => true",
31
+ "docs" => "doc separator first level hash nodes",
32
+ "dot" => "use dotfile if it exists",
33
+ "int" => "conv keys & vals: \"1\" => 1",
34
+ "int_keys" => "conv keys: \"1\" => 1",
35
+ "int_vals" => "conv vals: \"1\" => 1",
36
+ "list" => "return hash of addresses & comments",
37
+ "strip" => "strip keys & vals: \" both \" => \"both\"",
38
+ "strip_keys" => "strip keys: \" key \" => \"key\"",
39
+ "strip_vals" => "strip vals: \" val \" => \"val\"",
40
+ "symbolize" => "force conv keys & vals: \"both\" => :both",
41
+ "symbolize_keys" => "force conv keys: \"key\" => :key",
42
+ "symbolize_vals" => "force conv vals: \"val\" => :val",
43
+ "yaml" => "write files with YAML type array syntax"}
44
+ end
45
+
46
+ def self.options
47
+ { :int => INT,
48
+ :int_keys => INT_KEYS,
49
+ :int_vals => INT_VALS,
50
+ :symbolize => SYMBOLIZE,
51
+ :symbolize_keys => SYMBOLIZE_KEYS,
52
+ :symbolize_vals => SYMBOLIZE_VALS,
53
+ :auto_sym => AUTO_SYM,
54
+ :auto_sym_keys => AUTO_SYM_KEYS,
55
+ :auto_sym_vals => AUTO_SYM_VALS,
56
+ :auto_true => AUTO_TRUE,
57
+ :auto_true_keys => AUTO_TRUE_KEYS,
58
+ :auto_true_vals => AUTO_TRUE_VALS,
59
+ :strip => STRIP,
60
+ :strip_keys => STRIP_KEYS,
61
+ :strip_vals => STRIP_VALS,
62
+ :list => LIST,
63
+ :dot => DOT,
64
+ :dotfile => DOTFILE,
65
+ :yaml => YAML,
66
+ :docs => DOCS}
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ module Cheeba
2
+ module Errors
3
+ class EmptyFilenameError < StandardError; end
4
+ class EmptyInputError < StandardError; end
5
+ class InvalidInputError < StandardError; end
6
+ class InvalidFilenameError < StandardError; end
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,25 @@
1
+ module Cheeba
2
+ module Indicators
3
+ DOC_START = '---'
4
+ DOC_TERM = '...'
5
+ HASH = ':'
6
+ SYMBOL = ':'
7
+ ARRAY = '-'
8
+ COMMENT = '#'
9
+ LINE_END = "\n"
10
+ SPACE = "\s"
11
+ INDENT = 2
12
+
13
+ def self.options
14
+ { :doc_start => DOC_START,
15
+ :doc_term => DOC_TERM,
16
+ :hash => HASH,
17
+ :symbol => SYMBOL,
18
+ :array => ARRAY,
19
+ :comment => COMMENT,
20
+ :line_end => LINE_END,
21
+ :space => SPACE,
22
+ :indent => INDENT }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'cheeba/reader/node'
2
+ require 'cheeba/reader/format'
3
+ require 'cheeba/reader/builder'
4
+ require 'cheeba/reader/parser'
5
+
6
+ module Cheeba
7
+ module Reader
8
+ class EmptyFileError < StandardError; end
9
+ class EmptyInputError < StandardError; end
10
+ class InvalidInputError < StandardError; end
11
+ #
12
+ # parses file or string into Ruby Array, or Hash
13
+ #
14
+ def self.read(input, options)
15
+ raise Cheeba::Reader::EmptyInputError if (input.is_a?(String) && input.strip.empty?)
16
+ raise Cheeba::Reader::InvalidInputError unless (input.is_a?(String) or input.is_a?(File))
17
+ input = IO.readlines(input) if File.exists?(input)
18
+ raise Cheeba::Reader::EmptyFileError if input.empty?
19
+ hash = {}
20
+ lineno = 0
21
+ input.each {|line|
22
+ parsed_hash = Cheeba::Reader::Parser.parse(line, options, (lineno += 1))
23
+ formatted_hash = Cheeba::Reader::Format.format(parsed_hash)
24
+ Cheeba::Reader::Builder.build(hash, formatted_hash)
25
+ }
26
+ hash.delete(:adr)
27
+ case
28
+ when options[:list]: hash
29
+ when !options[:list]: hash.delete(:lst) && (hash.length == 1) ? hash[1] : hash
30
+ end
31
+ end
32
+ end
33
+ end