aerials 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55d124b4056f7777832c330340576788de10c2a3
4
+ data.tar.gz: 2102944d9b1c3e50302cc8ccfc7a4d7745aa565c
5
+ SHA512:
6
+ metadata.gz: 0798f0491e79da7edb1a9b7bc24a38ec58e9313139a2461f545fad115703c08f2102fb92619d5e36979ec2291b6679f0f2e9a984a2b64f2025d5f03accb6a660
7
+ data.tar.gz: 99a100cacef2d39d5bc87d4f35aca29fde188748abb2ff7e04bf6a932846e1c53ab7e81aa187c0021f31ece456bc20d5f08a8ab9b42c6ac60d0e2f642b990b89
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ .idea
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aerials.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Roman Exempliarov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Aerials
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'aerials'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aerials
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/appelsin/aerials )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/aerials.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aerials/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aerials"
8
+ spec.version = Aerials::VERSION
9
+ spec.authors = ["Roman Exempliarov"]
10
+ spec.email = ["urvala@gmail.com"]
11
+ spec.summary = %q{Sorted json generator. Use it for hash signing.}
12
+ spec.description = %q{Sorted json generator. Use it for hash signing.}
13
+ spec.homepage = "https://github.com/appelsin/aerials"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ end
@@ -0,0 +1,3 @@
1
+ class Aerials
2
+ VERSION = "0.0.1"
3
+ end
data/lib/aerials.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "aerials/version"
2
+
3
+ class Aerials
4
+ def self.sign(struct, exclude: [])
5
+ create_json(struct, exclude)
6
+ end
7
+
8
+ def self.create_json_rails(struct, exclude: [:action, :controller, :key])
9
+ self.create_json(struct, exclude)
10
+ end
11
+
12
+ def self.create_json(struct, exclude: [])
13
+ if struct.is_a? Hash
14
+ struct = struct.clone
15
+ exclude.each { |key| struct.delete(key) }
16
+ struct = struct.sort
17
+ "{#{ struct.map{|elem| "#{to_val elem[0]}:#{to_val elem[1]}"}.join(',') }}"
18
+ elsif struct.is_a? Array
19
+ struct = struct.clone.sort
20
+ "[#{ struct.map{|elem| to_val elem }.join(',') }]"
21
+ elsif struct.respond_to? :to_s
22
+ struct.to_s
23
+ else
24
+ ''
25
+ end
26
+ end
27
+
28
+ def self.to_val(elem)
29
+ elem = elem.to_s if elem.is_a?(Symbol)
30
+
31
+ if elem.is_a?(Hash) || elem.is_a?(Array)
32
+ self.create_json(elem)
33
+ elsif elem.is_a?(String)
34
+ "'#{ elem.to_s.gsub("'","\\'") }'"
35
+ else
36
+ "'#{ elem.to_s }'"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Aerials do
4
+ context 'create_json' do
5
+ {
6
+ 'string keys & vals' => {'key_a' => 'val_a', 'key_b' => 'val_b'},
7
+ 'symbol keys' => {:key_a => 'val_a', :key_b => 'val_b'},
8
+ 'symbol keys & vals' => {:key_a => :val_a, :key_b => :val_b}
9
+ }.each do |type, struct|
10
+ it "processes plain hash with #{type} correctly" do
11
+ expect(Aerials.create_json struct).to eq "{'key_a':'val_a','key_b':'val_b'}"
12
+ end
13
+ end
14
+
15
+ {
16
+ 'string vals' => ['val_a', 'val_b'],
17
+ 'symbol vals' => [:val_a, :val_b]
18
+ }.each do |type, struct|
19
+ it "processes plain array with #{type} correctly" do
20
+ expect(Aerials.create_json struct).to eq "['val_a','val_b']"
21
+ end
22
+ end
23
+
24
+ it 'sorts hash keys' do
25
+ struct = {'b' => 'c', 'c' => 'z', 'a' => 'g'}
26
+ expect(Aerials.create_json struct).to eq "{'a':'g','b':'c','c':'z'}"
27
+ end
28
+
29
+ it 'sorts array' do
30
+ struct = ['b', 'c', 'a']
31
+ expect(Aerials.create_json struct).to eq "['a','b','c']"
32
+ end
33
+
34
+ it 'processes nested hash' do
35
+ struct = { 'key_a' => 'val_a',
36
+ 'key_b' => { 'key_d' => 'val_d', 'key_c' => 'val_c'},
37
+ 'key_e' => 'val_e' }
38
+ expect(
39
+ Aerials.create_json struct
40
+ ).to eq "{'key_a':'val_a','key_b':{'key_c':'val_c','key_d':'val_d'},'key_e':'val_e'}"
41
+ end
42
+
43
+ it 'processes nested array' do
44
+ struct = { 'key_a' => 'val_a',
45
+ 'key_b' => ['val_d', 'val_c'],
46
+ 'key_e' => 'val_e' }
47
+ expect(
48
+ Aerials.create_json struct
49
+ ).to eq "{'key_a':'val_a','key_b':['val_c','val_d'],'key_e':'val_e'}"
50
+ end
51
+
52
+ it 'quotes numbers in array' do
53
+ struct = [1, 2]
54
+ expect(Aerials.create_json struct).to eq "['1','2']"
55
+ end
56
+
57
+ it 'quotes numbers' do
58
+ struct = { 1 => 2, 3 => 4 }
59
+ expect(Aerials.create_json struct).to eq "{'1':'2','3':'4'}"
60
+ end
61
+
62
+ it 'excludes keys' do
63
+ struct = {'b' => 'c', 'c' => 'z', 'a' => 'g', 'd' => 'e'}
64
+ expect(Aerials.create_json struct, exclude: ['c', 'd']).to eq "{'a':'g','b':'c'}"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1 @@
1
+ require 'aerials'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aerials
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Exempliarov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: Sorted json generator. Use it for hash signing.
56
+ email:
57
+ - urvala@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - aerials.gemspec
68
+ - lib/aerials.rb
69
+ - lib/aerials/version.rb
70
+ - spec/aerials_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: https://github.com/appelsin/aerials
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Sorted json generator. Use it for hash signing.
96
+ test_files:
97
+ - spec/aerials_spec.rb
98
+ - spec/spec_helper.rb