nstore 0.2.1 → 0.3.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
  SHA256:
3
- metadata.gz: b44826b78a625b48dc3e71ed369cb0ffe15f63a8febaa5763129cad63ffdbe27
4
- data.tar.gz: 2e4d22c78bf6d0e0d7a50b618359bc1948a1d60643e1d37296df93b55bc69400
3
+ metadata.gz: 04ee4be1e7cd11ed3b5d5987ab85612fce6ef7673d9c41cfbcce89621206bea1
4
+ data.tar.gz: 3fd3fae6277bad85a6cefccc0211ce9c279b6e14adfb68cd64c01e4aeaf8d653
5
5
  SHA512:
6
- metadata.gz: 65daf27f6a13a6b16aca2a8140a2e27a3a790af5fe2f6c85a00cf5a074f425e1e959e8ea38dddc17e951f121ede9af6620db5f5fae4cd42caf0be3d993c96d41
7
- data.tar.gz: 1067fee3aff32cc0136e10ce7c3bedbf1481c78581a31a2be6350f4cdffc521775f4c6c8916f13018dbe2037000d42cafa6c2f496d1f60145848799487b8ee6c
6
+ metadata.gz: 97604d80f612888e25e54f4e0b639f81b1226ba75c44d1c82d779706098b7c33a40ce4c5c0d82fff871ef0ab66931be6c6dd929921bc26fa928b3ea903872568
7
+ data.tar.gz: 9ce9b5d22dd8dfc3cd1c9da7820259da56394c61a140d41e72d70a05e92bf3b3d130768c6750a0712ab907482d936cbb07d46f9972469490c4200faeb8b071f1
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ - 0.3.0 - Feature: added compatibility with ActiveRecord storage
4
+ - 0.2.1 - Feature: Ruby version and GPL v3 license has been added
5
+ - 0.2.0 - Bugfix: create empty hash attribute after initialization
6
+ - 0.1.0 - Initial release
data/Gemfile.lock CHANGED
@@ -1,15 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nstore (0.2.1)
4
+ nstore (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ activemodel (4.1.14.2)
10
+ activesupport (= 4.1.14.2)
11
+ builder (~> 3.1)
12
+ activerecord (4.1.14.2)
13
+ activemodel (= 4.1.14.2)
14
+ activesupport (= 4.1.14.2)
15
+ arel (~> 5.0.0)
16
+ activesupport (4.1.14.2)
17
+ i18n (~> 0.6, >= 0.6.9)
18
+ json (~> 1.7, >= 1.7.7)
19
+ minitest (~> 5.1)
20
+ thread_safe (~> 0.1)
21
+ tzinfo (~> 1.1)
22
+ arel (5.0.1.20140414130214)
9
23
  ast (2.4.0)
10
24
  awesome_print (1.8.0)
25
+ builder (3.2.3)
26
+ concurrent-ruby (1.1.5)
11
27
  diff-lcs (1.3)
28
+ i18n (0.9.5)
29
+ concurrent-ruby (~> 1.0)
12
30
  jaro_winkler (1.5.3)
31
+ json (1.8.6)
32
+ minitest (5.11.3)
13
33
  parallel (1.17.0)
14
34
  parser (2.6.3.0)
15
35
  ast (~> 2.4.0)
@@ -38,12 +58,17 @@ GEM
38
58
  ruby-progressbar (~> 1.7)
39
59
  unicode-display_width (>= 1.4.0, < 1.7)
40
60
  ruby-progressbar (1.10.1)
61
+ sqlite3 (1.3.13)
62
+ thread_safe (0.3.6)
63
+ tzinfo (1.2.5)
64
+ thread_safe (~> 0.1)
41
65
  unicode-display_width (1.6.0)
42
66
 
43
67
  PLATFORMS
44
68
  ruby
45
69
 
46
70
  DEPENDENCIES
71
+ activerecord (~> 4.1.14.1)
47
72
  awesome_print
48
73
  bundler (~> 1.17)
49
74
  nstore!
@@ -51,6 +76,7 @@ DEPENDENCIES
51
76
  rspec (~> 3.0)
52
77
  rspec_junit_formatter
53
78
  rubocop (~> 0.49)
79
+ sqlite3 (~> 1.3.6)
54
80
 
55
81
  BUNDLED WITH
56
82
  1.17.3
data/README.md CHANGED
@@ -70,6 +70,46 @@ List of options:
70
70
 
71
71
  - `stringify` - (true by default) this option is useful for serialization of a hash-map attribute into JSON/YAML format or for saving it in
72
72
  a Database HSTORE/JSON/JSONB if you use symbol keys as accessors
73
+
74
+ Possible to use with ActiveRecord model.
75
+
76
+ ```
77
+ class Dump < ActiveRecord::Base
78
+ include NStore
79
+
80
+ store :meta, serialize: JSON # use store_accessor with PostgreSQL and HSTORE/JSON/JSONB type
81
+ store :storage, serialize: JSON
82
+
83
+ nstore :meta,
84
+ accessors: { board: %i[id name] },
85
+ prefix: false
86
+ nstore :storage,
87
+ accessors: { board: %i[id name] },
88
+ prefix: true
89
+ ...
90
+ ```
91
+
92
+ creates list of methods to get and set nested values:
93
+ ```
94
+
95
+ dump = Dump.new
96
+ dump.board_id = 100
97
+ dump.board_name = 'Meta'
98
+ dump.storage_board_id = 300
99
+ dump.storage_board_name = 'Storage Board'
100
+ dump.save!
101
+
102
+ puts dump.board_id
103
+ => 100
104
+ puts dump.board_name
105
+ => "Mega"
106
+ puts dump.storage_board_id
107
+ => 300
108
+ puts dump.storage_board_name
109
+ => "Storage Board"
110
+ ```
111
+
112
+ When using couple of `nstore` declarations in the same Class, please, use `prefix: true` to avoid conflicts.
73
113
 
74
114
  ## Development
75
115
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NStore
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/nstore.rb CHANGED
@@ -16,8 +16,8 @@ require 'nstore/version'
16
16
  # },
17
17
  # trello: %i[id name]
18
18
  # },
19
- # prefix: false,
20
- # stringify: false
19
+ # prefix: false,
20
+ # stringify: true
21
21
  # ...
22
22
  module NStore
23
23
  class Error < StandardError; end
@@ -29,24 +29,25 @@ module NStore
29
29
  # List of Class methods going to be included above
30
30
  module ClassMethods
31
31
  def nstore(attribute, options)
32
- prefix = options.fetch(:prefix, false)
33
- stringify = options.fetch(:stringify, false)
34
32
  accessors = options[:accessors]
33
+ prefix = options.fetch(:prefix, false)
34
+ stringify = options.fetch(:stringify, true)
35
35
 
36
36
  flat_accessors = []
37
37
  deep_flatten(accessors, [], flat_accessors)
38
+ attribute = attribute.to_s if stringify
38
39
  _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify)
