brief 1.7.3 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a3acf77feeaf14fa2cd960e182ef9d3983272bb
4
- data.tar.gz: a49c26a0ab788f553faef5e06c2ee4c78935fad8
3
+ metadata.gz: 9b414746de1313eabc5f64d32bafe473099cc2d5
4
+ data.tar.gz: cb3f076ee49965246f2e0bb6a3e9bc90d0c7f20f
5
5
  SHA512:
6
- metadata.gz: d8d95128ea80a9a7b03c49eb1d12cccfdc1792468e2fc713e74d34ff342086a3748d66243969deae46df73876da2d99284ab32e46001a6c6ac23c830fb48747d
7
- data.tar.gz: abfdd1bc9606144883135179ecf6b28316caf9b886c9d33b60eb41057fb4e0a953748ec2c5b7d02fd92ebcd8c937739c9b72e24cd44374bbedf2d047b7e76275
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.2)
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.7.0)
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.4)
89
+ thread_safe (0.3.5)
90
90
  tzinfo (1.2.2)
91
91
  thread_safe (~> 0.1)
92
92
  virtus (1.0.4)
@@ -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
 
@@ -15,7 +15,9 @@ module Brief
15
15
  def current
16
16
  @current ||= {
17
17
  docs_path: 'docs',
18
- models_path: 'models'
18
+ models_path: 'models',
19
+ templates_path: 'templates',
20
+ data_path: 'data'
19
21
  }.to_mash
20
22
  end
21
23
 
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
@@ -1,3 +1,3 @@
1
1
  module Brief
2
- VERSION = '1.7.3'
2
+ VERSION = '1.8.0'
3
3
  end
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"}]
@@ -3,7 +3,7 @@ type: concept
3
3
 
4
4
  ---
5
5
 
6
- # Modified Content tqk61jvbsbeb4igh79e8f3lzic4jxiy2bsvn
6
+ # Modified Content nba3xb1p04i7n5rmnsp9jnd1t0dqlm11lp51
7
7
 
8
8
  1
9
9
 
@@ -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.7.3
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-12 00:00:00.000000000 Z
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