nstore 0.3.0 → 0.4.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
2
  SHA256:
3
- metadata.gz: 04ee4be1e7cd11ed3b5d5987ab85612fce6ef7673d9c41cfbcce89621206bea1
4
- data.tar.gz: 3fd3fae6277bad85a6cefccc0211ce9c279b6e14adfb68cd64c01e4aeaf8d653
3
+ metadata.gz: dfd4edc17a4065d5a1381cc5a675bdc777cceb2d6325b56e0518f80fa0841416
4
+ data.tar.gz: 67b58eba0465335ff5294a62e11768c3338c831c00b6351415cb2628b6ac78f3
5
5
  SHA512:
6
- metadata.gz: 97604d80f612888e25e54f4e0b639f81b1226ba75c44d1c82d779706098b7c33a40ce4c5c0d82fff871ef0ab66931be6c6dd929921bc26fa928b3ea903872568
7
- data.tar.gz: 9ce9b5d22dd8dfc3cd1c9da7820259da56394c61a140d41e72d70a05e92bf3b3d130768c6750a0712ab907482d936cbb07d46f9972469490c4200faeb8b071f1
6
+ metadata.gz: 8eb1321fcdc3db9929078fce412b032cf96f6b8d9f36462f8b0c0d778e814960648c4fd1afdf56704628723f4d09ad86ef7fdd309bab4b147b1790c511ed43cf
7
+ data.tar.gz: 15d7467a455f9b0552802c8dd113d0a64a2da25703ffb83182b298abff156183c92031e7bd4fbe2f4743d1a0e1791e089ab7ff83cf559ebf3b7d6d817f61bdcc
@@ -0,0 +1,65 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.3-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+ - run:
22
+ name: install sqlite
23
+ command: |
24
+ sudo apt-get install sqlite3
25
+
26
+ # Download and cache dependencies
27
+ - restore_cache:
28
+ keys:
29
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
30
+ # fallback to using the latest cache if no exact match is found
31
+ - v1-dependencies-
32
+ - run:
33
+ name: install bundler
34
+ command: |
35
+ gem install bundler --pre
36
+
37
+ - run:
38
+ name: install dependencies
39
+ command: |
40
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
41
+
42
+ - save_cache:
43
+ paths:
44
+ - ./vendor/bundle
45
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
46
+
47
+ # run tests!
48
+ - run:
49
+ name: run tests
50
+ command: |
51
+ mkdir /tmp/test-results
52
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
53
+
54
+ bundle exec rspec --format progress \
55
+ --format RspecJunitFormatter \
56
+ --out /tmp/test-results/rspec.xml \
57
+ --format progress \
58
+ $TEST_FILES
59
+
60
+ # collect reports
61
+ - store_test_results:
62
+ path: /tmp/test-results
63
+ - store_artifacts:
64
+ path: /tmp/test-results
65
+ destination: test-results
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ - 0.4.0 - Feature: ability to set access through an array
3
4
  - 0.3.0 - Feature: added compatibility with ActiveRecord storage
4
5
  - 0.2.1 - Feature: Ruby version and GPL v3 license has been added
