grape_resource 0.1.3

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
+ SHA256:
3
+ metadata.gz: 5785fa70d230cc60d30b9697296ccd0cb5a1a0ee43258345c3ba5eef5a5e9878
4
+ data.tar.gz: 14adaeb5c8107575411ac066e1e983f4ba1db57804268c671a9ae26a042f61f9
5
+ SHA512:
6
+ metadata.gz: 655a039abb684839b9ad128d75c153e3a8116141456a6aa1ae39146c40f650dd8f41eb5bb19f1c3833c0731d332661530b4c2207bf001534b7cbca785b485de1
7
+ data.tar.gz: caa522101776ec36d70f574c84bd7318320605c59cde01cb951bb8da39bf6997c4357c3afb022bd0a147fc7f9fbb935b02ec80e7d95ab0b29e8613a9d98a0965
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
12
+
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
@@ -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 m.yunan.helmy@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
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in grape_resource.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grape_resource (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (5.2.3)
10
+ actionview (= 5.2.3)
11
+ activesupport (= 5.2.3)
12
+ rack (~> 2.0)
13
+ rack-test (>= 0.6.3)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
16
+ actionview (5.2.3)
17
+ activesupport (= 5.2.3)
18
+ builder (~> 3.1)
19
+ erubi (~> 1.4)
20
+ rails-dom-testing (~> 2.0)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
22
+ activesupport (5.2.3)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (>= 0.7, < 2)
25
+ minitest (~> 5.1)
26
+ tzinfo (~> 1.1)
27
+ builder (3.2.3)
28
+ concurrent-ruby (1.1.5)
29
+ crass (1.0.4)
30
+ diff-lcs (1.3)
31
+ erubi (1.8.0)
32
+ generator_spec (0.9.4)
33
+ activesupport (>= 3.0.0)
34
+ railties (>= 3.0.0)
35
+ i18n (1.6.0)
36
+ concurrent-ruby (~> 1.0)
37
+ loofah (2.2.3)
38
+ crass (~> 1.0.2)
39
+ nokogiri (>= 1.5.9)
40
+ method_source (0.9.2)
41
+ mini_portile2 (2.4.0)
42
+ minitest (5.11.3)
43
+ nokogiri (1.10.3)
44
+ mini_portile2 (~> 2.4.0)
45
+ rack (2.0.7)
46
+ rack-test (1.1.0)
47
+ rack (>= 1.0, < 3)
48
+ rails-dom-testing (2.0.3)
49
+ activesupport (>= 4.2.0)
50
+ nokogiri (>= 1.6)
51
+ rails-html-sanitizer (1.0.4)
52
+ loofah (~> 2.2, >= 2.2.2)
53
+ railties (5.2.3)
54
+ actionpack (= 5.2.3)
55
+ activesupport (= 5.2.3)
56
+ method_source
57
+ rake (>= 0.8.7)
58
+ thor (>= 0.19.0, < 2.0)
59
+ rake (10.5.0)
60
+ rspec (3.8.0)
61
+ rspec-core (~> 3.8.0)
62
+ rspec-expectations (~> 3.8.0)
63
+ rspec-mocks (~> 3.8.0)
64
+ rspec-core (3.8.1)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-expectations (3.8.4)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.8.0)
69
+ rspec-mocks (3.8.1)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.8.0)
72
+ rspec-support (3.8.2)
73
+ thor (0.20.3)
74
+ thread_safe (0.3.6)
75
+ tzinfo (1.2.5)
76
+ thread_safe (~> 0.1)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ bundler (~> 2.0)
83
+ generator_spec
84
+ grape_resource!
85
+ rake (~> 10.0)
86
+ rspec (~> 3.0)
87
+
88
+ BUNDLED WITH
89
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yunan Helmy
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,107 @@
1
+ # GrapeResource
2
+
3
+ GrapeResource is opinionated resource generator for your Grape API mounted inside Rails.
4
+
5
+ By using GrapeResource, you could generate Grape endpoints just like rails generate scaffold controller. GrapeResource only generates API resource. You need to create a model by yourself.
6
+
7
+ ## Dependencies
8
+
9
+ 1. Grape (mounted on Rails)
10
+ 2. Grape Entity
11
+ 3. Rspec
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'grape_resource'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install grape_resource
28
+
29
+ ## Usage
30
+
31
+ ### Initialize
32
+
33
+ Initialize GrapeResource with command :
34
+
35
+ $ rails g grape_resource:install
36
+
37
+ ### Configuration
38
+
39
+ Modify GrapeResource configuration inside `config/initializers/grape_resource.rb`
40
+
41
+ 1. `config.directory` will be your endpoint directory. Default to : `controllers/API/v1/`
42
+ 2. `config.class_name_prefix` will be your class name prefix for your endpoint. Default to : `API::V1`
43
+
44
+ ### Generator
45
+
46
+ To generate REST API :
47
+
48
+ $ rails g grape_resource:rest class_name
49
+
50
+ This will give you :
51
+
52
+ 1. GET /
53
+ 2. GET /:id
54
+ 3. POST /
55
+ 4. PUT /:id
56
+ 5. DELETE /:id
57
+
58
+ To generate namespaced API :
59
+
60
+ $ rails g grape_resource:namespace namespace api_endpoint1 api_endpoint2:method
61
+
62
+ While method is one of :
63
+
64
+ 1. `get` (default)
65
+ 2. `post`
66
+ 3. `put`
67
+ 4. `delete`
68
+
69
+ Command above will give you :
70
+
71
+ 1. GET /namespace/api_endpoint1
72
+ 2. METHOD /namespace/api_endpoint2
73
+
74
+ Endpoint generators above contains :
75
+
76
+ 1. `routes.rb` This is your endpoint entry point. You could mount it to your main entry point
77
+ 2. `entities` directory. It contains grape entity for your endpoint.
78
+ 3. `resources` directory. It contains your endpoint.
79
+ 4. `spec` directory. It contains rspec test for your endpoint.
80
+
81
+ ## Development
82
+
83
+ 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.
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`.
86
+
87
+ ## Release
88
+
89
+ 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).
90
+
91
+ You could use [gem release](https://github.com/svenfuchs/gem-release).
92
+ 1. Install gem release using command `gem install gem-release`.
93
+ 2. Update version using command `gem bump minor`
94
+ 3. Build gem using command `gem build grape_resource.gemspec`
95
+ 4. Release gem using command `gem release`
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/extrainteger/grape_resource. 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.
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
104
+
105
+ ## Code of Conduct
106
+
107
+ Everyone interacting in the GrapeResource project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/extrainteger/grape_resource/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "grape_resource"
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
@@ -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,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "grape_resource/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grape_resource"
8
+ spec.version = GrapeResource::VERSION
9
+ spec.authors = ["Yunan Helmy", "Ashar Mubasir"]
10
+ spec.email = ["helmy@extrainteger.com", "ashar@extrainteger.com"]
11
+
12
+ spec.summary = "GrapeResource is opinionated resource generator for your Grape API"
13
+ spec.description = "GrapeResource is opinionated resource generator for your Grape API mounted inside Rails"
14
+ spec.homepage = "https://github.com/extrainteger/grape-resource"
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
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/extrainteger/grape-resource"
24
+ spec.metadata["changelog_uri"] = "https://github.com/extrainteger/grape-resource/blob/master/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "generator_spec"
43
+ end
@@ -0,0 +1,9 @@
1
+ module GrapeResource
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../../templates", __FILE__)
4
+
5
+ def copy_initializer
6
+ template "initializer.rb", "config/initializers/grape_resource.rb"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ GrapeResource.setup do |config|
2
+ # Directory to create endpoint
3
+ config.directory = "controllers/API/v1/"
4
+
5
+ # Class name prefix
6
+ config.class_name_prefix = "API::V1"
7
+ end
@@ -0,0 +1,11 @@
1
+ require "grape_resource/version"
2
+ require "grape_resource/configuration"
3
+
4
+ module GrapeResource
5
+ class Error < StandardError; end
6
+
7
+ extend GrapeResource::Configuration
8
+
9
+ define_setting :directory, "controllers/API/v1/"
10
+ define_setting :class_name_prefix, "API::V1"
11
+ end
@@ -0,0 +1,27 @@
1
+ module GrapeResource
2
+ module Configuration
3
+ def setup
4
+ yield self
5
+ end
6
+
7
+ def define_setting(name, default = nil)
8
+ class_variable_set("@@#{name}", default)
9
+
10
+ define_class_method "#{name}=" do |value|
11
+ class_variable_set("@@#{name}", value)
12
+ end
13
+
14
+ define_class_method name do
15
+ class_variable_get("@@#{name}")
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def define_class_method(name, &block)
22
+ (class << self; self; end).instance_eval do
23
+ define_method name, &block
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module GrapeResource
2
+ VERSION = "0.1.3"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape_resource
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Yunan Helmy
8
+ - Ashar Mubasir
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2019-06-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: generator_spec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: GrapeResource is opinionated resource generator for your Grape API mounted
71
+ inside Rails
72
+ email:
73
+ - helmy@extrainteger.com
74
+ - ashar@extrainteger.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - grape_resource.gemspec
91
+ - lib/generators/grape_resource/install_generator.rb
92
+ - lib/generators/templates/initializer.rb
93
+ - lib/grape_resource.rb
94
+ - lib/grape_resource/configuration.rb
95
+ - lib/grape_resource/version.rb
96
+ homepage: https://github.com/extrainteger/grape-resource
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ allowed_push_host: https://rubygems.org
101
+ homepage_uri: https://github.com/extrainteger/grape-resource
102
+ source_code_uri: https://github.com/extrainteger/grape-resource
103
+ changelog_uri: https://github.com/extrainteger/grape-resource/blob/master/CHANGELOG.md
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.0.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: GrapeResource is opinionated resource generator for your Grape API
123
+ test_files: []