dough 0.1.0
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/README.md +1 -0
- data/lib/dough.rb +46 -0
- data/lib/dough/bread.rb +18 -0
- data/lib/dough/id.rb +34 -0
- data/lib/dough/ingredient.rb +49 -0
- data/lib/dough/masher.rb +48 -0
- data/lib/dough/plain_text_masher.rb +40 -0
- data/lib/dough/section.rb +17 -0
- data/metadata.rb +22 -0
- metadata +59 -0
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Dough
|
data/lib/dough.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path('../../metadata', __FILE__)
|
2
|
+
|
3
|
+
class Dough
|
4
|
+
autoload :Masher, "dough/masher"
|
5
|
+
autoload :PlainTextMasher, "dough/plain_text_masher"
|
6
|
+
autoload :Ingredient, "dough/ingredient"
|
7
|
+
autoload :ID, "dough/id"
|
8
|
+
autoload :Bread, "dough/bread"
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@refs = {}
|
12
|
+
@ingredients = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Put an ingredient into the dough
|
16
|
+
#
|
17
|
+
# ingredient - The ingredient to add
|
18
|
+
#
|
19
|
+
# Returns an id with which to reference the ingredient
|
20
|
+
def add(ingredient)
|
21
|
+
ingredient = Ingredient.new(ingredient) unless ingredient.is_a? Ingredient
|
22
|
+
|
23
|
+
ingredient.freeze
|
24
|
+
|
25
|
+
@ingredients[ingredient.id] = ingredient
|
26
|
+
ingredient.id
|
27
|
+
end
|
28
|
+
alias :<< :add
|
29
|
+
|
30
|
+
# Public: Gets an ingredient
|
31
|
+
#
|
32
|
+
# id - The id of the ingredient
|
33
|
+
#
|
34
|
+
# Returns the ingredient specified by id
|
35
|
+
def get(id)
|
36
|
+
@ingredients[id]
|
37
|
+
end
|
38
|
+
alias :[] :get
|
39
|
+
|
40
|
+
# Deprecated: Bakes the Dough
|
41
|
+
#
|
42
|
+
# Returns a Bread
|
43
|
+
def bake
|
44
|
+
Bread.new self
|
45
|
+
end
|
46
|
+
end
|
data/lib/dough/bread.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "dough"
|
2
|
+
|
3
|
+
class Dough
|
4
|
+
# Deprecated: Baked (Frozen) Dough
|
5
|
+
class Bread
|
6
|
+
# extend Forwardable
|
7
|
+
|
8
|
+
# def_delegators :@dough, :[], :get
|
9
|
+
|
10
|
+
def initialize(dough)
|
11
|
+
# @dough = dough.dup.freeze
|
12
|
+
|
13
|
+
@ingredients = dough.ingredients.dup.freeze
|
14
|
+
|
15
|
+
freeze
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/dough/id.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "dough"
|
2
|
+
require "digest/sha1"
|
3
|
+
|
4
|
+
class Dough
|
5
|
+
class ID
|
6
|
+
attr_reader :ingredient
|
7
|
+
attr_reader :hash
|
8
|
+
attr_reader :sha
|
9
|
+
|
10
|
+
def initialize(ingredient)
|
11
|
+
@ingredient = ingredient
|
12
|
+
# update
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Refresh the id
|
16
|
+
#
|
17
|
+
# Returns self
|
18
|
+
def update
|
19
|
+
@sha = Digest::SHA1.hexdigest ingredient.marshalled
|
20
|
+
@hash = ingredient.marshalled.hash
|
21
|
+
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def eql?(other)
|
26
|
+
other.is_a?(ID) && @hash == other.hash && @sha == other.sha
|
27
|
+
end
|
28
|
+
alias :== :eql?
|
29
|
+
|
30
|
+
def ===(other)
|
31
|
+
self == other || super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "dough"
|
2
|
+
|
3
|
+
class Dough
|
4
|
+
class Ingredient
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_reader :object
|
8
|
+
attr_reader :id
|
9
|
+
|
10
|
+
def_delegators :@id, :==, :eql?
|
11
|
+
|
12
|
+
def initialize(object)
|
13
|
+
@id = ID.new(self)
|
14
|
+
update object
|
15
|
+
|
16
|
+
super()
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(object)
|
20
|
+
@object = object.dup.freeze
|
21
|
+
@id.update # if @id
|
22
|
+
@marshalled = nil
|
23
|
+
@mashed = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def marshalled
|
27
|
+
@marshalled ||= Marshal.dump(@object)
|
28
|
+
end
|
29
|
+
|
30
|
+
def size
|
31
|
+
marshalled.size
|
32
|
+
end
|
33
|
+
|
34
|
+
def mashed(masher = Dough::Masher.default)
|
35
|
+
@mashed[masher] ||= @object.mash(masher.new)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def object=(object)
|
41
|
+
@object = object.dup.freeze
|
42
|
+
end
|
43
|
+
|
44
|
+
# def self.infect(mod = ::Object)
|
45
|
+
# $stderr.puts "Dough::Ingredient.infect: Infecting #{mod.to_s}"
|
46
|
+
# mod.send :include, Ingredient
|
47
|
+
# end
|
48
|
+
end
|
49
|
+
end
|
data/lib/dough/masher.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "dough"
|
2
|
+
|
3
|
+
class Dough
|
4
|
+
# Public: Masher
|
5
|
+
class Masher
|
6
|
+
def initialize
|
7
|
+
@sections = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](name)
|
11
|
+
(@sections[name] ||= Section.new(name)).contents
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(name, contents)
|
15
|
+
(@sections[name] ||= Section.new(name)).contents = contents
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
""
|
20
|
+
end
|
21
|
+
|
22
|
+
def from_s(string)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.default
|
27
|
+
PlainTextMasher
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.from(string)
|
31
|
+
new.from_s(string)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Kernel
|
37
|
+
def mash(masher = Dough::Masher.default.new)
|
38
|
+
instance_variables.each do |name|
|
39
|
+
masher[:instance_variables] += "#{name}=#{instance_variable_get name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
masher
|
43
|
+
end
|
44
|
+
|
45
|
+
def unmash(masher)
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "dough"
|
2
|
+
|
3
|
+
class Dough
|
4
|
+
class PlainTextMasher < Masher
|
5
|
+
def contents
|
6
|
+
@sections.values.map do |section|
|
7
|
+
"#{section.name}(#{section.size})>>#{section.contents.to_s}<<"
|
8
|
+
end.join("\n")
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
contents = self.contents
|
13
|
+
header = "#{@ingredient.object.class} #{contents.size}\n"
|
14
|
+
header + contents
|
15
|
+
end
|
16
|
+
|
17
|
+
def from_s(str)
|
18
|
+
str.gsub! /\A([\:A-Za-z0-9\_]+)/, ''
|
19
|
+
type = $1
|
20
|
+
parts = type.split '::'
|
21
|
+
cla = Object
|
22
|
+
parts.each do |part|
|
23
|
+
cla = cla.const_get part
|
24
|
+
end
|
25
|
+
|
26
|
+
loop do
|
27
|
+
break if str.empty?
|
28
|
+
|
29
|
+
str.gsub! /\A(.*)\((\d+)\)>>/, ''
|
30
|
+
name, size = $~
|
31
|
+
str.gsub! /\A(.{#{size}})<</, ''
|
32
|
+
contents = $1
|
33
|
+
section = Section.new(name, contents)
|
34
|
+
@sections[name] = section
|
35
|
+
end
|
36
|
+
|
37
|
+
self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/metadata.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Dough
|
2
|
+
NAME = "dough"
|
3
|
+
SUMMARY = "An object store"
|
4
|
+
DESCRIPTION = "Dough is #{SUMMARY}"
|
5
|
+
AUTHORS = ["Drew Young"]
|
6
|
+
|
7
|
+
module VERSION
|
8
|
+
MAJOR = 0
|
9
|
+
MINOR = 1
|
10
|
+
PATCH = 0
|
11
|
+
TAG = nil
|
12
|
+
BUILD = nil
|
13
|
+
|
14
|
+
def self.to_a
|
15
|
+
[ MAJOR, MINOR, PATCH, TAG, BUILD ].compact
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.to_s
|
19
|
+
to_a.join '.'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dough
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Drew Young
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Dough is An object store
|
15
|
+
email:
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/dough/bread.rb
|
21
|
+
- lib/dough/id.rb
|
22
|
+
- lib/dough/ingredient.rb
|
23
|
+
- lib/dough/masher.rb
|
24
|
+
- lib/dough/plain_text_masher.rb
|
25
|
+
- lib/dough/section.rb
|
26
|
+
- lib/dough.rb
|
27
|
+
- metadata.rb
|
28
|
+
- README.md
|
29
|
+
homepage:
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
hash: 179971539
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
hash: 179971539
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.11
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: An object store
|
59
|
+
test_files: []
|