5
6
  - 0.2.0 - Bugfix: create empty hash attribute after initialization
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nstore (0.3.0)
4
+ nstore (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # NStore
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/mpakus/nstore.svg?style=svg)](https://circleci.com/gh/mpakus/nstore)
4
+
3
5
  Store gives you a thin wrapper around serialize for the purpose of storing hashes in a single column. It's like a simple key/value store baked into your record when you don't care about being able to query that store outside the context of a single record.
4
6
 
5
7
  You can then declare accessors to this store that are then accessible just like any other attribute of the model. This is very helpful for easily exposing store keys to a form or elsewhere that's already built around just accessing attributes on the model.
@@ -24,7 +26,7 @@ Or install it yourself as:
24
26
 
25
27
  First include NStore module to your class/model and then describe hash-map attribute, list of accessors and couple of options.
26
28
 
27
- ```
29
+ ```ruby
28
30
  class User
29
31
  include NStore
30
32
 
@@ -46,7 +48,7 @@ First include NStore module to your class/model and then describe hash-map attri
46
48
 
47
49
  This will generate several setter and getter methods:
48
50
 
49
- ```
51
+ ```ruby
50
52
  user = User.new
51
53
  user.profile_uid = 100
52
54
  user.profile_url
@@ -73,7 +75,7 @@ List of options:
73
75
 
74
76
  Possible to use with ActiveRecord model.
75
77
 
76
- ```
78
+ ```ruby
77
79
  class Dump < ActiveRecord::Base
78
80
  include NStore
79
81
 
@@ -90,8 +92,7 @@ class Dump < ActiveRecord::Base
90
92
  ```
91
93
 
92
94
  creates list of methods to get and set nested values:
93
- ```
94
-
95
+ ```ruby
95
96
  dump = Dump.new
96
97
  dump.board_id = 100
97
98
  dump.board_name = 'Meta'
@@ -109,6 +110,39 @@ puts dump.storage_board_name
109
110
  => "Storage Board"
110
111
  ```
111
112
 
113
+ or just a flat array when need one level of methods, with or without prefix (be careful with attributes conflicts)
114
+
115
+ ```ruby
116
+ class Dump < ActiveRecord::Base
117
+ include NStore
118
+
119
+ attr_accessor :member
120
+ attr_accessor :card
121
+ nstore :member,
122
+ accessors: [:id, :avatar],
123
+ prefix: true
124
+ nstore :card,
125
+ accessors: [:number, :date],
126
+ prefix: false
127
+ ...
128
+ ```
129
+
130
+ ```ruby
131
+ dump = Dump.new
132
+ dump.member_id = 100
133
+ dump.member_avatar = 'Avatar URL'
134
+ dump.number = 'Card Number'
135
+ dump.date = 'Card Date'
136
+ puts dump.member_id
137
+ => 100
138
+ puts dump.member_avatar
139
+ => "Avatar URL"
140
+ puts dump.number
141
+ => "Card Number"
142
+ puts dump.date
143
+ => "Card Date"
144
+ ```
145
+
112
146
  When using couple of `nstore` declarations in the same Class, please, use `prefix: true` to avoid conflicts.
113
147
 
114
148
  ## Development
@@ -33,6 +33,7 @@ module NStore
33
33
  prefix = options.fetch(:prefix, false)
34
34
  stringify = options.fetch(:stringify, true)
35
35
 
36
+ accessors = { nil => accessors } if accessors.is_a? Array
36
37
  flat_accessors = []
37
38
  deep_flatten(accessors, [], flat_accessors)
38
39
  attribute = attribute.to_s if stringify
@@ -41,6 +42,7 @@ module NStore
41
42
 
42
43
  def _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify)
43
44
  flat_accessors.each do |keys|
45
+ keys.reject!(&:nil?)
44
46
  keys.map!(&:to_s) if stringify
45
47
 
46
48
  define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}=".to_sym) do |value|
@@ -79,10 +81,8 @@ module NStore
79
81
  end
80
82
  end
81
83
 
82
- private
83
-
84
- # @param [Symbol] attribute
85
- # @param [Array] keys
84
+ # @param [Symbol,String] attribute
85
+ # @param [Array<String,Symbol>] keys
86
86
  # @param [Object] value
87
87
  def write_nstore_attribute(attribute, keys, value)
88
88
  send("#{attribute}=", {}) if send(attribute).nil?
@@ -95,11 +95,10 @@ module NStore
95
95
  position[keys[-1]] = value
96
96
  end
97
97
 
98
+ # @param [Symbol,String] attribute
99
+ # @param [Array<String,Symbol>] keys
100
+ # @return [Object]
98
101
  def read_nstore_attribute(attribute, keys)
99
102
  send(attribute).send(:dig, *keys)
100
103
  end
101
-
102
- def nstore_key_brakets(attribute, keys)
103
- ([attribute] + keys).map { |k| "['#{k}']" }.join
104
- end
105
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NStore
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.required_ruby_version = '>= 2.3.1'
17
17
 
18
18
  spec.metadata = {
19
- 'changelog_uri' => 'https://github.com/mpakus/nstore/CHANGELOG.md',
19
+ 'changelog_uri' => 'https://github.com/mpakus/nstore/blob/master/CHANGELOG.md',
20
20
  'documentation_uri' => 'https://github.com/mpakus/nstore',
21
21
  'homepage_uri' => 'https://github.com/mpakus/nstore',
22
22
  'source_code_uri' => 'https://github.com/mpakus/nstore'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renat "MpaK" Ibragimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-17 00:00:00.000000000 Z
11
+ date: 2019-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".circleci/config.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".rubocop.yml"
@@ -136,7 +137,7 @@ homepage: https://github.com/mpakus/nstore
136
137
  licenses:
137
138
  - GPL-3
138
139
  metadata:
139
- changelog_uri: https://github.com/mpakus/nstore/CHANGELOG.md
140
+ changelog_uri: https://github.com/mpakus/nstore/blob/master/CHANGELOG.md
140
141
  documentation_uri: https://github.com/mpakus/nstore
141
142
  homepage_uri: https://github.com/mpakus/nstore
142
143
  source_code_uri: https://github.com/mpakus/nstore
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  - !ruby/object:Gem::Version
156
157
  version: '0'
157
158
  requirements: []
158
- rubygems_version: 3.0.2
159
+ rubygems_version: 3.0.4
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: NStore - nested attributes accessors.