scheherazade 0.1.1 → 0.1.2
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.
- checksums.yaml +7 -0
- data/README.md +3 -3
- data/Rakefile +3 -9
- data/lib/scheherazade/bare.rb +1 -1
- data/lib/scheherazade/character_builder.rb +1 -1
- data/lib/scheherazade/current_hash.rb +55 -0
- data/lib/scheherazade/story.rb +10 -11
- data/lib/scheherazade/version.rb +1 -1
- metadata +19 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d624c9331ac258bae8c1cad405214505c3295cc3
|
4
|
+
data.tar.gz: d2c0f723ce6c5bf83bd92eacbb8623edc880bf23
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: caa91c5084c99072d4c8cc0ecf6cdbec4a980d36767979ff3481f73a7585b6e6176d09fcbcaf037669e9eda9ba7a394ecf64e967f7b38175d71960a8a9ff6867
|
7
|
+
data.tar.gz: 3e46fff4918ed4eb9a77c58be70bcbf54025113be08a085806a4852a2c73000caa941278e8fbeab48245fed4e9b193048bfe0deb8d66040718babe27256e5731
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Scheherazade
|
1
|
+
# Scheherazade [](https://travis-ci.org/marcandre/scheherazade) [](http://badge.fury.io/rb/scheherazade)
|
2
2
|
|
3
3
|
With Sheherazade's imagination and storytelling skills, fixtures can be as entertaining as the "Arabian Nights".
|
4
4
|
|
@@ -24,8 +24,8 @@ Scheherazade
|
|
24
24
|
# with a default name,
|
25
25
|
# associated to a new Company
|
26
26
|
story.imagine(Department) # creates another Department
|
27
|
-
|
28
|
-
|
27
|
+
# with another name
|
28
|
+
# and associated to the same Company
|
29
29
|
|
30
30
|
## Features
|
31
31
|
|
data/Rakefile
CHANGED
@@ -25,14 +25,8 @@ end
|
|
25
25
|
|
26
26
|
Bundler::GemHelper.install_tasks
|
27
27
|
|
28
|
-
require '
|
29
|
-
|
30
|
-
Rake::TestTask.new(:test) do |t|
|
31
|
-
t.libs << 'lib'
|
32
|
-
t.libs << 'test'
|
33
|
-
t.pattern = 'test/**/*_test.rb'
|
34
|
-
t.verbose = false
|
35
|
-
end
|
28
|
+
require 'rspec/core/rake_task'
|
36
29
|
|
30
|
+
RSpec::Core::RakeTask.new(:spec)
|
37
31
|
|
38
|
-
task :default => :
|
32
|
+
task :default => :spec
|
data/lib/scheherazade/bare.rb
CHANGED
@@ -94,7 +94,7 @@ module Scheherazade
|
|
94
94
|
when :has_one
|
95
95
|
ar
|
96
96
|
when :has_many
|
97
|
-
if ar && ar.persisted?
|
97
|
+
if ar.respond_to?(:persisted?) && ar.persisted?
|
98
98
|
if ar.send(assoc.active_record.name.underscore) != @ar
|
99
99
|
log :additional_character, assoc.name
|
100
100
|
[self.class.new(associated_character).build(opts)]
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Scheherazade
|
2
|
+
|
3
|
+
# A subclass of Hash, with automatic lookup up
|
4
|
+
# the story chain and ability to restore the characters
|
5
|
+
#
|
6
|
+
class CurrentHash < Hash
|
7
|
+
def initialize(story)
|
8
|
+
@restore = []
|
9
|
+
super() do |h, k|
|
10
|
+
if (char = story.to_character!(k))
|
11
|
+
h[char]
|
12
|
+
else
|
13
|
+
if up = story.parent
|
14
|
+
h[k] = remember(up.current[k])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# restore all characters borrowed to parent stories
|
21
|
+
# to their original state.
|
22
|
+
#
|
23
|
+
def restore
|
24
|
+
@restore.each_slice(3) do |obj, instance_variable_names, values|
|
25
|
+
instance_variable_names.zip(values) do |iv, val|
|
26
|
+
obj.instance_variable_set(iv, val)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
# Implementation note: the reason why we remember the object
|
35
|
+
# and then reset it, instead of attempting to clone it is
|
36
|
+
# that active record doesn't implement a meaningful clone
|
37
|
+
# and dup creates a different object altogether.
|
38
|
+
#
|
39
|
+
# Attempting to clone an AR object, including it's loaded relations
|
40
|
+
# would require playing too close to the metal and would be too brittle
|
41
|
+
#
|
42
|
+
def remember(object)
|
43
|
+
return object unless object
|
44
|
+
ivs = object.instance_variables
|
45
|
+
@restore << object << ivs << ivs.map do |iv|
|
46
|
+
v = object.instance_variable_get(iv)
|
47
|
+
v = v.clone if v.duplicable?
|
48
|
+
v
|
49
|
+
end
|
50
|
+
object
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/scheherazade/story.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Scheherazade
|
2
|
+
class RedefinitionError < Exception
|
3
|
+
end
|
4
|
+
|
2
5
|
class Story < Hash
|
3
|
-
attr_reader :fill_attributes, :characters, :counter, :current
|
6
|
+
attr_reader :fill_attributes, :characters, :counter, :current, :parent
|
4
7
|
|
5
8
|
module ClassMethods
|
6
9
|
def current
|
@@ -19,7 +22,7 @@ module Scheherazade
|
|
19
22
|
# to the previous current story
|
20
23
|
#
|
21
24
|
def end(opts = nil)
|
22
|
-
current.send :rollback
|
25
|
+
current.send :rollback, opts && opts[:rollback]
|
23
26
|
Thread.current[:scheherazade_stories].pop
|
24
27
|
current
|
25
28
|
end
|
@@ -59,13 +62,7 @@ module Scheherazade
|
|
59
62
|
def initialize(parent = self.class.current)
|
60
63
|
super(){|h, k| parent[k] if parent }
|
61
64
|
@parent = parent
|
62
|
-
@current =
|
63
|
-
if (char = to_character!(k))
|
64
|
-
h[char]
|
65
|
-
else
|
66
|
-
parent.current[k] if parent
|
67
|
-
end
|
68
|
-
end
|
65
|
+
@current = CurrentHash.new(self)
|
69
66
|
@fill_attributes = Hash.new{|h, k| parent.fill_attributes[k] if parent }
|
70
67
|
@characters = Hash.new {|h, k| parent.characters[k] if parent }
|
71
68
|
@counter = parent ? parent.counter.dup : Hash.new(0)
|
@@ -145,6 +142,7 @@ module Scheherazade
|
|
145
142
|
|
146
143
|
def fill(character_or_model, *with)
|
147
144
|
char = to_character(character_or_model)
|
145
|
+
raise RedefinitionError, "#{char} already defined for this story" if fill_attributes.has_key? char
|
148
146
|
fill_attributes[char] = with
|
149
147
|
@characters[char] = current_fill unless to_model(char)
|
150
148
|
begin
|
@@ -177,8 +175,9 @@ module Scheherazade
|
|
177
175
|
end
|
178
176
|
end
|
179
177
|
|
180
|
-
def rollback
|
181
|
-
|
178
|
+
def rollback(hard)
|
179
|
+
current.restore
|
180
|
+
@built.each(&:destroy) if hard
|
182
181
|
end
|
183
182
|
|
184
183
|
def building(ar)
|
data/lib/scheherazade/version.rb
CHANGED
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheherazade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marc-André Lafortune
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: sqlite3
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec-rails
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: With Sheherazade's imagination and storytelling skills, fixtures can
|
@@ -67,44 +60,38 @@ executables: []
|
|
67
60
|
extensions: []
|
68
61
|
extra_rdoc_files: []
|
69
62
|
files:
|
63
|
+
- MIT-LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/scheherazade.rb
|
70
67
|
- lib/scheherazade/bare.rb
|
71
68
|
- lib/scheherazade/character_builder.rb
|
69
|
+
- lib/scheherazade/current_hash.rb
|
72
70
|
- lib/scheherazade/extension.rb
|
73
71
|
- lib/scheherazade/log.rb
|
74
72
|
- lib/scheherazade/story.rb
|
75
73
|
- lib/scheherazade/version.rb
|
76
|
-
- lib/scheherazade.rb
|
77
|
-
- MIT-LICENSE
|
78
|
-
- Rakefile
|
79
|
-
- README.md
|
80
74
|
homepage: http://github.com/marcandre/scheherazade
|
81
75
|
licenses: []
|
76
|
+
metadata: {}
|
82
77
|
post_install_message:
|
83
78
|
rdoc_options: []
|
84
79
|
require_paths:
|
85
80
|
- lib
|
86
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
82
|
requirements:
|
89
|
-
- -
|
83
|
+
- - ">="
|
90
84
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
hash: -946841948511242031
|
85
|
+
version: 1.9.0
|
95
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
87
|
requirements:
|
98
|
-
- -
|
88
|
+
- - ">="
|
99
89
|
- !ruby/object:Gem::Version
|
100
90
|
version: '0'
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
hash: -946841948511242031
|
104
91
|
requirements: []
|
105
92
|
rubyforge_project:
|
106
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.2.2
|
107
94
|
signing_key:
|
108
|
-
specification_version:
|
95
|
+
specification_version: 4
|
109
96
|
summary: Entertaining fixtures for Rails
|
110
97
|
test_files: []
|