fixed_record 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +16 -2
- data/lib/fixed_record.rb +14 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e28a9a9f85d811dca1463d6d5ae8944d0d5fd66a098be6e93a9c86b939f4807
|
|
4
|
+
data.tar.gz: 1849d6bb120d51aa6f275f1bc9c2d8e78166bf492c4e39887ed2fa010dbfa1fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a03e177ac9d18c4ee7bd5f5589cdc9657369cc7444dd7b371ca644ec53c0030d160a2fd76ab3669093e44364baae267e1c165f47d23cbe481c7d2c04b61999ed
|
|
7
|
+
data.tar.gz: a6462fa10d6eff0704dbd51aa3001a5a5ee367947eea83a32962de27c8fe68c907204b20860270063ac23cbd8ce50aea2697a01d1d0649bc7b58cb1962164165
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Gem fixed_record Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
* Added class method `valid_names` to return valid names in records
|
|
5
|
+
* Documented class method `filename`
|
|
6
|
+
* Add instance method `present?` to test if a value was supplied for an optional field
|
|
7
|
+
|
|
3
8
|
## 0.4.4
|
|
4
9
|
* Syntax Errors in YAML file now reported as ArgumentError
|
|
5
10
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Then to load these, create a class
|
|
|
48
48
|
require 'fixed_record'
|
|
49
49
|
|
|
50
50
|
class MyFavoriteWebsite < FixedRecord
|
|
51
|
-
data "#{Rails.root}/data/my_favorite_websites.yml", required: [:name, :url]
|
|
51
|
+
data "#{Rails.root}/data/my_favorite_websites.yml", required: [:name, :url], optional: [:title]
|
|
52
52
|
|
|
53
53
|
# Return hostname of url for company
|
|
54
54
|
def hostname
|
|
@@ -76,6 +76,20 @@ A count of the number of records is available:
|
|
|
76
76
|
puts MyFavoriteWebsite.count
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
As is the filename and the set of valid field names:
|
|
80
|
+
```ruby
|
|
81
|
+
puts MyFavoriteWebsite.filename # .../my_favorite_websites.yml
|
|
82
|
+
puts MyFavoriteWebsite.valid_keys.include?( :name ) # true
|
|
83
|
+
```
|
|
84
|
+
## Value presence
|
|
85
|
+
|
|
86
|
+
It's possible to check whether a value is supplied for an optional field for an item:
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
puts MyFavoriteWebsite.all.first.present?(:title) # true
|
|
90
|
+
```
|
|
91
|
+
This makes it possible to distinguish between an optional value being omitted and explicitly being given the value nil.
|
|
92
|
+
|
|
79
93
|
The declared class will also include all the methods from the `Enumerable` module.
|
|
80
94
|
|
|
81
95
|
### Hash of Records
|
|
@@ -136,7 +150,7 @@ The declared class will also include all the methods from the `Enumerable` modul
|
|
|
136
150
|
|
|
137
151
|
### Singleton Record
|
|
138
152
|
|
|
139
|
-
Create a YAML file `
|
|
153
|
+
Create a YAML file `site_settings.yml` defining a single records like this:
|
|
140
154
|
|
|
141
155
|
```yaml
|
|
142
156
|
|
data/lib/fixed_record.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'psych'
|
|
|
4
4
|
require 'set'
|
|
5
5
|
|
|
6
6
|
class FixedRecord
|
|
7
|
-
VERSION = "0.
|
|
7
|
+
VERSION = "0.5.0"
|
|
8
8
|
|
|
9
9
|
# Lazy load data from given filename
|
|
10
10
|
# creating accessors for top level attributes
|
|
@@ -61,7 +61,7 @@ class FixedRecord
|
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def self.
|
|
64
|
+
def self.has_item_key?( k )
|
|
65
65
|
if all.is_a?(Hash)
|
|
66
66
|
all.has_key?( k )
|
|
67
67
|
else
|
|
@@ -77,6 +77,10 @@ class FixedRecord
|
|
|
77
77
|
@@filename
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
+
def self.valid_names
|
|
81
|
+
load!
|
|
82
|
+
@@valid_keys
|
|
83
|
+
end
|
|
80
84
|
|
|
81
85
|
def self.load!
|
|
82
86
|
if @@items.nil?
|
|
@@ -150,8 +154,16 @@ private
|
|
|
150
154
|
valid_keys.each do |key|
|
|
151
155
|
define_method( key.to_sym) { @values[key] }
|
|
152
156
|
end
|
|
157
|
+
# Test if a value is defined (could be nil) for a name
|
|
158
|
+
class_eval %Q{
|
|
159
|
+
def present?(name)
|
|
160
|
+
@values.key?( name.to_s )
|
|
161
|
+
end
|
|
162
|
+
}
|
|
153
163
|
end
|
|
154
164
|
|
|
165
|
+
|
|
166
|
+
|
|
155
167
|
# Validate the top level of the data structure returned
|
|
156
168
|
# Validate the top level of the data structure returned
|
|
157
169
|
def self.validate_structure( y, singleton, filename )
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fixed_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
|
- Mike Bell
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-03-
|
|
11
|
+
date: 2020-03-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|