frozen_record 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/lib/frozen_record/base.rb +5 -2
- data/lib/frozen_record/version.rb +1 -1
- data/spec/fixtures/countries.yml +3 -3
- data/spec/frozen_record_spec.rb +11 -2
- data/spec/spec_helper.rb +0 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad19f85347f51987f1a255fe74a2a4916eb5142
|
4
|
+
data.tar.gz: dc414922b4275665bf3b8e17bf7a2cf3421e6072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba5c169a4137855ca8e7c2c11e103c7a6063e5eea198ce3b32a9d1fa93323a359a6fe7d064a9783b2a65fc3ab5a550f585cb533910c196a98912c86083b7daf9
|
7
|
+
data.tar.gz: ce52b5baa783a5e515ca7692e5d786e1cc61d3443d294d55a5cca7856d6852d98fb7bd16f79350959fb6f06872c6159611e75bd3c97c4de68f645fbb6f9581fd
|
data/.travis.yml
CHANGED
data/lib/frozen_record/base.rb
CHANGED
@@ -51,7 +51,7 @@ module FrozenRecord
|
|
51
51
|
:minimum, :maximum, :average, :sum, to: :current_scope
|
52
52
|
|
53
53
|
def file_path
|
54
|
-
|
54
|
+
fail ArgumentError, "You must define `#{name}.base_path`" unless base_path
|
55
55
|
File.join(base_path, "#{name.underscore.pluralize}.yml")
|
56
56
|
end
|
57
57
|
|
@@ -85,7 +85,10 @@ module FrozenRecord
|
|
85
85
|
|
86
86
|
def load_records
|
87
87
|
@records ||= begin
|
88
|
-
|
88
|
+
yml_erb_data = File.read(file_path)
|
89
|
+
yml_data = ERB.new(yml_erb_data).result
|
90
|
+
|
91
|
+
records = YAML.load(yml_data) || []
|
89
92
|
define_attributes!(list_attributes(records))
|
90
93
|
records.map(&method(:new)).freeze
|
91
94
|
end
|
data/spec/fixtures/countries.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
- id: 1
|
3
3
|
name: Canada
|
4
|
-
capital: Ottawa
|
4
|
+
capital: <%= 'Ottawa' %>
|
5
5
|
density: 3.5
|
6
6
|
population: 33.88
|
7
7
|
founded_on: 1867-07-01
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
- id: 2
|
13
13
|
name: France
|
14
|
-
capital: Paris
|
14
|
+
capital: <%= 'Paris' %>
|
15
15
|
density: 116
|
16
16
|
population: 65.7
|
17
17
|
founded_on: 486-01-01
|
@@ -19,7 +19,7 @@
|
|
19
19
|
|
20
20
|
- id: 3
|
21
21
|
name: Austria
|
22
|
-
capital: Vienna
|
22
|
+
capital: <%= 'Vienna' %>
|
23
23
|
density: 100.3
|
24
24
|
population: 8.462
|
25
25
|
founded_on: 1156-01-01
|
data/spec/frozen_record_spec.rb
CHANGED
@@ -5,10 +5,19 @@ describe FrozenRecord::Base do
|
|
5
5
|
describe '.base_path' do
|
6
6
|
|
7
7
|
it 'raise a RuntimeError on first query attempt if not set' do
|
8
|
-
Country.
|
8
|
+
allow(Country).to receive_message_chain(:base_path).and_return(nil)
|
9
9
|
expect {
|
10
10
|
Country.file_path
|
11
|
-
}.to raise_error
|
11
|
+
}.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#load_records' do
|
17
|
+
|
18
|
+
it 'processes erb' do
|
19
|
+
country = Country.first
|
20
|
+
expect(country.capital).to be == 'Ottawa'
|
12
21
|
end
|
13
22
|
|
14
23
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,6 @@ FrozenRecord::Base.base_path = File.join(File.dirname(__FILE__), 'fixtures')
|
|
17
17
|
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
|
18
18
|
|
19
19
|
RSpec.configure do |config|
|
20
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
21
20
|
config.run_all_when_everything_filtered = true
|
22
21
|
config.filter_run :focus
|
23
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -152,4 +152,3 @@ test_files:
|
|
152
152
|
- spec/spec_helper.rb
|
153
153
|
- spec/support/car.rb
|
154
154
|
- spec/support/country.rb
|
155
|
-
has_rdoc:
|