grapeful 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae3f0c43283001a1dd07a7b8e3082b3ab3826063
4
+ data.tar.gz: 05b40e23abc5e68652a072d50d402f2921513d7b
5
+ SHA512:
6
+ metadata.gz: eb9c108e9d3026d57c7d67c264e5f140e116bcf41746a9039211fe429f45b44dbca8c295c2043d79631872c4ff37c8ef2833d55203a410faf4b381bfd2723d50
7
+ data.tar.gz: 53c116cf13b75b0a3e7be69fbb2ac5c254eccf1e4567786d8760b7ff6388408d1431439f00c3ef8e7bdd513ccb4459636f6d1652d189973e59881de2d154c5a3
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grapeful.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rack-test"
8
+ gem "rspec", "~> 2.14.1"
9
+ gem "pry"
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Zoloo
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,97 @@
1
+ # Grapeful
2
+
3
+ Customer Response builder for Grape.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'grapeful'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install grapeful
18
+
19
+ ## Usage
20
+ Hello world example
21
+ ```ruby
22
+ class API < Grape::API
23
+ get :hello do
24
+ ful :hello, 'world'
25
+ end
26
+ end
27
+ ```
28
+ The response will be
29
+ ```ruby
30
+ {
31
+ "hello": "world"
32
+ }
33
+ ```
34
+
35
+ Using with ActiveRecord
36
+ ```ruby
37
+ class API < Grape::API
38
+ resources :users do
39
+ get '/' do
40
+ users = User.recent
41
+ ful :users, users
42
+ ful :total, users.length if current_user.admin?
43
+ end
44
+ end
45
+ end
46
+ ```
47
+ The response will be
48
+ ```ruby
49
+ {
50
+ "users": [
51
+ {
52
+ "id": 21,
53
+ "name": "John Smith",
54
+ "uic": "john",
55
+ "role": "admin",
56
+ "created_at": "2013-08-14T10:12:30.933Z"
57
+ }
58
+ ],
59
+ "total": 1
60
+ }
61
+ ```
62
+
63
+ Using with `active_model_serializers`
64
+ ```ruby
65
+ class API < Grape::API
66
+ resources :users do
67
+
68
+ params { requires :user, type: Hash, desc: 'User data' }
69
+ post '/' do
70
+ user = User.new(params[:user])
71
+ user.save!
72
+ ful :user, UserSerializer.new(user), message: 'The user was successfuly created.'
73
+ end
74
+ end
75
+ end
76
+ ```
77
+ The response will be
78
+ ```ruby
79
+ {
80
+ "user": {
81
+ "id": 25,
82
+ "name": "Don Dan",
83
+ "uic": "don",
84
+ "role": "admin",
85
+ "created_at": "2013-08-14T10:12:30.933Z"
86
+ },
87
+ "message": "The user was successfully created."
88
+ }
89
+ ```
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/grapeful.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grapeful/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grapeful"
8
+ spec.version = Grapeful::VERSION
9
+ spec.authors = ["Zolzaya E."]
10
+ spec.email = ["zolzaya.erdenebaatar@gmail.com"]
11
+ spec.description = "Custom Response builder for Grape"
12
+ spec.summary = "Custom Response builder for Grape"
13
+ spec.homepage = "https://github.com/zolzaya/grapeful"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "grape", "~> 0.5.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,19 @@
1
+ module Grapeful
2
+ module Endpoint
3
+
4
+ def ful(*args)
5
+ options = args.count > 1 ? args.extract_options! : {}
6
+ key, object = if args.count == 2 && args.first.is_a?(Symbol)
7
+ args
8
+ else
9
+ [nil, args.first]
10
+ end
11
+ @data ||= Hash.new
12
+ @data[key] = object if key
13
+ @data.merge!(options)
14
+ body @data
15
+ end
16
+ end
17
+ end
18
+
19
+ Grape::Endpoint.send(:include, Grapeful::Endpoint)
@@ -0,0 +1,3 @@
1
+ module Grapeful
2
+ VERSION = "0.0.1"
3
+ end
data/lib/grapeful.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "grape"
2
+ require "grapeful/version"
3
+ require "grapeful/endpoint"
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Grapeful do
4
+ subject do
5
+ Class.new(Grape::API)
6
+ end
7
+
8
+ before do
9
+ subject.format :json
10
+ end
11
+
12
+ def app
13
+ subject
14
+ end
15
+
16
+ it 'should work without grapeful' do
17
+ subject.get("/home") {"Hello World"}
18
+ get "/home"
19
+ last_response.body.should == "\"Hello World\""
20
+ end
21
+
22
+ describe "#ful" do
23
+ it 'ful' do
24
+ subject.get('/users') do
25
+ @user = OpenStruct.new(name: "Bob Marlin")
26
+ ful :user, @user
27
+ ful :fff, 'fffff', root: 'users'
28
+ ful :message, 'foo bar me'
29
+ end
30
+
31
+ get '/users'
32
+ last_response.body.should == "{\"user\":\"#<OpenStruct name=\\\"Bob Marlin\\\">\",\"fff\":\"fffff\",\"root\":\"users\",\"message\":\"foo bar me\"}"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+ require 'grape'
4
+ require 'grapeful'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ # Include Rack::Test
12
+ config.include Rack::Test::Methods
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grapeful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zolzaya E.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.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.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Custom Response builder for Grape
56
+ email:
57
+ - zolzaya.erdenebaatar@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - grapeful.gemspec
69
+ - lib/grapeful.rb
70
+ - lib/grapeful/endpoint.rb
71
+ - lib/grapeful/version.rb
72
+ - spec/grapeful_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: https://github.com/zolzaya/grapeful
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Custom Response builder for Grape
98
+ test_files:
99
+ - spec/grapeful_spec.rb
100
+ - spec/spec_helper.rb