sumaki 0.1.0 → 0.2.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: 743c9cc65c7fb7b06a254d6f96ccacd405101fbd87b12b9ba9a0283341f0203b
4
- data.tar.gz: 922c9652b6a0bee5fcca21e261b653a8fe9362ad0ee174050f6a0e8fae9986d1
3
+ metadata.gz: 4b7187ea951d6b5b682b054303d696ce2c65e205519c151aed52a7e6a542cdf7
4
+ data.tar.gz: 70631c497947954364961b3fde444bcc56be61b534687826872cab5efa139e86
5
5
  SHA512:
6
- metadata.gz: 3d368a98fe977ba95aad3b0d01233a46eb00391e0c2825faa6b4fe9991b6394808a90dbfe37af1648ddf3bed13b904fb3dee72f5ee83237c4c0d876a628df660
7
- data.tar.gz: 122196f48283f4e23f3a9ba52d84aff764487066016da59bb42e5fe5e405780bde902f41bf45bc25ead3b6fcc5347935b786d4723e17328f137052b0ff0836ed
6
+ metadata.gz: a913803fdde6db3a69bce4ad967048673c6d3b089d05265029d21e09074b817d45cb7b3c2f1570cc50e3ec034bdb85420eb7f38a0b6625803d2054bbb4fad733
7
+ data.tar.gz: 355746b7f56600a79023a056aaaee86a599f9b5951b371b8b6a600086428cf392528f8447bc03f71f3173a91cd939b661d1134cb80cae4d99c993053e9973987
data/Gemfile.lock CHANGED
@@ -2,69 +2,88 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  sumaki (0.1.0)
5
+ minenum
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  ast (2.4.2)
10
- debug (1.7.1)
11
- irb (>= 1.5.0)
12
- reline (>= 0.3.1)
13
- diff-lcs (1.5.0)
11
+ debug (1.9.2)
12
+ irb (~> 1.10)
13
+ reline (>= 0.3.8)
14
+ diff-lcs (1.5.1)
14
15
  docile (1.4.0)
15
- io-console (0.6.0)
16
- irb (1.6.2)
17
- reline (>= 0.3.0)
18
- json (2.6.3)
19
- parallel (1.22.1)
20
- parser (3.2.0.0)
16
+ io-console (0.7.2)
17
+ irb (1.12.0)
18
+ rdoc
19
+ reline (>= 0.4.2)
20
+ json (2.7.2)
21
+ language_server-protocol (3.17.0.3)
22
+ minenum (0.1.0)
23
+ parallel (1.24.0)
24
+ parser (3.3.0.5)
21
25
  ast (~> 2.4.1)
26
+ racc
27
+ psych (5.1.2)
28
+ stringio
29
+ racc (1.7.3)
22
30
  rainbow (3.1.1)
23
- rake (13.0.6)
24
- regexp_parser (2.6.2)
25
- reline (0.3.2)
31
+ rake (13.2.1)
32
+ rdoc (6.6.3.1)
33
+ psych (>= 4.0.0)
34
+ regexp_parser (2.9.0)
35
+ reline (0.5.2)
26
36
  io-console (~> 0.5)
27
- rexml (3.2.5)
28
- rspec (3.12.0)
29
- rspec-core (~> 3.12.0)
30
- rspec-expectations (~> 3.12.0)
31
- rspec-mocks (~> 3.12.0)
32
- rspec-core (3.12.0)
33
- rspec-support (~> 3.12.0)
34
- rspec-expectations (3.12.2)
37
+ rexml (3.2.6)
38
+ rspec (3.13.0)
39
+ rspec-core (~> 3.13.0)
40
+ rspec-expectations (~> 3.13.0)
41
+ rspec-mocks (~> 3.13.0)
42
+ rspec-core (3.13.0)
43
+ rspec-support (~> 3.13.0)
44
+ rspec-expectations (3.13.0)
35
45
  diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.12.0)
37
- rspec-mocks (3.12.3)
46
+ rspec-support (~> 3.13.0)
47
+ rspec-mocks (3.13.0)
38
48
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.12.0)
40
- rspec-support (3.12.0)
41
- rubocop (1.44.1)
49
+ rspec-support (~> 3.13.0)
50
+ rspec-support (3.13.1)
51
+ rubocop (1.63.3)
42
52
  json (~> 2.3)
53
+ language_server-protocol (>= 3.17.0)
43
54
  parallel (~> 1.10)
44
- parser (>= 3.2.0.0)
55
+ parser (>= 3.3.0.2)
45
56
  rainbow (>= 2.2.2, < 4.0)
46
57
  regexp_parser (>= 1.8, < 3.0)
