pincushion 0.1.0 → 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 +4 -4
- data/lib/pincushion.rb +6 -6
- data/lib/pincushion/plugins/csv_serializer.rb +5 -4
- data/lib/pincushion/version.rb +1 -1
- data/spec/pincushion_spec.rb +3 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 217f846dde4bd0ec90ee69747c5e766fd841077f
|
4
|
+
data.tar.gz: 5629f332f932df0ad0554860424f40c5fc3e0a70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e89c6a58f94dc875efe71cfd32fbf682dcb02cda2a79220e53bf6b67adf8fccaaa5468df074394f52e80c2a31c4c40c4c199fa09f4023dbf82c1aa832c53a55
|
7
|
+
data.tar.gz: f388bcaa354ca75e17d2d961e3767852b70c3c21d4b4c4b9eceb4cf587e43bee6a5ab3ab6845be8604ca309ef6f7ffe122c970e0aa5600abc5c0e83c7cdb2a1c
|
data/lib/pincushion.rb
CHANGED
@@ -69,7 +69,7 @@ module Pincushion
|
|
69
69
|
|
70
70
|
def all_predicates_hash
|
71
71
|
obj = new ""
|
72
|
-
predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }
|
72
|
+
Hash[predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }]
|
73
73
|
end
|
74
74
|
|
75
75
|
def identifiers
|
@@ -103,16 +103,16 @@ module Pincushion
|
|
103
103
|
|
104
104
|
def that_are(*preds)
|
105
105
|
Pincushion.validate(self, preds)
|
106
|
-
|
107
|
-
mod.include
|
106
|
+
base = self
|
107
|
+
mod = Module.new { include base }
|
108
108
|
mod.is(*preds)
|
109
109
|
mod
|
110
110
|
end
|
111
111
|
|
112
112
|
def that_is(*preds)
|
113
113
|
Pincushion.validate(self, preds)
|
114
|
-
|
115
|
-
klass.include
|
114
|
+
base = self
|
115
|
+
klass = Class.new { include base }
|
116
116
|
klass.is(*preds)
|
117
117
|
klass
|
118
118
|
end
|
@@ -141,7 +141,7 @@ module Pincushion
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def all_predicates_hash
|
144
|
-
all_predicates.map { |p| [p, is?(p)] }
|
144
|
+
Hash[all_predicates.map { |p| [p, is?(p)] }]
|
145
145
|
end
|
146
146
|
|
147
147
|
def is(*preds)
|
@@ -4,7 +4,7 @@ module Pincushion
|
|
4
4
|
def self.from_csv(csv, *args)
|
5
5
|
args << {} unless args.last.is_a?(Hash)
|
6
6
|
args.last.merge!(Plugins::CsvSerializer::OPTS)
|
7
|
-
from_rows(CSV.parse(csv, *args).map(&:
|
7
|
+
from_rows(CSV.parse(csv, *args).map(&:to_hash))
|
8
8
|
end
|
9
9
|
|
10
10
|
module Plugins
|
@@ -22,10 +22,11 @@ module Pincushion
|
|
22
22
|
}.freeze
|
23
23
|
|
24
24
|
module RootModuleMethods
|
25
|
-
def to_csv(*args
|
26
|
-
|
25
|
+
def to_csv(*args)
|
26
|
+
args << {} unless args.last.is_a?(Hash)
|
27
|
+
args.last[:headers] ||= [:identifier, *predicates]
|
27
28
|
|
28
|
-
CSV.generate(*args
|
29
|
+
CSV.generate(*args) do |csv|
|
29
30
|
rows.each { |row| csv << row }
|
30
31
|
end
|
31
32
|
end
|
data/lib/pincushion/version.rb
CHANGED
data/spec/pincushion_spec.rb
CHANGED
@@ -32,8 +32,7 @@ describe Pincushion do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "can be used to define a category with properties" do
|
35
|
-
animals = Module.new
|
36
|
-
animals.include Pincushion
|
35
|
+
animals = Module.new { include Pincushion }
|
37
36
|
animals.predicates :carnivore, :herbivore
|
38
37
|
cat = animals.that_is(:carnivore).named("Mee-mow")
|
39
38
|
mittens = animals.find("Mee-mow")
|
@@ -43,8 +42,7 @@ describe Pincushion do
|
|
43
42
|
end
|
44
43
|
|
45
44
|
it "doesn't allow unregistered predicates" do
|
46
|
-
animals = Module.new
|
47
|
-
animals.include Pincushion
|
45
|
+
animals = Module.new { include Pincushion }
|
48
46
|
animals.predicates :herbivore
|
49
47
|
|
50
48
|
assert_raises Pincushion::MissingPredicateError do
|
@@ -67,8 +65,7 @@ describe Pincushion do
|
|
67
65
|
end
|
68
66
|
|
69
67
|
it "doesn't allow unregistered predicates (empty set)" do
|
70
|
-
animals = Module.new
|
71
|
-
animals.include Pincushion
|
68
|
+
animals = Module.new { include Pincushion }
|
72
69
|
assert_raises Pincushion::MissingPredicateError do
|
73
70
|
animals.that_is(:carnivore)
|
74
71
|
end
|