frozen_record 0.20.1 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +29 -0
- data/frozen_record.gemspec +0 -1
- data/lib/frozen_record.rb +2 -27
- data/lib/frozen_record/backends/empty.json +1 -0
- data/lib/frozen_record/backends/json.rb +20 -3
- data/lib/frozen_record/backends/yaml.rb +29 -3
- data/lib/frozen_record/base.rb +5 -11
- data/lib/frozen_record/compact.rb +3 -2
- data/lib/frozen_record/minimal.rb +27 -0
- data/lib/frozen_record/serialization.rb +13 -0
- data/lib/frozen_record/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +7 -18
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b998592ed0453f220a0679b3ee2aea49d1d5381a3a7c4d6e9286434e6e3b6c27
|
4
|
+
data.tar.gz: 3f430857f5b5626951360d2c28402c58b5751cb1ef2805f139558d600b7e1e1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbc8307030df2b393d69499c7be236ef62349ad6f74b7fc9de914260748fd0919e293204b30ba31e377acf157acb90e9371d4ed50a77da955f60222694f74892
|
7
|
+
data.tar.gz: f211b9298137e71e098e841658341f0cceb3dd902f7974a5a9a7c2233173bd1016037832ba744f8966beb9045fa9c93068365ad5d9b7d64f9b68631e1b840ca1
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
11
|
+
name: Ruby ${{ matrix.ruby }} tests
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Setup Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- uses: actions/cache@v2
|
19
|
+
with:
|
20
|
+
path: vendor/bundle
|
21
|
+
key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('Gemfile', 'frozen_record.gemspec') }}
|
22
|
+
restore-keys: |
|
23
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-
|
24
|
+
- name: Bundle install
|
25
|
+
run: |
|
26
|
+
gem install bundler
|
27
|
+
bundle install --jobs 4 --retry 3 --path=vendor/bundle
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rake
|
data/frozen_record.gemspec
CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency 'activemodel'
|
23
23
|
spec.add_runtime_dependency 'dedup'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler'
|
26
25
|
spec.add_development_dependency 'rake'
|
27
26
|
spec.add_development_dependency 'rspec'
|
28
27
|
spec.add_development_dependency 'pry'
|
data/lib/frozen_record.rb
CHANGED
@@ -1,30 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'active_support/all'
|
6
|
-
require 'active_model'
|
7
|
-
|
8
|
-
require 'dedup'
|
9
|
-
|
10
|
-
require 'frozen_record/version'
|
11
|
-
require 'frozen_record/scope'
|
12
|
-
require 'frozen_record/index'
|
13
|
-
require 'frozen_record/base'
|
14
|
-
require 'frozen_record/compact'
|
15
|
-
|
16
|
-
module FrozenRecord
|
17
|
-
RecordNotFound = Class.new(StandardError)
|
18
|
-
|
19
|
-
class << self
|
20
|
-
attr_accessor :deprecated_yaml_erb_backend
|
21
|
-
|
22
|
-
def eager_load!
|
23
|
-
Base.descendants.each(&:eager_load!)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
self.deprecated_yaml_erb_backend = true
|
28
|
-
end
|
29
|
-
|
3
|
+
require 'frozen_record/minimal'
|
4
|
+
require 'frozen_record/serialization'
|
30
5
|
require 'frozen_record/railtie' if defined?(Rails)
|
@@ -0,0 +1 @@
|
|
1
|
+
true
|
@@ -9,9 +9,26 @@ module FrozenRecord
|
|
9
9
|
"#{model_name.underscore.pluralize}.json"
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
if JSON.respond_to?(:load_file)
|
13
|
+
supports_freeze = begin
|
14
|
+
JSON.load_file(File.expand_path('../empty.json', __FILE__), freeze: true)
|
15
|
+
rescue ArgumentError
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
if supports_freeze
|
20
|
+
def load(file_path)
|
21
|
+
JSON.load_file(file_path, freeze: true) || Dedup::EMPTY_ARRAY
|
22
|
+
end
|
23
|
+
else
|
24
|
+
def load(file_path)
|
25
|
+
Dedup.deep_intern!(JSON.load_file(file_path) || Dedup::EMPTY_ARRAY)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
def load(file_path)
|
30
|
+
Dedup.deep_intern!(JSON.parse(File.read(file_path)) || Dedup::EMPTY_ARRAY)
|
31
|
+
end
|
15
32
|
end
|
16
33
|
end
|
17
34
|
end
|
@@ -34,15 +34,41 @@ module FrozenRecord
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
load_string(yml_data)
|
38
38
|
else
|
39
39
|
if file_path.end_with?('.erb')
|
40
|
-
|
40
|
+
load_string(ERB.new(File.read(file_path)).result)
|
41
41
|
else
|
42
|
-
|
42
|
+
load_file(file_path)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
supports_freeze = begin
|
50
|
+
YAML.load_file(File.expand_path('../empty.json', __FILE__), freeze: true)
|
51
|
+
rescue ArgumentError
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
if supports_freeze
|
56
|
+
def load_file(path)
|
57
|
+
YAML.load_file(path, freeze: true) || Dedup::EMPTY_ARRAY
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_string(yaml)
|
61
|
+
YAML.load(yaml, freeze: true) || Dedup::EMPTY_ARRAY
|
62
|
+
end
|
63
|
+
else
|
64
|
+
def load_file(path)
|
65
|
+
Dedup.deep_intern!(YAML.load_file(path) || Dedup::EMPTY_ARRAY)
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_string(yaml)
|
69
|
+
Dedup.deep_intern!(YAML.load(yaml) || Dedup::EMPTY_ARRAY)
|
70
|
+
end
|
71
|
+
end
|
46
72
|
end
|
47
73
|
end
|
48
74
|
end
|
data/lib/frozen_record/base.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'set'
|
4
3
|
require 'active_support/descendants_tracker'
|
5
4
|
require 'frozen_record/backends'
|
6
|
-
require 'objspace'
|
7
5
|
|
8
6
|
module FrozenRecord
|
9
7
|
class Base
|
@@ -11,11 +9,6 @@ module FrozenRecord
|
|
11
9
|
extend ActiveModel::Naming
|
12
10
|
include ActiveModel::Conversion
|
13
11
|
include ActiveModel::AttributeMethods
|
14
|
-
include ActiveModel::Serializers::JSON
|
15
|
-
|
16
|
-
if defined? ActiveModel::Serializers::Xml
|
17
|
-
include ActiveModel::Serializers::Xml
|
18
|
-
end
|
19
12
|
|
20
13
|
FIND_BY_PATTERN = /\Afind_by_(\w+)(!?)/
|
21
14
|
FALSY_VALUES = [false, nil, 0, -''].to_set
|
@@ -52,7 +45,7 @@ module FrozenRecord
|
|
52
45
|
alias_method :set_default_attributes, :default_attributes=
|
53
46
|
private :set_default_attributes
|
54
47
|
def default_attributes=(default_attributes)
|
55
|
-
set_default_attributes(Dedup.deep_intern!(default_attributes.
|
48
|
+
set_default_attributes(Dedup.deep_intern!(default_attributes.transform_keys(&:to_s)))
|
56
49
|
end
|
57
50
|
|
58
51
|
alias_method :set_primary_key, :primary_key=
|
@@ -146,8 +139,9 @@ module FrozenRecord
|
|
146
139
|
|
147
140
|
@records ||= begin
|
148
141
|
records = backend.load(file_path)
|
149
|
-
|
150
|
-
|
142
|
+
if default_attributes
|
143
|
+
records = records.map { |r| assign_defaults!(r.dup).freeze }.freeze
|
144
|
+
end
|
151
145
|
@attributes = list_attributes(records).freeze
|
152
146
|
define_attribute_methods(@attributes.to_a)
|
153
147
|
records = records.map { |r| load(r) }.freeze
|
@@ -164,7 +158,7 @@ module FrozenRecord
|
|
164
158
|
private :load
|
165
159
|
|
166
160
|
def new(attrs = {})
|
167
|
-
load(assign_defaults!(attrs.
|
161
|
+
load(assign_defaults!(attrs.transform_keys(&:to_s)))
|
168
162
|
end
|
169
163
|
|
170
164
|
private
|
@@ -13,8 +13,9 @@ module FrozenRecord
|
|
13
13
|
|
14
14
|
@records ||= begin
|
15
15
|
records = backend.load(file_path)
|
16
|
-
|
17
|
-
|
16
|
+
if default_attributes
|
17
|
+
records = records.map { |r| assign_defaults!(r.dup).freeze }.freeze
|
18
|
+
end
|
18
19
|
@attributes = list_attributes(records).freeze
|
19
20
|
build_attributes_cache
|
20
21
|
define_attribute_methods(@attributes.to_a)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'set'
|
5
|
+
require 'active_model'
|
6
|
+
|
7
|
+
require 'dedup'
|
8
|
+
|
9
|
+
require 'frozen_record/version'
|
10
|
+
require 'frozen_record/scope'
|
11
|
+
require 'frozen_record/index'
|
12
|
+
require 'frozen_record/base'
|
13
|
+
require 'frozen_record/compact'
|
14
|
+
|
15
|
+
module FrozenRecord
|
16
|
+
RecordNotFound = Class.new(StandardError)
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :deprecated_yaml_erb_backend
|
20
|
+
|
21
|
+
def eager_load!
|
22
|
+
Base.descendants.each(&:eager_load!)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
self.deprecated_yaml_erb_backend = true
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.21.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: 2021-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,9 +101,9 @@ executables: []
|
|
115
101
|
extensions: []
|
116
102
|
extra_rdoc_files: []
|
117
103
|
files:
|
104
|
+
- ".github/workflows/main.yml"
|
118
105
|
- ".gitignore"
|
119
106
|
- ".rspec"
|
120
|
-
- ".travis.yml"
|
121
107
|
- Gemfile
|
122
108
|
- LICENSE.txt
|
123
109
|
- README.md
|
@@ -128,13 +114,16 @@ files:
|
|
128
114
|
- frozen_record.gemspec
|
129
115
|
- lib/frozen_record.rb
|
130
116
|
- lib/frozen_record/backends.rb
|
117
|
+
- lib/frozen_record/backends/empty.json
|
131
118
|
- lib/frozen_record/backends/json.rb
|
132
119
|
- lib/frozen_record/backends/yaml.rb
|
133
120
|
- lib/frozen_record/base.rb
|
134
121
|
- lib/frozen_record/compact.rb
|
135
122
|
- lib/frozen_record/index.rb
|
123
|
+
- lib/frozen_record/minimal.rb
|
136
124
|
- lib/frozen_record/railtie.rb
|
137
125
|
- lib/frozen_record/scope.rb
|
126
|
+
- lib/frozen_record/serialization.rb
|
138
127
|
- lib/frozen_record/test_helper.rb
|
139
128
|
- lib/frozen_record/version.rb
|
140
129
|
- spec/fixtures/animals.json
|
@@ -168,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
157
|
- !ruby/object:Gem::Version
|
169
158
|
version: '0'
|
170
159
|
requirements: []
|
171
|
-
rubygems_version: 3.1.
|
160
|
+
rubygems_version: 3.1.4
|
172
161
|
signing_key:
|
173
162
|
specification_version: 4
|
174
163
|
summary: ActiveRecord like interface to read only access and query static YAML files
|