47
58
  rexml (>= 3.2.5, < 4.0)
48
- rubocop-ast (>= 1.24.1, < 2.0)
59
+ rubocop-ast (>= 1.31.1, < 2.0)
49
60
  ruby-progressbar (~> 1.7)
50
61
  unicode-display_width (>= 2.4.0, < 3.0)
51
- rubocop-ast (1.24.1)
52
- parser (>= 3.1.1.0)
53
- rubocop-capybara (2.17.0)
62
+ rubocop-ast (1.31.2)
63
+ parser (>= 3.3.0.4)
64
+ rubocop-capybara (2.20.0)
54
65
  rubocop (~> 1.41)
55
- rubocop-rspec (2.18.1)
56
- rubocop (~> 1.33)
66
+ rubocop-factory_bot (2.25.1)
67
+ rubocop (~> 1.41)
68
+ rubocop-rspec (2.29.1)
69
+ rubocop (~> 1.40)
57
70
  rubocop-capybara (~> 2.17)
58
- ruby-progressbar (1.11.0)
71
+ rubocop-factory_bot (~> 2.22)
72
+ rubocop-rspec_rails (~> 2.28)
73
+ rubocop-rspec_rails (2.28.3)
74
+ rubocop (~> 1.40)
75
+ ruby-progressbar (1.13.0)
59
76
  simplecov (0.22.0)
60
77
  docile (~> 1.1)
61
78
  simplecov-html (~> 0.11)
62
79
  simplecov_json_formatter (~> 0.1)
63
80
  simplecov-html (0.12.3)
64
81
  simplecov_json_formatter (0.1.4)
65
- unicode-display_width (2.4.2)
82
+ stringio (3.1.0)
83
+ unicode-display_width (2.5.0)
66
84
 
67
85
  PLATFORMS
86
+ ruby
68
87
  x86_64-linux
69
88
 
70
89
  DEPENDENCIES
@@ -77,4 +96,4 @@ DEPENDENCIES
77
96
  sumaki!
78
97
 
79
98
  BUNDLED WITH
