frozen_record 0.7.1 → 0.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: 275b29fe63b81841f976203d89605b9a9a5c6289
4
- data.tar.gz: 4243044175796dec9f623da8e9e1a589eef85994
3
+ metadata.gz: 5477acbd4ee7ae0a0fcdfe48f71d323d00468780
4
+ data.tar.gz: 8d5eb8ed257ea8c244754c1e181b8cac7c3da91b
5
5
  SHA512:
6
- metadata.gz: f4de4b60e0cee0988b3aaae4fab620958e034d2d22057cf7d4c896b3ec879295c0d3340576e9a388cd6b5e77d3bf581ed08eb3542cc6d51a5a0ad5cd79a254c7
7
- data.tar.gz: 531c13fa6479eabbc5662910ff92173851cb06949a51e781523379ac6089cfb2b1c0cce8b0e1b1b861c45ada84ac8ab88b31472f222b375832edc41fd700d14a
6
+ metadata.gz: 766bd1bc51a4a3550cb1f0c393ebff069acea8f2315d969aa7ecd706792f1bc0e37a2796d01576aef597b540bf456889b60ae9bf45eff2081c06189f951116d7
7
+ data.tar.gz: ac701b3390eead9b097f7fa0a89aa2c8ef9bb1a2602dd4f2b97b20084b2d8c789e6645919bfe3df667be3444be76e963a263657c73eee50df480664abbabbe32
data/.travis.yml CHANGED
@@ -2,6 +2,6 @@ sudo: false
2
2
  before_install:
3
3
  - gem install bundler
4
4
  rvm:
5
- - '2.1'
6
- - '2.2'
7
- - '2.3.1'
5
+ - '2.2.3'
6
+ - '2.3.3'
7
+ - '2.4.0'
@@ -1,7 +1,9 @@
1
1
  require 'set'
2
+ require 'active_support/descendants_tracker'
2
3
 
3
4
  module FrozenRecord
4
5
  class Base
6
+ extend ActiveSupport::DescendantsTracker
5
7
  extend ActiveModel::Naming
6
8
  include ActiveModel::Conversion
7
9
  include ActiveModel::AttributeMethods
@@ -42,6 +44,11 @@ module FrozenRecord
42
44
  end
43
45
 
44
46
  class << self
47
+ attr_accessor :abstract_class
48
+
49
+ def abstract_class?
50
+ defined?(@abstract_class) && @abstract_class
51
+ end
45
52
 
46
53
  def current_scope
47
54
  store[:scope] ||= Scope.new(self)
@@ -56,7 +63,7 @@ module FrozenRecord
56
63
  :minimum, :maximum, :average, :sum, :count, to: :current_scope
57
64
 
58
65
  def file_path
59
- fail ArgumentError, "You must define `#{name}.base_path`" unless base_path
66
+ raise ArgumentError, "You must define `#{name}.base_path`" unless base_path
60
67
  File.join(base_path, "#{name.underscore.pluralize}.yml")
61
68
  end
62
69
 
@@ -67,6 +74,16 @@ module FrozenRecord
67
74
  end
68
75
  end
69
76
 
77
+ def eager_load!
78
+ if auto_reloading
79
+ raise RuntimeError, "There is no point eager loading a FrozenRecord if auto_reloading is enabled!"
80
+ end
81
+
82
+ return if abstract_class?
83
+
84
+ load_records
85
+ end
86
+
70
87
  def load_records
71
88
  if auto_reloading && file_changed?
72
89
  @records = nil
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/frozen_record.rb CHANGED
@@ -9,4 +9,10 @@ require 'frozen_record/base'
9
9
 
10
10
  module FrozenRecord
11
11
  RecordNotFound = Class.new(StandardError)
12
+
13
+ class << self
14
+ def eager_load!
15
+ Base.descendants.each(&:eager_load!)
16
+ end
17
+ end
12
18
  end
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,8 @@ FrozenRecord::Base.base_path = File.join(File.dirname(__FILE__), 'fixtures')
16
16
 
17
17
  Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
18
18
 
19
+ FrozenRecord.eager_load!
20
+
19
21
  RSpec.configure do |config|
20
22
  config.run_all_when_everything_filtered = true
21
23
  config.filter_run :focus
@@ -0,0 +1,3 @@
1
+ class AbstractModel < FrozenRecord::Base
2
+ self.abstract_class = true
3
+ end
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.7.1
4
+ version: 0.8.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: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -118,6 +118,7 @@ files:
118
118
  - spec/frozen_record_spec.rb
119
119
  - spec/scope_spec.rb
120
120
  - spec/spec_helper.rb
121
+ - spec/support/abstract_model.rb
121
122
  - spec/support/car.rb
122
123
  - spec/support/country.rb
123
124
  homepage: https://github.com/byroot/frozen_record
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  version: '0'
141
142
  requirements: []
142
143
  rubyforge_project:
143
- rubygems_version: 2.4.6
144
+ rubygems_version: 2.5.1
144
145
  signing_key:
145
146
  specification_version: 4
146
147
  summary: ActiveRecord like interface to read only access and query static YAML files
@@ -150,5 +151,6 @@ test_files:
150
151
  - spec/frozen_record_spec.rb
151
152
  - spec/scope_spec.rb
152
153
  - spec/spec_helper.rb
154
+ - spec/support/abstract_model.rb
153
155
  - spec/support/car.rb
154
156
  - spec/support/country.rb