cfn_camelizer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4175a42f5c53d6d90e2fcd76673b74f6a2d0fbef965a2c998277b9395884974f
4
+ data.tar.gz: d546bfbfa412020dba9491a3f80bda894124f1135e431b641933ac2956bec9f9
5
+ SHA512:
6
+ metadata.gz: aa9423e76f8313ee0c78da8c3eb3a3d6d1c312b9bff3b3618abdc8c582866be71fd41c20129a15150df3efdad9abb653ced1cb7e8300804e2a6844add119d0b3
7
+ data.tar.gz: 9b9bb6c7b88e00d768204c39d8bd182e65f26c8ac6ea0c32f2916fffc2d7f50c31dff486665055f0d3ebcd5ad06463a31129726331e9079984bc3dcd27fe8161
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cfn_camelizer.gemspec
4
+ gemspec
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cfn_camelizer (0.1.0)
5
+ activesupport
6
+ memoist
7
+ rainbow
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.2.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ concurrent-ruby (1.1.5)
18
+ diff-lcs (1.3)
19
+ i18n (1.6.0)
20
+ concurrent-ruby (~> 1.0)
21
+ memoist (0.16.0)
22
+ minitest (5.11.3)
23
+ rainbow (3.0.0)
24
+ rake (12.3.2)
25
+ rspec (3.8.0)
26
+ rspec-core (~> 3.8.0)
27
+ rspec-expectations (~> 3.8.0)
28
+ rspec-mocks (~> 3.8.0)
29
+ rspec-core (3.8.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-expectations (3.8.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-mocks (3.8.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-support (3.8.0)
38
+ thread_safe (0.3.6)
39
+ tzinfo (1.2.5)
40
+ thread_safe (~> 0.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler
47
+ cfn_camelizer!
48
+ rake
49
+ rspec
50
+
51
+ BUNDLED WITH
52
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tung Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # CfnCamelizer
2
+
3
+ Camelizer for CloudFormation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cfn_camelizer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cfn_camelizer
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ data = {my_data: 1}
25
+ CfnCamelizer.transform(data) => {"MyData" => 1}
26
+ ```
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cfn_camelizer.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cfn_camelizer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cfn_camelizer/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cfn_camelizer"
8
+ spec.version = CfnCamelizer::VERSION
9
+ spec.authors = ["Tung Nguyen"]
10
+ spec.email = ["tongueroo@gmail.com"]
11
+
12
+ spec.summary = "Cfn Camelizer"
13
+ spec.homepage = "https://github.com/tongueroo/cfn_camelizer"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "activesupport"
26
+ spec.add_dependency "memoist"
27
+ spec.add_dependency "rainbow"
28
+
29
+ spec.add_development_dependency "bundler"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rspec"
32
+ end
@@ -0,0 +1,13 @@
1
+ ---
2
+ special_keys:
3
+ TemplateUrl: TemplateURL
4
+ Ttl: TTL
5
+ MaxReceiveCount: maxReceiveCount
6
+ DeadLetterTargetArn: deadLetterTargetArn
7
+ DbSubnetGroupDescription: DBSubnetGroupDescription
8
+ DbSubnetGroupName: DBSubnetGroupName
9
+ RoleArn: RoleARN
10
+ passthrough_parent_keys:
11
+ - Variables # Lambda Environment Variables https://amzn.to/2HLlttV
12
+ - ResponseParameters # API Gateway MethodResponse https://amzn.to/2HKw0Wk
13
+ - Fn::Sub # https://amzn.to/2HKwxri
@@ -0,0 +1,83 @@
1
+ require "cfn_camelizer/version"
2
+ require "memoist"
3
+ require "yaml"
4
+ require "rainbow/ext/string"
5
+ require "active_support/core_ext/string"
6
+ require "active_support/core_ext/hash"
7
+
8
+ class CfnCamelizer
9
+ class << self
10
+ extend Memoist
11
+
12
+ def transform(value, parent_keys=[])
13
+ case value
14
+ when Array
15
+ value.map { |v| transform(v, parent_keys) }
16
+ when Hash
17
+ initializer = value.map do |k, v|
18
+ new_key = camelize_key(k, parent_keys)
19
+ [new_key, transform(v, parent_keys+[new_key])]
20
+ end
21
+ Hash[initializer]
22
+ else
23
+ value # do not transform values
24
+ end
25
+ end
26
+
27
+ def camelize_key(k, parent_keys=[])
28
+ k = k.to_s
29
+
30
+ if passthrough?(k, parent_keys)
31
+ k # pass through untouch
32
+ elsif parent_keys.last == "EventPattern" # top-level
33
+ k.dasherize
34
+ elsif parent_keys.include?("EventPattern")
35
+ # Any keys at 2nd level under EventPattern will be pascalized
36
+ pascalize(k)
37
+ else
38
+ camelize(k)
39
+ end
40
+ end
41
+
42
+ def passthrough?(k, parent_keys)
43
+ # Do not transform keys under certain parent keys or keys that contain - or /
44
+ passthrough = camelizer_yaml["passthrough_parent_keys"]
45
+ intersection = parent_keys & passthrough
46
+ !intersection.empty? || k.include?('-') || k.include?('/')
47
+ end
48
+
49
+ def camelize(value)
50
+ return value if value.is_a?(Integer)
51
+
52
+ value = value.to_s.camelize
53
+ special_map[value] || value
54
+ end
55
+
56
+ def pascalize(value)
57
+ new_value = value.camelize
58
+ first_char = new_value[0..0].downcase
59
+ new_value[0] = first_char
60
+ new_value
61
+ end
62
+
63
+ # Some keys have special mappings
64
+ def special_map
65
+ camelizer_yaml["special_keys"]
66
+ end
67
+
68
+ def camelizer_yaml
69
+ # default
70
+ path = File.expand_path("camelizer.yml", File.dirname(__FILE__))
71
+ default = YAML.load_file(path)
72
+ # project specific
73
+ path = "#{Dir.pwd}/configs/camelizer.yml"
74
+ if File.exist?(path)
75
+ project = YAML.load_file(path)
76
+ default.deep_merge(project)
77
+ else
78
+ default
79
+ end
80
+ end
81
+ memoize :camelizer_yaml
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ class CfnCamelizer
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cfn_camelizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tung Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: memoist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - tongueroo@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - cfn_camelizer.gemspec
115
+ - lib/camelizer.yml
116
+ - lib/cfn_camelizer.rb
117
+ - lib/cfn_camelizer/version.rb
118
+ homepage: https://github.com/tongueroo/cfn_camelizer
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.0.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Cfn Camelizer
141
+ test_files: []