pincushion 0.1.0 → 0.2.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.
- checksums.yaml +5 -5
- data/lib/pincushion/plugins/csv_serializer.rb +6 -7
- data/lib/pincushion/version.rb +1 -1
- data/lib/pincushion.rb +8 -11
- data/spec/pincushion_spec.rb +21 -6
- metadata +12 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: adbd27566528f46d79e0fd15bf71936ed29382d6de0515557e274692bb427400
|
4
|
+
data.tar.gz: ad694d4c37d67c482573857938886cb8e2d212c38cf053f23f2846c73cea4efb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1d878b8ec0d3a5f3609b1df590cf39b7b889563c4b566d25f02b3123a561f424b5623e91d9d736f5b1f370a836b5d33a643499a3ee3127a5744bd9ab3c8bf16
|
7
|
+
data.tar.gz: b854ce1141ccaaefb3580ba7336810c321b05ec4e13fefe73ba5265d60f4f7d957e248450bdff62ce6f2fb88945917c026e4a04a40f70fd062d6546528113e27
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'csv'
|
2
2
|
|
3
3
|
module Pincushion
|
4
|
-
def self.from_csv(csv,
|
5
|
-
|
6
|
-
|
7
|
-
from_rows(CSV.parse(csv, *args).map(&:to_h))
|
4
|
+
def self.from_csv(csv, opts = {})
|
5
|
+
opts = opts.merge(Plugins::CsvSerializer::OPTS)
|
6
|
+
from_rows(CSV.parse(csv, **opts).map(&:to_hash))
|
8
7
|
end
|
9
8
|
|
10
9
|
module Plugins
|
@@ -22,10 +21,10 @@ module Pincushion
|
|
22
21
|
}.freeze
|
23
22
|
|
24
23
|
module RootModuleMethods
|
25
|
-
def to_csv(
|
26
|
-
|
24
|
+
def to_csv(opts)
|
25
|
+
opts[:headers] ||= [:identifier, *predicates]
|
27
26
|
|
28
|
-
CSV.generate(
|
27
|
+
CSV.generate(**opts) do |csv|
|
29
28
|
rows.each { |row| csv << row }
|
30
29
|
end
|
31
30
|
end
|
data/lib/pincushion/version.rb
CHANGED
data/lib/pincushion.rb
CHANGED
@@ -54,9 +54,6 @@ module Pincushion
|
|
54
54
|
fail "Predicates can't be changed after initialization" if @predicates
|
55
55
|
@predicates = Set.new(preds)
|
56
56
|
is_not(*@predicates)
|
57
|
-
@predicates.each do |predicate|
|
58
|
-
alias_method(:"is_#{predicate}?", :"#{predicate}?")
|
59
|
-
end
|
60
57
|
end
|
61
58
|
end # module RootModuleMethods
|
62
59
|
|
@@ -69,7 +66,7 @@ module Pincushion
|
|
69
66
|
|
70
67
|
def all_predicates_hash
|
71
68
|
obj = new ""
|
72
|
-
predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }
|
69
|
+
Hash[predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }]
|
73
70
|
end
|
74
71
|
|
75
72
|
def identifiers
|
@@ -102,17 +99,17 @@ module Pincushion
|
|
102
99
|
end
|
103
100
|
|
104
101
|
def that_are(*preds)
|
105
|
-
Pincushion.validate(
|
106
|
-
|
107
|
-
mod.include
|
102
|
+
Pincushion.validate(predicate_pincushion_root, preds)
|
103
|
+
base = self
|
104
|
+
mod = Module.new { include base }
|
108
105
|
mod.is(*preds)
|
109
106
|
mod
|
110
107
|
end
|
111
108
|
|
112
109
|
def that_is(*preds)
|
113
|
-
Pincushion.validate(
|
114
|
-
|
115
|
-
klass.include
|
110
|
+
Pincushion.validate(predicate_pincushion_root, preds)
|
111
|
+
base = self
|
112
|
+
klass = Class.new { include base }
|
116
113
|
klass.is(*preds)
|
117
114
|
klass
|
118
115
|
end
|
@@ -141,7 +138,7 @@ module Pincushion
|
|
141
138
|
end
|
142
139
|
|
143
140
|
def all_predicates_hash
|
144
|
-
all_predicates.map { |p| [p, is?(p)] }
|
141
|
+
Hash[all_predicates.map { |p| [p, is?(p)] }]
|
145
142
|
end
|
146
143
|
|
147
144
|
def is(*preds)
|
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,10 +42,12 @@ 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
|
|
48
|
+
elephants = animals.that_are(:herbivore)
|
49
|
+
elephants.that_is.named("Tree Trunks")
|
50
|
+
|
50
51
|
assert_raises Pincushion::MissingPredicateError do
|
51
52
|
animals.that_is(:carnivore)
|
52
53
|
end
|
@@ -67,8 +68,7 @@ describe Pincushion do
|
|
67
68
|
end
|
68
69
|
|
69
70
|
it "doesn't allow unregistered predicates (empty set)" do
|
70
|
-
animals = Module.new
|
71
|
-
animals.include Pincushion
|
71
|
+
animals = Module.new { include Pincushion }
|
72
72
|
assert_raises Pincushion::MissingPredicateError do
|
73
73
|
animals.that_is(:carnivore)
|
74
74
|
end
|
@@ -92,4 +92,19 @@ describe Pincushion do
|
|
92
92
|
animals.plugin :json_serializer
|
93
93
|
assert_equal animals.to_json, animal_data_json
|
94
94
|
end
|
95
|
+
|
96
|
+
it "creates question-mark methods, not is-methods" do
|
97
|
+
animals = Module.new { include Pincushion }
|
98
|
+
animals.predicates :herbivore
|
99
|
+
elephants = animals.that_is(:herbivore)
|
100
|
+
assert elephants.new("").herbivore?
|
101
|
+
|
102
|
+
assert_raises(NoMethodError) do
|
103
|
+
elephants.new("").is_herbivore
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_raises(NoMethodError) do
|
107
|
+
elephants.new("").is_herbivore?
|
108
|
+
end
|
109
|
+
end
|
95
110
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pincushion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Miller
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
19
|
+
version: '0'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: minitest
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +38,7 @@ dependencies:
|
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '5.0'
|
55
|
-
description:
|
41
|
+
description:
|
56
42
|
email: bmiller@rackspace.com
|
57
43
|
executables: []
|
58
44
|
extensions: []
|
@@ -69,13 +55,13 @@ homepage: https://github.com/bjmllr/pincushion
|
|
69
55
|
licenses:
|
70
56
|
- MIT
|
71
57
|
metadata: {}
|
72
|
-
post_install_message:
|
58
|
+
post_install_message:
|
73
59
|
rdoc_options: []
|
74
60
|
require_paths:
|
75
61
|
- lib
|
76
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
63
|
requirements:
|
78
|
-
- - "
|
64
|
+
- - ">="
|
79
65
|
- !ruby/object:Gem::Version
|
80
66
|
version: '2.0'
|
81
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -84,12 +70,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
70
|
- !ruby/object:Gem::Version
|
85
71
|
version: '0'
|
86
72
|
requirements: []
|
87
|
-
|
88
|
-
|
89
|
-
signing_key:
|
73
|
+
rubygems_version: 3.1.6
|
74
|
+
signing_key:
|
90
75
|
specification_version: 4
|
91
76
|
summary: Predicate-centric classification toolkit
|
92
77
|
test_files:
|
93
78
|
- spec/pincushion_spec.rb
|
94
79
|
- spec/spec_helper.rb
|
95
|
-
has_rdoc:
|