josebuilder 1.0.0.pre → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/josebuilder/josebuilder_generator.rb +56 -58
- metadata +3 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23b60c029063a8ba8a33e0cafcf1036817cf641
|
4
|
+
data.tar.gz: f853a0db3168ca2f0f0da537304e6eaa38918d73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4542abfa611bf9f9eebde5212918ed14e91a120ac6476c88537d1576fa00db7e443d05f9b3090e9013f71930f5cf041c4c4a36297a2f79b48e1fe3b5eba4331d
|
7
|
+
data.tar.gz: ae4e6b7fce4f8cbac2dddd0cdda802ab79bcf534e0e143a6a41824017a95a043c895c4520f67e03fa84f7d6e9054a344944edb53159583a2f058dd339402a84e
|
@@ -1,74 +1,72 @@
|
|
1
|
-
require 'rails/generators'
|
2
1
|
require 'rails/generators/resource_helpers'
|
3
2
|
require 'rails/generators/named_base'
|
4
|
-
module Josebuilder
|
5
|
-
class JosebuilderGenerator < Rails::Generators::Base
|
6
|
-
source_root File.expand_path('../templates', __FILE__)
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
argument :algorithm, :type => :string, :default => "HS256"
|
11
|
-
|
12
|
-
class_option :signature, :type => :boolean, :default => true,
|
13
|
-
:description => "include signature"
|
14
|
-
class_option :encryption, :type => :boolean, :default => false,
|
15
|
-
:description => "include encryption"
|
16
|
-
class_option :combination, :type => :boolean, :default => false,
|
17
|
-
:description => "combine digital signature and encryption"
|
18
|
-
|
19
|
-
def generate_json_web_signature
|
20
|
-
["index", "show"].each do |view|
|
21
|
-
file = filename_with_directory('app/views', view)
|
22
|
-
source = "signature_" + filename_with_extensions(view)
|
23
|
-
template source, file
|
24
|
-
end if options.signature?
|
25
|
-
end
|
4
|
+
class JosebuilderGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
26
6
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
7
|
+
argument :resource_name, :type => :string, :default => "defaultResourceName"
|
8
|
+
argument :secret, :type => :string, :default => "secret"
|
9
|
+
argument :algorithm, :type => :string, :default => "HS256"
|
10
|
+
|
11
|
+
class_option :signature, :type => :boolean, :default => true,
|
12
|
+
:description => "include signature"
|
13
|
+
class_option :encryption, :type => :boolean, :default => false,
|
14
|
+
:description => "include encryption"
|
15
|
+
#class_option :combination, :type => :boolean, :default => false,
|
16
|
+
# :description => "combine digital signature and encryption"
|
17
|
+
|
18
|
+
def generate_json_web_signature
|
19
|
+
["index", "show"].each do |view|
|
20
|
+
file = filename_with_directory('app/views', view)
|
21
|
+
source = "signature_" + filename_with_extensions(view)
|
22
|
+
template source, file
|
23
|
+
end if options.signature?
|
24
|
+
end
|
34
25
|
|
26
|
+
def generate_json_web_encription
|
27
|
+
["index", "show"].each do |view|
|
28
|
+
file = filename_with_directory('app/views', view)
|
29
|
+
source = "encryption_" + filename_with_extensions(view)
|
30
|
+
template source, file
|
31
|
+
end if options.encryption?
|
32
|
+
end
|
35
33
|
|
36
|
-
private
|
37
34
|
|
38
|
-
|
39
|
-
secret
|
40
|
-
end
|
41
|
-
def file_name
|
42
|
-
resource_name.underscore
|
43
|
-
end
|
35
|
+
private
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
def get_secret
|
38
|
+
secret
|
39
|
+
end
|
40
|
+
def file_name
|
41
|
+
resource_name.underscore
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
plural || singular.pluralize
|
54
|
-
end
|
44
|
+
def filename_with_extensions(name)
|
45
|
+
[name, :json, :jbuilder] * '.'
|
46
|
+
end
|
55
47
|
|
56
|
-
|
48
|
+
def pluralize(count, singular, plural = nil)
|
49
|
+
word = if (count == 1 || count =~ /^1(\.0+)?$/)
|
50
|
+
singular
|
51
|
+
else
|
52
|
+
plural || singular.pluralize
|
57
53
|
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
File.join(directory, controller_file_path, file_name)
|
62
|
-
end
|
55
|
+
"#{count || 0} #{word}"
|
56
|
+
end
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
def filename_with_directory(directory, file_name)
|
59
|
+
file_name = filename_with_extensions(file_name)
|
60
|
+
File.join(directory, controller_file_path, file_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def controller_file_path
|
64
|
+
pluralize_without_count(2, resource_name)
|
65
|
+
end
|
66
|
+
def pluralize_without_count(count, noun, text=nil)
|
67
|
+
if count!=0
|
68
|
+
count == 1? "#{noun}#{text}": "#{noun.pluralize}#{text}"
|
71
69
|
end
|
72
|
-
|
73
70
|
end
|
71
|
+
|
74
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josebuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nguyen Ngo Dinh
|
@@ -44,26 +44,6 @@ dependencies:
|
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.2'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: jwt
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '1.4'
|
54
|
-
- - '>='
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 1.4.1
|
57
|
-
type: :runtime
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - ~>
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '1.4'
|
64
|
-
- - '>='
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 1.4.1
|
67
47
|
description: json signature and encryption builder
|
68
48
|
email:
|
69
49
|
- nguyenngodinh@outlook.com
|
@@ -94,9 +74,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
74
|
version: 1.9.3
|
95
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
76
|
requirements:
|
97
|
-
- - '
|
77
|
+
- - '>='
|
98
78
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
79
|
+
version: '0'
|
100
80
|
requirements: []
|
101
81
|
rubyforge_project:
|
102
82
|
rubygems_version: 2.4.6
|