camel_snake_struct 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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +11 -6
- data/bin/rake +29 -0
- data/camel_snake_struct.gemspec +1 -1
- data/lib/camel_snake_struct.rb +4 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 987bc380d252b4990ae2007fcf0d5d75dcb1eb56a9f680eb043a3b6e7e65fa0c
|
4
|
+
data.tar.gz: 1ac44036b2c851c8f98c3bef57c20ab3cf1e6d557b675c2a48465a6b8e3be5ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c64e7b0995a1098f8a932fa80f6c488ab1c75ce6dbcbaeaa181981442fb147c599b49e9a4b156fcb9930ca044d34fa92b795499594f99c1cc678259185fbe103
|
7
|
+
data.tar.gz: e8f184b499b1fbff46d2d22ff86459cc7c46b8f38369d7e28fc7af4cf5b3d07caef7115bacc3daa375fa452e503cb91bb2701ec1041515eb6242a463cc50c81e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# CamelSnakeStruct
|
2
2
|
|
3
3
|
Easily access camelCased hashes in a ruby_friendly_way.
|
4
4
|
Main focus is handling responses from APIs that use camelCased keys.
|
@@ -8,7 +8,7 @@ Main focus is handling responses from APIs that use camelCased keys.
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem '
|
11
|
+
gem 'camel_snake_struct'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -17,7 +17,7 @@ And then execute:
|
|
17
17
|
|
18
18
|
Or install it yourself as:
|
19
19
|
|
20
|
-
$ gem install
|
20
|
+
$ gem install camel_snake_struct
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
@@ -30,10 +30,15 @@ For once of hashes
|
|
30
30
|
|
31
31
|
puts result.version # 1
|
32
32
|
puts result.ruby_version # 2.5.0
|
33
|
-
puts result.sites[0].url # https://duckduckgo.com
|
34
|
-
puts result.sites[1].url # https://d.tube/
|
35
|
-
puts result.unknown # NoMethodError
|
36
33
|
puts result['version'] # 1
|
34
|
+
|
35
|
+
if result.sites?
|
36
|
+
puts result.sites[0].url # https://duckduckgo.com
|
37
|
+
puts result.sites[1].url # https://d.tube/
|
38
|
+
end
|
39
|
+
|
40
|
+
puts result.people? # false
|
41
|
+
puts result.people # NoMethodError
|
37
42
|
```
|
38
43
|
|
39
44
|
Or Learning Structs
|
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../gems.rb",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/camel_snake_struct.gemspec
CHANGED
data/lib/camel_snake_struct.rb
CHANGED
@@ -60,6 +60,9 @@ class CamelSnakeStruct
|
|
60
60
|
else # no method defined for empty arrays as we don't know what it returns
|
61
61
|
@_raw_hash[camelize_key]
|
62
62
|
end
|
63
|
+
elsif method_name.to_s.end_with?('?')
|
64
|
+
camelize_key = __method_to_key(method_name.to_s.chop)
|
65
|
+
@_raw_hash.key?(camelize_key)
|
63
66
|
else
|
64
67
|
super
|
65
68
|
end
|
@@ -67,7 +70,7 @@ class CamelSnakeStruct
|
|
67
70
|
|
68
71
|
def respond_to_missing?(method_name, include_private = false)
|
69
72
|
camelize_key = __method_to_key(method_name)
|
70
|
-
!camelize_key.nil? || super
|
73
|
+
!camelize_key.nil? || method_name.to_s.end_with?('?') || super
|
71
74
|
end
|
72
75
|
|
73
76
|
def __method_to_key(method_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camel_snake_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Petersen-Speelman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- README.md
|
45
45
|
- Rakefile
|
46
46
|
- bin/console
|
47
|
+
- bin/rake
|
47
48
|
- bin/rspec
|
48
49
|
- bin/rubocop
|
49
50
|
- bin/setup
|
@@ -56,7 +57,7 @@ metadata:
|
|
56
57
|
homepage_uri: https://github.com/NEXL-LTS/camel_snake_struct-ruby
|
57
58
|
source_code_uri: https://github.com/NEXL-LTS/camel_snake_struct-ruby
|
58
59
|
changelog_uri: https://github.com/NEXL-LTS/camel_snake_struct/CHANGELOG.md
|
59
|
-
post_install_message:
|
60
|
+
post_install_message:
|
60
61
|
rdoc_options: []
|
61
62
|
require_paths:
|
62
63
|
- lib
|
@@ -71,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
- !ruby/object:Gem::Version
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
75
|
-
signing_key:
|
75
|
+
rubygems_version: 3.2.22
|
76
|
+
signing_key:
|
76
77
|
specification_version: 4
|
77
78
|
summary: Easily access camelCased hashes in a ruby friendly way
|
78
79
|
test_files: []
|