39
40
  end
40
41
 
41
42
  def _nstore_generate_accessors(attribute, flat_accessors, prefix, stringify)
42
43
  flat_accessors.each do |keys|
44
+ keys.map!(&:to_s) if stringify
45
+
43
46
  define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}=".to_sym) do |value|
44
- keys.map!(&:to_s) if stringify
45
47
  write_nstore_attribute(attribute, keys, value)
46
48
  end
47
49
 
48
50
  define_method("#{prefix ? "#{attribute}_" : ''}#{keys.join('_')}".to_sym) do
49
- keys.map!(&:to_s) if stringify
50
51
  read_nstore_attribute(attribute, keys)
51
52
  end
52
53
  end
@@ -97,4 +98,8 @@ module NStore
97
98
  def read_nstore_attribute(attribute, keys)
98
99
  send(attribute).send(:dig, *keys)
99
100
  end
101
+
102
+ def nstore_key_brakets(attribute, keys)
103
+ ([attribute] + keys).map { |k| "['#{k}']" }.join
104
+ end
100
105
  end
data/nstore.gemspec CHANGED
@@ -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/README.md',
19
+ 'changelog_uri' => 'https://github.com/mpakus/nstore/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'
@@ -44,9 +44,11 @@ Gem::Specification.new do |spec|
44
44
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
45
45
  spec.require_paths = ['lib']
46
46
 
47
+ spec.add_development_dependency 'activerecord', '~> 4.1.14.1'
47
48
  spec.add_development_dependency 'awesome_print'
48
49
  spec.add_development_dependency 'bundler', '~> 1.17'
49
50
  spec.add_development_dependency 'rake', '~> 10.0'
50
51
  spec.add_development_dependency 'rspec', '~> 3.0'
51
52
  spec.add_development_dependency 'rubocop', '~> 0.49'
53
+ spec.add_development_dependency 'sqlite3', '~> 1.3.6'
52
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renat "MpaK" Ibragimov
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.14.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.14.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: awesome_print
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.49'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.6
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.6
83
111
  description: Generates nested attributes accessors.
84
112
  email:
85
113
  - mrak69@gmail.com
@@ -93,6 +121,7 @@ files:
93
121
  - ".ruby-gemset"
94
122
  - ".ruby-version"
95
123
  - ".travis.yml"
124
+ - CHANGELOG.md
96
125
  - Gemfile
97
126
  - Gemfile.lock
98
127
  - LICENSE
@@ -107,7 +136,7 @@ homepage: https://github.com/mpakus/nstore
107
136
  licenses:
108
137
  - GPL-3
109
138
  metadata:
110
- changelog_uri: https://github.com/mpakus/nstore/README.md
139
+ changelog_uri: https://github.com/mpakus/nstore/CHANGELOG.md
111
140
  documentation_uri: https://github.com/mpakus/nstore
112
141
  homepage_uri: https://github.com/mpakus/nstore
113
142
  source_code_uri: https://github.com/mpakus/nstore