brief 1.7.3 → 1.8.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 +4 -4
- data/Gemfile.lock +3 -3
- data/lib/brief/briefcase.rb +12 -0
- data/lib/brief/configuration.rb +3 -1
- data/lib/brief/data.rb +58 -0
- data/lib/brief/document_mapper.rb +6 -0
- data/lib/brief/version.rb +1 -1
- data/lib/brief.rb +2 -0
- data/spec/fixtures/example/data/items.json +1 -0
- data/spec/fixtures/example/docs/concept.html.md +1 -1
- data/spec/lib/brief/data_spec.rb +17 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b414746de1313eabc5f64d32bafe473099cc2d5
|
4
|
+
data.tar.gz: cb3f076ee49965246f2e0bb6a3e9bc90d0c7f20f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7fd7e64d649737ebd6caa4536d12756447f6cdeebfb83c7c85a94a7569494393d293da50a18fa68458b57ad21752c44bd2300b9df09e9ed3b7b72557ab22bd7
|
7
|
+
data.tar.gz: 724f46bddea7aeb0f82ea8deb81ae5e5b1e3c8c2adf8a00d970c6a6d64731ab63d9de86c168d53d06ef9fea62d1f51b25ef174fbb2bf21879d077ae4beb7d439
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
brief (1.7.
|
4
|
+
brief (1.7.3)
|
5
5
|
activemodel
|
6
6
|
activesupport (>= 4.0)
|
7
7
|
commander (>= 4.2.1)
|
@@ -57,7 +57,7 @@ GEM
|
|
57
57
|
multipart-post (2.0.0)
|
58
58
|
nokogiri (1.6.6.2)
|
59
59
|
mini_portile (~> 0.6.0)
|
60
|
-
octokit (3.
|
60
|
+
octokit (3.8.0)
|
61
61
|
sawyer (~> 0.6.0, >= 0.5.3)
|
62
62
|
pry (0.10.1)
|
63
63
|
coderay (~> 1.1.0)
|
@@ -86,7 +86,7 @@ GEM
|
|
86
86
|
addressable (~> 2.3.5)
|
87
87
|
faraday (~> 0.8, < 0.10)
|
88
88
|
slop (3.6.0)
|
89
|
-
thread_safe (0.3.
|
89
|
+
thread_safe (0.3.5)
|
90
90
|
tzinfo (1.2.2)
|
91
91
|
thread_safe (~> 0.1)
|
92
92
|
virtus (1.0.4)
|
data/lib/brief/briefcase.rb
CHANGED
@@ -80,6 +80,14 @@ module Brief
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
def data
|
84
|
+
@data ||= data!
|
85
|
+
end
|
86
|
+
|
87
|
+
def data!
|
88
|
+
@data = Brief::Data::Wrapper.new(root: data_path)
|
89
|
+
end
|
90
|
+
|
83
91
|
def config(&block)
|
84
92
|
Brief::Configuration.instance.tap do |cfg|
|
85
93
|
cfg.instance_eval(&block) if block.respond_to?(:call)
|
@@ -171,6 +179,10 @@ module Brief
|
|
171
179
|
root.join options.fetch(:docs_path) { config.docs_path }
|
172
180
|
end
|
173
181
|
|
182
|
+
def data_path
|
183
|
+
root.join options.fetch(:data_path) { config.data_path }
|
184
|
+
end
|
185
|
+
|
174
186
|
def models_path
|
175
187
|
value = options.fetch(:models_path) { config.models_path }
|
176
188
|
|
data/lib/brief/configuration.rb
CHANGED
data/lib/brief/data.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Brief
|
2
|
+
module Data
|
3
|
+
class Queryable
|
4
|
+
def initialize(array)
|
5
|
+
@array = Array(array)
|
6
|
+
end
|
7
|
+
|
8
|
+
def where(*args, &block)
|
9
|
+
Brief::DocumentMapper::Query.new(@array).send(:where, *args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(meth, *args, &block)
|
13
|
+
@array.send(meth,*args,&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class Wrapper
|
19
|
+
attr_accessor :sources, :root
|
20
|
+
|
21
|
+
def initialize(options={})
|
22
|
+
@root = options.fetch(:root) { Pathname(Dir.pwd).join('data') }
|
23
|
+
@sources = {}.to_mash
|
24
|
+
|
25
|
+
load_files.each do |source, data|
|
26
|
+
@sources[source] = Queryable.new(data)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(meth, *args, &block)
|
31
|
+
return sources.send(meth, *args, &block) if sources.key?(meth)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_files
|
36
|
+
files = Dir[root.join("**/*.yml")] + Dir[root.join("**/*.json")] + Dir[root.join("**/*.yaml")]
|
37
|
+
|
38
|
+
files.map! do |file|
|
39
|
+
path = Pathname(file)
|
40
|
+
|
41
|
+
if path.extname == ".json"
|
42
|
+
key = "#{path.basename.to_s.gsub(/\.json$/i, '')}"
|
43
|
+
data = JSON.parse(path.read)
|
44
|
+
elsif path.extname == '.yml' || path.extname == ".yaml"
|
45
|
+
key = "#{path.basename.to_s.gsub(/\.ya?ml$/i, '')}"
|
46
|
+
data = YAML.load(path.read)
|
47
|
+
else
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
{key => data} if key && data
|
52
|
+
end
|
53
|
+
|
54
|
+
files.compact.reduce({}) {|memo, hash| memo.merge(hash) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -77,10 +77,16 @@ module Brief::DocumentMapper
|
|
77
77
|
match = true
|
78
78
|
|
79
79
|
@where.each do |selector, value|
|
80
|
+
obj = obj.symbolize_keys if obj.is_a?(Hash)
|
81
|
+
|
80
82
|
if obj.respond_to?(selector.attribute)
|
81
83
|
test_value = obj.send(selector.attribute)
|
82
84
|
operator = OPERATOR_MAPPING[selector.operator]
|
83
85
|
match = false unless test_value.send(operator, value)
|
86
|
+
elsif obj.key?(selector.attribute.to_sym)
|
87
|
+
test_value = obj.send(:[], selector.attribute.to_sym)
|
88
|
+
operator = OPERATOR_MAPPING[selector.operator]
|
89
|
+
match = false unless test_value.send(operator, value)
|
84
90
|
else
|
85
91
|
match = false
|
86
92
|
end
|
data/lib/brief/version.rb
CHANGED
data/lib/brief.rb
CHANGED
@@ -94,6 +94,8 @@ require 'brief/model'
|
|
94
94
|
require 'brief/model/definition'
|
95
95
|
require 'brief/model/persistence'
|
96
96
|
require 'brief/model/serializers'
|
97
|
+
require 'brief/model/serializers'
|
98
|
+
require 'brief/data'
|
97
99
|
require 'brief/dsl'
|
98
100
|
require 'brief/server'
|
99
101
|
require 'brief/briefcase'
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"id":0,"name":"Item 0","status":"active"},{"id":1,"name":"Item 1","status":"inactive"},{"id":2,"name":"Item 2","status":"active"}]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Brief Data Wrapper" do
|
4
|
+
let(:briefcase) { Brief.testcase }
|
5
|
+
|
6
|
+
it "lets me query the items data" do
|
7
|
+
expect(briefcase.data.items.where(status: "inactive").length).to eq(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "lets me query the items data" do
|
11
|
+
expect(briefcase.data.items.where(status: "active").length).to eq(2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "gives me the data" do
|
15
|
+
expect(briefcase.data.items.length).to eq(3)
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brief
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Soeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -259,6 +259,7 @@ files:
|
|
259
259
|
- lib/brief/cli/write.rb
|
260
260
|
- lib/brief/configuration.rb
|
261
261
|
- lib/brief/core_ext.rb
|
262
|
+
- lib/brief/data.rb
|
262
263
|
- lib/brief/document.rb
|
263
264
|
- lib/brief/document/content_extractor.rb
|
264
265
|
- lib/brief/document/front_matter.rb
|
@@ -294,6 +295,7 @@ files:
|
|
294
295
|
- spec/acceptance/showing_spec.rb
|
295
296
|
- spec/fixtures/apps/sample/config.rb
|
296
297
|
- spec/fixtures/example/brief.rb
|
298
|
+
- spec/fixtures/example/data/items.json
|
297
299
|
- spec/fixtures/example/docs/concept.html.md
|
298
300
|
- spec/fixtures/example/docs/epics/epic.html.md
|
299
301
|
- spec/fixtures/example/docs/page.html.md
|
@@ -312,6 +314,7 @@ files:
|
|
312
314
|
- spec/fixtures/structures/two.html.md
|
313
315
|
- spec/lib/brief/apps_spec.rb
|
314
316
|
- spec/lib/brief/briefcase_spec.rb
|
317
|
+
- spec/lib/brief/data_spec.rb
|
315
318
|
- spec/lib/brief/document_spec.rb
|
316
319
|
- spec/lib/brief/dsl_spec.rb
|
317
320
|
- spec/lib/brief/hashing_spec.rb
|
@@ -370,6 +373,7 @@ test_files:
|
|
370
373
|
- spec/acceptance/showing_spec.rb
|
371
374
|
- spec/fixtures/apps/sample/config.rb
|
372
375
|
- spec/fixtures/example/brief.rb
|
376
|
+
- spec/fixtures/example/data/items.json
|
373
377
|
- spec/fixtures/example/docs/concept.html.md
|
374
378
|
- spec/fixtures/example/docs/epics/epic.html.md
|
375
379
|
- spec/fixtures/example/docs/page.html.md
|
@@ -388,6 +392,7 @@ test_files:
|
|
388
392
|
- spec/fixtures/structures/two.html.md
|
389
393
|
- spec/lib/brief/apps_spec.rb
|
390
394
|
- spec/lib/brief/briefcase_spec.rb
|
395
|
+
- spec/lib/brief/data_spec.rb
|
391
396
|
- spec/lib/brief/document_spec.rb
|
392
397
|
- spec/lib/brief/dsl_spec.rb
|
393
398
|
- spec/lib/brief/hashing_spec.rb
|