80
- 2.4.5
99
+ 2.5.9
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ---
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/sumaki.svg)](https://badge.fury.io/rb/sumaki)
6
+ ![example workflow](https://github.com/nowlinuxing/sumaki/actions/workflows/main.yml/badge.svg?branch=main)
5
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/dd92d4092d6858cbcfb2/maintainability)](https://codeclimate.com/github/nowlinuxing/sumaki/maintainability)
6
8
  [![Test Coverage](https://api.codeclimate.com/v1/badges/dd92d4092d6858cbcfb2/test_coverage)](https://codeclimate.com/github/nowlinuxing/sumaki/test_coverage)
7
9
 
@@ -223,7 +225,7 @@ By declaring `enum`, You can map a field to the specified value.
223
225
  class Character
224
226
  include Sumaki::Model
225
227
  field :name
226
- enum :type, vampire: 1, vampire_hunter: 2, familier: 3, editor: 4
228
+ enum :type, { vampire: 1, vampire_hunter: 2, familier: 3, editor: 4 }
227
229
  end
228
230
 
229
231
  data = {
@@ -244,7 +246,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
244
246
 
245
247
  ## Contributing
246
248
 
247
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sumaki.
249
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nowlinuxing/sumaki.
248
250
 
249
251
  ## License
250
252
 
@@ -107,8 +107,6 @@ module Sumaki
107
107
  end
108
108
 
109
109
  module InstanceMethods # :nodoc:
110
- private
111
-
112
110
  def get(name)
113
111
  self.class.adapter.get(object, name)
114
112
  end
@@ -1,33 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'minenum'
4
+
3
5
  module Sumaki
4
6
  module Model
5
7
  # = Sumaki::Model::Enum
6
8
  module Enum
7
9
  def self.included(base)
10
+ base.include Minenum::Model
8
11
  base.extend ClassMethods
9
12
  end
10
13
 
11
- class EnumValue < Hash # :nodoc:
12
- code = <<-RUBY
13
- case value
14
- when Symbol then super(value) || super(value.to_s)
15
- when String then super(value) || super(value.to_sym)
16
- else super(value)
17
- end
18
- RUBY
19
-
20
- class_eval <<-RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
21
- def key?(value); #{code}; end
22
- RUBY
23
-
24
- class_eval <<-RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
25
- def key(value); #{code}; end
26
- RUBY
27
-
28
- class_eval <<-RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
29
- def value?(value); #{code}; end
30
- RUBY
14
+ module EnumAttrAccessor # :nodoc:
15
+ def get(model, name)
16
+ model.get(name)
17
+ end
18
+ module_function :get
31
19
  end
32
20
 
33
21
  module ClassMethods # :nodoc:
@@ -36,7 +24,7 @@ module Sumaki
36
24
  # class Character
37
25
  # include Sumaki::Model
38
26
  # field :name
39
- # enum :type, vampire: 1, vampire_hunter: 2, familier: 3, editor: 4
27
+ # enum :type, { vampire: 1, vampire_hunter: 2, familier: 3, editor: 4 }
40
28
  # end
41
29
  #
42
30
  # data = {
@@ -45,19 +33,11 @@ module Sumaki
45
33
  # }
46
34
  #
47
35
  # character = Character.new(data)
48
- # character.type #=> :familier
49
- def enum(name, **values)
50
- values = EnumValue[values]
51
-
52
- enum_methods_module.define_method(name) do
53
- value = get(name)
54
-
55
- if values.key?(value)
56
- value
57
- elsif values.value?(value)
58
- values.key(value)
59
- end
60
- end
36
+ # character.type.name #=> :familier
37
+ # character.type.familier? #=> true
38
+ # character.type.vampire? #=> false
39
+ def enum(name, values)
40
+ super(name, values, adapter: EnumAttrAccessor)
61
41
  end
62
42
 
63
43
  private
@@ -69,6 +49,11 @@ module Sumaki
69
49
  mod
70
50
  end
71
51
  end
52
+
53
+ # TODO: remove this
54
+ def classify(key)
55
+ key.gsub(/([a-z\d]+)_?/) { |_| Regexp.last_match(1).capitalize }
56
+ end
72
57
  end
73
58
  end
74
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sumaki
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumaki
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
  - Loose Coupling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-19 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minenum
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: |
14
28
  Sumaki is a wrapper for structured data like JSON.
15
29
  Since Sumaki wraps the target data as it is, rather than parsing it using a schema, the original data can be referenced at any time.
@@ -39,7 +53,6 @@ files:
39
53
  - lib/sumaki/model/enum.rb
40
54
  - lib/sumaki/version.rb
41
55
  - sig/sumaki.rbs
42
- - sumaki.gemspec
43
56
  homepage: https://github.com/nowlinuxing/sumaki/
44
57
  licenses:
45
58
  - MIT
@@ -57,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
70
  requirements:
58
71
  - - ">="
59
72
  - !ruby/object:Gem::Version
60
- version: 2.6.0
73
+ version: 3.0.0
61
74
  required_rubygems_version: !ruby/object:Gem::Requirement
62
75
  requirements:
63
76
  - - ">="
64
77
  - !ruby/object:Gem::Version
65
78
  version: '0'
66
79
  requirements: []
67
- rubygems_version: 3.4.1
80
+ rubygems_version: 3.5.9
68
81
  signing_key:
69
82
  specification_version: 4
70
83
  summary: Sumaki is a wrapper for structured data like JSON.
data/sumaki.gemspec DELETED
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/sumaki/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'sumaki'
7
- spec.version = Sumaki::VERSION
8
- spec.authors = ['Loose Coupling']
9
- spec.email = ['loosecpl@gmail.com']
10
-
11
- spec.summary = 'Sumaki is a wrapper for structured data like JSON.'
12
- spec.description = <<~DESC
13
- Sumaki is a wrapper for structured data like JSON.
14
- Since Sumaki wraps the target data as it is, rather than parsing it using a schema, the original data can be referenced at any time.
15
- This makes it easy to add or modify definitions as needed while checking the target data.
16
- This feature may be useful when there is no document defining the structure of the data, or when the specification is complex and difficult to grasp, and the definition is written little by little starting from the obvious places.
17
- DESC
18
- spec.homepage = 'https://github.com/nowlinuxing/sumaki/'
19
- spec.license = 'MIT'
20
- spec.required_ruby_version = '>= 2.6.0'
21
-
22
- spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
23
-
24
- spec.metadata['homepage_uri'] = spec.homepage
25
- spec.metadata['source_code_uri'] = spec.homepage
26
- spec.metadata['changelog_uri'] = spec.homepage
27
- spec.metadata['rubygems_mfa_required'] = 'true'
28
-
29
- # Specify which files should be added to the gem when it is released.
30
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(__dir__) do
32
- `git ls-files -z`.split("\x0").reject do |f|
33
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
34
- end
35
- end
36
- spec.bindir = 'exe'
37
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
38
- spec.require_paths = ['lib']
39
-
40
- # Uncomment to register a new dependency of your gem
41
- # spec.add_dependency "example-gem", "~> 1.0"
42
-
43
- # For more information and examples about making a new gem, check out our
44
- # guide at: https://bundler.io/guides/creating_gem.html
45
- end