yaml_b_sides 0.5.4 → 0.6.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: 38528f28487b4fee667f601cdc9e2781e746c008
4
- data.tar.gz: 618a5537afdfa020e9c385d567699f45df12a3db
3
+ metadata.gz: 45adeca9c08395b043daad3db4e33e0b94795901
4
+ data.tar.gz: 1086182181619ef1eca880e287f36f304a60fc7f
5
5
  SHA512:
6
- metadata.gz: e1ee24700b632b362c12a9a2a915cc7cceaf34a2497d162b3453f500c81b9c56c80a295b8ca69ab1630ebd6706c6e4daadf04c5129a50ec690f76e51a4b8e64d
7
- data.tar.gz: 132c93cab0ba2b73c22b4dc2d2192a28cb7224d485482c8e466c1781ee647b84089057331ceca2aa916107e9d9e10c2bf8bf79dbe133d2e940f183fe4bd34280
6
+ metadata.gz: a735ae884e248753f0a3db63c9e25632d094ba46694c0dcbbaf6d9ef810ad20b1d2c68800b9369bc671bac8cc8e8828dd9e8935791a33bf26d97cdf26bc844ff
7
+ data.tar.gz: f369847c980b4af239d1cbdd9c735b07f73da28b64b79d21e49a8bd10596a706c1cad21b60421ef3e00273e1dcae2c2d70b51e3472ea2d4aeaa9a4e8c57117ff
data/README.md CHANGED
@@ -198,6 +198,11 @@ The setup is pretty straightforward. Yaml B-Sides wants a logger and a base dir
198
198
  ```ruby
199
199
  YamlBSides::Base.logger = Rails.logger
200
200
  YamlBSides::Base.root_path = Rails.root.join 'db', 'fixtures'
201
+
202
+ # in development.rb
203
+
204
+ # eanble reload of the data files to avoid having to restart the server for every change
205
+ YamlBSides.live_reload = true
201
206
  ```
202
207
 
203
208
  ## Development
data/lib/yaml_b_sides.rb CHANGED
@@ -18,4 +18,10 @@ module YamlBSides
18
18
  autoload :Indexable, 'yaml_b_sides/indexable'
19
19
  autoload :Propertiable, 'yaml_b_sides/propertiable'
20
20
  autoload :Queriable, 'yaml_b_sides/queriable'
21
+
22
+ class << self
23
+ attr_accessor :live_reload
24
+ end
25
+
26
+ self.live_reload = false
21
27
  end
@@ -18,7 +18,7 @@ module YamlBSides
18
18
  idify_data!
19
19
  logger.info "#{self} successfully loaded data"
20
20
  # let's preemptively index by id so that when we do a find_by id:, or a where id: it won't table scan
21
- index :id
21
+ index :id unless YamlBSides.live_reload
22
22
  rescue => e
23
23
  logger.error "#{self} failed to load data: #{e}"
24
24
  end
@@ -38,6 +38,11 @@ module YamlBSides
38
38
  v[:id] = k
39
39
  end
40
40
  end
41
+
42
+ def data
43
+ load! if YamlBSides.live_reload
44
+ @data
45
+ end
41
46
  end
42
47
  end
43
48
  end
@@ -5,7 +5,7 @@ module YamlBSides
5
5
  included do
6
6
  class << self
7
7
  def cache_key
8
- @cache_key ||= Digest::SHA256.hexdigest(@data.to_json)
8
+ @cache_key ||= Digest::SHA256.hexdigest(data.to_json)
9
9
  end
10
10
  end
11
11
 
@@ -8,14 +8,14 @@ module YamlBSides
8
8
 
9
9
  class << self
10
10
  def index(field)
11
- self.__indices = __indices.merge( { field => Index.new(field, @data) } )
11
+ self.__indices = __indices.merge( { field => Index.new(field, data) } )
12
12
  end
13
13
 
14
14
  def find_in_index(field, values)
15
15
  keys = Array(index_for(field).find(values))
16
16
 
17
17
  keys.map do |id|
18
- @data[id]
18
+ data[id]
19
19
  end
20
20
  end
21
21
 
@@ -5,7 +5,7 @@ module YamlBSides
5
5
  included do
6
6
  class << self
7
7
  def find(id)
8
- record = @data[id]
8
+ record = data[id]
9
9
  raise Errors::RecordNotFound, "#{self}: Record not found: #{id}" unless record
10
10
  new record
11
11
  end
@@ -17,13 +17,13 @@ module YamlBSides
17
17
  end
18
18
 
19
19
  def all
20
- @data.values.map do |obj|
20
+ data.values.map do |obj|
21
21
  new obj
22
22
  end
23
23
  end
24
24
 
25
25
  def first
26
- new @data.values.first
26
+ new data.values.first
27
27
  end
28
28
 
29
29
  # TODO: move this into scopes
@@ -41,7 +41,7 @@ module YamlBSides
41
41
  private
42
42
 
43
43
  def find_by_scan(params)
44
- @data.values.select do |datum|
44
+ data.values.select do |datum|
45
45
  params.all? do |param, expected_value|
46
46
  val = Array(expected_value).include? datum[param]
47
47
  end
@@ -1,3 +1,3 @@
1
1
  module YamlBSides
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_b_sides
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Orlov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-13 00:00:00.000000000 Z
11
+ date: 2016-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport