static_collection 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6199b4a21a4295980ea842bb4bce5d4b79b83af3
4
- data.tar.gz: 75e0bc003f13bd5e4eb521dc93ed03860488334c
2
+ SHA256:
3
+ metadata.gz: aee7a2335834e9e570ff2bc0e0289c33babb47131cfbba9a7e99f23d117f7583
4
+ data.tar.gz: 26d5d69190b140785b8355e45c99cdcc0de4173e380ce8b195d8fab56ee5ed23
5
5
  SHA512:
6
- metadata.gz: fa8b41e1d4b23351d3bb1e810a1acf4e495ed9bdd19bbf088e9f9e3fc9940af043284ce455605757c5cea7813e7b0619c8e1ba1dd47a5c86e84212e65a85e8f0
7
- data.tar.gz: 145d67ebebb03c43e7cf985116290494343a579682ffecca5171c3286ea3815b6023cfdb691db5a2aecefc9241c123433280ba5572df5b43e3050e54f7efb16d
6
+ metadata.gz: bd6b84129218e0a98310d745aab5ef54e8a6ef5c14f868acb3dcc4a0d0aa701f5897f2e760a4beb4471960f393b1dc4e34303e13939799eb217a3cb4d567b9f5
7
+ data.tar.gz: d2c325572a184526e2fde0a1e89f6d85bd7c074ccbc42826b82af5b804c8f79eda390e5e0b16d2670ffbd5bb8596b414720d73f8eef8ce2c5899e38cd2ab8b9d
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ *.gem
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.5.1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # StaticCollection [![CircleCI](https://circleci.com/gh/wealthsimple/static_collection.svg?style=svg)](https://circleci.com/gh/wealthsimple/static_collection)
1
+ # StaticCollection [![CircleCI](https://circleci.com/gh/wealthsimple/static_collection.svg?style=svg)](https://circleci.com/gh/wealthsimple/static_collection) [![](https://img.shields.io/gem/v/static_collection.svg)](https://rubygems.org/gems/static_collection)
2
2
 
3
- Rubygem for running basic queries against static YAML data.
3
+ Rubygem for running basic queries against static data.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,37 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ To create a StaticCollection model, inherit from `StaticCollection::Base`
24
+
25
+ ```ruby
26
+ class AccountType < StaticCollection::Base
27
+ end
28
+ ```
29
+
30
+ Then set the source for the static collection data. To read from YAML,
31
+
32
+ ```ruby
33
+ class AccountType < StaticCollection::Base
34
+ set_source YAML.load_file('./data/account_types_test.yml')
35
+ end
36
+ ```
37
+
38
+ To set a default value for an attribute, pass a defaults hash into `set_source`
39
+
40
+ ```ruby
41
+ class AccountType < StaticCollection::Base
42
+ set_source YAML.load_file('./data/account_types_test.yml'), defaults: { recommended_by_default: false }
43
+ end
44
+ ```
45
+
46
+ StaticCollection supports the following query methods: `:count`, `:all`, `:find_by`, and `:where`.
47
+
48
+ ```ruby
49
+ > AccountType.find_by(type: 'joint').ownership_type
50
+ => "multi-owner"
51
+ ```
52
+
53
+ To see the full `AccountType` example, take a look at our [blog post](http://code.wealthsimple.com/introducing-staticcollection-an-activerecord-interface-for-static-data/).
24
54
 
25
55
  ## Development
26
56
 
@@ -12,9 +12,11 @@ module StaticCollection
12
12
  all.first.attributes.each do |attribute_name, attribute_value|
13
13
  # Class methods
14
14
  self.define_singleton_method("find_by_#{attribute_name}") do |value|
15
+ ActiveSupport::Deprecation.warn("find_by_#{attribute_name} is deprecated for StaticCollection, use find_by(#{attribute_name}: [value])")
15
16
  all.find { |instance| instance.send(attribute_name) == value }
16
17
  end
17
18
  self.define_singleton_method("find_all_by_#{attribute_name}") do |value|
19
+ ActiveSupport::Deprecation.warn("find_all_by_#{attribute_name} is deprecated for StaticCollection, use where(#{attribute_name}: [value])")
18
20
  all.select { |instance| instance.send(attribute_name) == value }
19
21
  end
20
22
 
@@ -24,6 +26,14 @@ module StaticCollection
24
26
  end
25
27
  end
26
28
 
29
+ def self.find_by(opts)
30
+ all.find { |instance| opts.all? { |k, v| instance.send(k) == v } }
31
+ end
32
+
33
+ def self.where(opts)
34
+ all.select { |instance| opts.all? { |k, v| instance.send(k) == v } }
35
+ end
36
+
27
37
  def self.all
28
38
  defaults = self.class_variable_get(:@@defaults)
29
39
  self.class_variable_get(:@@source).map { |s| self.new(defaults.merge(s)) }
@@ -1,3 +1,3 @@
1
1
  module StaticCollection
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Peter Graham"]
10
10
  spec.email = ["peter@wealthsimple.com"]
11
11
 
12
- spec.summary = %q{Run queries against static YAML data.}
13
- spec.description = %q{Rubygem for running basic queries against static YAML data.}
12
+ spec.summary = %q{Run queries against static data.}
13
+ spec.description = %q{Rubygem for running basic queries against static data.}
14
14
  spec.homepage = "https://github.com/wealthsimple/static_collection"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Graham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-24 00:00:00.000000000 Z
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.2'
83
- description: Rubygem for running basic queries against static YAML data.
83
+ description: Rubygem for running basic queries against static data.
84
84
  email:
85
85
  - peter@wealthsimple.com
86
86
  executables: []
@@ -90,7 +90,6 @@ files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
92
  - ".ruby-version"
93
- - ".travis.yml"
94
93
  - Gemfile
95
94
  - LICENSE.txt
96
95
  - README.md
@@ -120,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
119
  version: '0'
121
120
  requirements: []
122
121
  rubyforge_project:
123
- rubygems_version: 2.5.2
122
+ rubygems_version: 2.7.6
124
123
  signing_key:
125
124
  specification_version: 4
126
- summary: Run queries against static YAML data.
125
+ summary: Run queries against static data.
127
126
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.14.3