ruby-commandify 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/commandify.gemspec +37 -0
- data/lib/commandify/version.rb +3 -0
- data/lib/commandify.rb +5 -0
- data/lib/generators/command/command_generator.rb +150 -0
- data/lib/generators/command/templates/application_controller.rb +5 -0
- data/lib/generators/command/templates/application_serializer.rb +24 -0
- data/lib/generators/command/templates/authentication.rb +14 -0
- data/lib/generators/command/templates/command.feature +7 -0
- data/lib/generators/command/templates/command.rb +39 -0
- data/lib/generators/command/templates/command_handler.rb +12 -0
- data/lib/generators/command/templates/command_spec.rb +27 -0
- data/lib/generators/command/templates/env.rb +21 -0
- data/lib/generators/command/templates/faker.rb +19 -0
- data/lib/generators/command/templates/helper.rb +41 -0
- data/lib/generators/command/templates/resource_serializer.rb +3 -0
- data/lib/generators/command/templates/resources_controller.rb +5 -0
- data/lib/generators/command/templates/serializer.rb +15 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3dcafc448a74bbf0b4f777f5595e4414760432f5
|
4
|
+
data.tar.gz: '002279f88d5df3607e148c05c7b4da9bbefa3d4d'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 977f81c34ef5d61a5e561926fe3066620c85d33bde9132788156f376665ac2026b6bb014a0c9e276081f63a9448bbb5321f9655e9b9bd49a0dc035e1ea6ceec4
|
7
|
+
data.tar.gz: 67b7b094d3d2a77cb500ed66797baffc93b86c58a6d408310f42db85f712d01fd3dc1a5eacc61d0115f4ca9e162eaac0a1627a6ab16c30b4e085121338449165
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at checkraiser11@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Truong Dung
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Commandify
|
2
|
+
|
3
|
+
DRY your feature.
|
4
|
+
|
5
|
+
Architecture:
|
6
|
+
|
7
|
+
```
|
8
|
+
HTTP request -> Authentication -> Command -> CommandHandler -> Serializer
|
9
|
+
```
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'active_model_serializer'
|
17
|
+
gem 'faker', group: [:development, :test]
|
18
|
+
gem 'spinach', group: :test
|
19
|
+
gem 'simple_command'
|
20
|
+
gem 'commandify', group: [:development, :test]
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install commandify
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```
|
34
|
+
bin/rails g command attribute:presence attribute2
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
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.
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/commandify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "commandify"
|
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__)
|
data/bin/setup
ADDED
data/commandify.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'commandify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-commandify"
|
8
|
+
spec.version = Commandify::VERSION
|
9
|
+
spec.authors = ["Truong Dung"]
|
10
|
+
spec.email = ["checkraiser11@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Commandify"
|
13
|
+
spec.description = "Commandify"
|
14
|
+
spec.homepage = "https://github.com/checkraiser/commandify"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "rails", "~> 4.0"
|
37
|
+
end
|
data/lib/commandify.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
class CommandGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
argument :values, type: :array, :default => [], :banner => 'value1:attr1 value2:attr2 value3:attr3 etc...'
|
4
|
+
|
5
|
+
class_option :collection, type: :boolean, default: false
|
6
|
+
class_option :version, type: :string, default: "v1"
|
7
|
+
|
8
|
+
def create_command_file
|
9
|
+
template "env.rb", "features/support/env.rb"
|
10
|
+
template "faker.rb", "features/steps/common/faker.rb"
|
11
|
+
template "helper.rb", "features/steps/common/helper.rb"
|
12
|
+
template "command.rb", "app/commands/api/#{options[:version]}/#{file_name}_command.rb"
|
13
|
+
template "command_spec.rb", "spec/commands/api/#{options[:version]}/#{file_name}_command_spec.rb"
|
14
|
+
inject_into_file "config/routes.rb", routes_temp, before: /^end/
|
15
|
+
template "command.feature", "features/api/#{options[:version]}/#{file_name}.feature"
|
16
|
+
template "application_controller.rb", "app/controllers/api/#{options[:version]}/application_controller.rb"
|
17
|
+
template "authentication.rb", "app/controllers/concerns/authentication.rb"
|
18
|
+
template "serializer.rb", "app/controllers/concerns/serializer.rb"
|
19
|
+
template "application_serializer.rb", "app/serializers/application_serializer.rb"
|
20
|
+
template "resource_serializer.rb", "app/serializers/api/#{options[:version]}/#{file_name}_serializer.rb"
|
21
|
+
template "command_handler.rb", "app/controllers/concerns/command_handler.rb"
|
22
|
+
template "resources_controller.rb", "app/controllers/api/#{options[:version]}/#{resources}_controller.rb"
|
23
|
+
inject_into_file "app/controllers/api/#{options[:version]}/#{resources}_controller.rb", inject_action_controller, before: /private/
|
24
|
+
inject_into_file "app/controllers/api/#{options[:version]}/#{resources}_controller.rb", inject_params_controller, after: /private/
|
25
|
+
if options[:collection]
|
26
|
+
inject_into_file "config/routes.rb", inject_route_temp_collection, after: /namespace :#{options[:version]} do/
|
27
|
+
else
|
28
|
+
inject_into_file "config/routes.rb", inject_route_temp_member, after: /namespace :#{options[:version]} do/
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def routes_temp
|
35
|
+
<<~HEREDOC
|
36
|
+
namespace :api do
|
37
|
+
namespace :#{options[:version]} do
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
HEREDOC
|
42
|
+
end
|
43
|
+
|
44
|
+
def inject_route_temp_collection
|
45
|
+
<<~HEREDOC
|
46
|
+
|
47
|
+
resources :#{resource.pluralize} do
|
48
|
+
post :#{verb}, on: :collection
|
49
|
+
end
|
50
|
+
|
51
|
+
HEREDOC
|
52
|
+
end
|
53
|
+
|
54
|
+
def inject_route_temp_member
|
55
|
+
<<~HEREDOC
|
56
|
+
|
57
|
+
resources :#{resource.singlarize} do
|
58
|
+
put :#{verb}, on: :member
|
59
|
+
end
|
60
|
+
|
61
|
+
HEREDOC
|
62
|
+
end
|
63
|
+
|
64
|
+
def feature_name
|
65
|
+
"#{verb.titleize} #{resource.camelize}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def intention
|
69
|
+
"#{verb} #{resource.camelize}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def resources
|
73
|
+
resource.pluralize
|
74
|
+
end
|
75
|
+
|
76
|
+
def inject_action_controller
|
77
|
+
<<~HEREDOC
|
78
|
+
|
79
|
+
def #{verb}
|
80
|
+
serialize(
|
81
|
+
handle(Api::#{options[:version].upcase}::#{file_name.camelize}Command, #{file_name}_params), Api::#{options[:version].upcase}::#{file_name.camelize}Serializer
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
HEREDOC
|
86
|
+
end
|
87
|
+
|
88
|
+
def inject_params_controller
|
89
|
+
<<~HEREDOC
|
90
|
+
|
91
|
+
def #{file_name}_params
|
92
|
+
params.require(:#{resource})
|
93
|
+
.permit(#{kreaders})
|
94
|
+
.merge(current_user: current_user)
|
95
|
+
end
|
96
|
+
|
97
|
+
HEREDOC
|
98
|
+
end
|
99
|
+
|
100
|
+
def resource
|
101
|
+
return @resource if @resource
|
102
|
+
@resource = file_name.split("_")[1..-1].join("_")
|
103
|
+
end
|
104
|
+
|
105
|
+
def verb
|
106
|
+
return @verb if @verb
|
107
|
+
@verb = file_name.split("_")[0]
|
108
|
+
end
|
109
|
+
|
110
|
+
def declaration
|
111
|
+
keys.map do |key|
|
112
|
+
"@#{key} = options[:#{key}]"
|
113
|
+
end.join("\n\t\t")
|
114
|
+
end
|
115
|
+
|
116
|
+
def kv
|
117
|
+
return @kv if @kv
|
118
|
+
@kv = { }
|
119
|
+
values.each do |v|
|
120
|
+
x, y = v.split(":")
|
121
|
+
@kv[x.to_sym] = y
|
122
|
+
end
|
123
|
+
@kv
|
124
|
+
end
|
125
|
+
|
126
|
+
def keys
|
127
|
+
return @keys if @keys
|
128
|
+
kv.keys.map(&:to_s)
|
129
|
+
end
|
130
|
+
|
131
|
+
def values
|
132
|
+
return @values if @values
|
133
|
+
kv.values
|
134
|
+
end
|
135
|
+
|
136
|
+
def kinits
|
137
|
+
return @kinits if @kinits
|
138
|
+
keys.map { |i| "#{i}: nil"}.join(", ")
|
139
|
+
end
|
140
|
+
|
141
|
+
def kreaders
|
142
|
+
return @readers if @readers
|
143
|
+
keys.map { |i| ":#{i}"}.join(", ")
|
144
|
+
end
|
145
|
+
|
146
|
+
def inits
|
147
|
+
return @inits if @inits
|
148
|
+
keys.join(", ")
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Uses russian doll technique
|
2
|
+
class ApplicationSerializer < ActiveModel::Serializer
|
3
|
+
delegate :cache_key, :to => :object
|
4
|
+
|
5
|
+
# Cache entire JSON string
|
6
|
+
def to_json(*args)
|
7
|
+
Rails.cache.fetch expand_cache_key(self.class.to_s.underscore, cache_key, 'to-json') do
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Cache individual Hash objects before serialization
|
13
|
+
# This also makes them available to associated serializers
|
14
|
+
def serializable_hash
|
15
|
+
Rails.cache.fetch expand_cache_key(self.class.to_s.underscore, cache_key, 'serilizable-hash') do
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def expand_cache_key(*args)
|
22
|
+
ActiveSupport::Cache.expand_cache_key args
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Api::<%= options[:version].upcase %>::<%= file_name.camelize %>Command
|
2
|
+
prepend SimpleCommand
|
3
|
+
include ActiveModel::Model
|
4
|
+
|
5
|
+
<% kv.each do |k, v| %>
|
6
|
+
validates <%= ":#{k}" %> <%= ", #{v}: true" if v %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
def initialize(options = { })
|
10
|
+
@current_user = options[:current_user]
|
11
|
+
<%= declaration %>
|
12
|
+
rescue => e
|
13
|
+
errors.add <%= ":#{file_name}" %>, e.message
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
return nil unless authorized?
|
19
|
+
return nil unless valid?
|
20
|
+
<%= file_name %>
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :status
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def authorized?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def <%= file_name %>
|
32
|
+
status = 200
|
33
|
+
rescue => e
|
34
|
+
errors.add <%= ":#{file_name}" %>, e.message
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :current_user, <%= kreaders %>
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe Api::<%= options[:version].upcase %>::<%= file_name.camelize %>Command do
|
4
|
+
subject(:context) { described_class.call(<%= "#{file_name}_params" %>) }
|
5
|
+
|
6
|
+
describe '.call' do
|
7
|
+
context 'when the context is successful' do
|
8
|
+
let(<%= ":#{file_name}_params" %>) do
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'succeeds' do
|
13
|
+
expect(context).to be_success
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when the context is not successful' do
|
18
|
+
let(<%= ":#{file_name}_params" %>) do
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'fails' do
|
23
|
+
expect(context).to be_failure
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
require "./config/environment"
|
3
|
+
require "rspec/rails"
|
4
|
+
require 'rack/test'
|
5
|
+
require 'database_cleaner'
|
6
|
+
require 'faker'
|
7
|
+
|
8
|
+
Dir[Rails.root.join('features/steps/common/**/*.rb')].each { |f| require f }
|
9
|
+
|
10
|
+
Spinach.hooks.before_scenario do
|
11
|
+
DatabaseCleaner.clean
|
12
|
+
end
|
13
|
+
|
14
|
+
class Spinach::FeatureSteps
|
15
|
+
include Rack::Test::Methods
|
16
|
+
include Rails.application.routes.url_helpers
|
17
|
+
include Common::Helper
|
18
|
+
include RSpec::Matchers
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveRecord::Migration.maintain_test_schema!
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Common
|
2
|
+
module Faker
|
3
|
+
def random_email
|
4
|
+
::Faker::Internet.email
|
5
|
+
end
|
6
|
+
|
7
|
+
def random_name
|
8
|
+
::Faker::Name.name
|
9
|
+
end
|
10
|
+
|
11
|
+
def random_first_name
|
12
|
+
::Faker::Name.first_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def random_last_name
|
16
|
+
::Faker::Name.last_name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative './faker'
|
2
|
+
|
3
|
+
module Common
|
4
|
+
module Helper
|
5
|
+
include Common::Faker
|
6
|
+
|
7
|
+
delegate :headers, to: :last_response
|
8
|
+
|
9
|
+
def json_body
|
10
|
+
last_response.body
|
11
|
+
end
|
12
|
+
|
13
|
+
def parsed_body
|
14
|
+
JSON.parse(json_body, symbolize_names: true)
|
15
|
+
end
|
16
|
+
|
17
|
+
def json_encode(json_hash)
|
18
|
+
ActiveSupport::JSON.encode(json_hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
def app
|
22
|
+
Rack::Builder.parse_file('config.ru').first
|
23
|
+
end
|
24
|
+
|
25
|
+
def http_status
|
26
|
+
last_response.status
|
27
|
+
end
|
28
|
+
|
29
|
+
def json_datetime_format(datetime)
|
30
|
+
datetime.to_formatted_s(:iso8601) if datetime
|
31
|
+
end
|
32
|
+
|
33
|
+
def body_ids
|
34
|
+
parsed_body.map { |obj| obj['id'] }
|
35
|
+
end
|
36
|
+
|
37
|
+
def mail_deliveries
|
38
|
+
ActionMailer::Base.deliveries
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Serializer
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def serialize(object, serializer)
|
5
|
+
if object[:result]
|
6
|
+
if object.respond_to?(:to_a?)
|
7
|
+
render json: object, each_serializer: serializer
|
8
|
+
else
|
9
|
+
render json: object, serializer: serializer
|
10
|
+
end
|
11
|
+
else
|
12
|
+
render json: { errors: object[:errors].as_json }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-commandify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Truong Dung
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-06 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
description: Commandify
|
70
|
+
email:
|
71
|
+
- checkraiser11@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- commandify.gemspec
|
87
|
+
- lib/commandify.rb
|
88
|
+
- lib/commandify/version.rb
|
89
|
+
- lib/generators/command/command_generator.rb
|
90
|
+
- lib/generators/command/templates/application_controller.rb
|
91
|
+
- lib/generators/command/templates/application_serializer.rb
|
92
|
+
- lib/generators/command/templates/authentication.rb
|
93
|
+
- lib/generators/command/templates/command.feature
|
94
|
+
- lib/generators/command/templates/command.rb
|
95
|
+
- lib/generators/command/templates/command_handler.rb
|
96
|
+
- lib/generators/command/templates/command_spec.rb
|
97
|
+
- lib/generators/command/templates/env.rb
|
98
|
+
- lib/generators/command/templates/faker.rb
|
99
|
+
- lib/generators/command/templates/helper.rb
|
100
|
+
- lib/generators/command/templates/resource_serializer.rb
|
101
|
+
- lib/generators/command/templates/resources_controller.rb
|
102
|
+
- lib/generators/command/templates/serializer.rb
|
103
|
+
homepage: https://github.com/checkraiser/commandify
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata:
|
107
|
+
allowed_push_host: https://rubygems.org
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.11
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Commandify
|
128
|
+
test_files: []
|