onsi 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efa13befa06b8a9e8c45e5364b9e77c14e261fa5898dc4c7a2fd7e881234b69c
4
- data.tar.gz: c3ca075945d5d8cb2d9c8f2e144039dab47338b23812674ac4cbd31639c51ae0
3
+ metadata.gz: f6876fd03dec07fb6571c584c254067e71a712acb2baf9ba1909994ad10d3da5
4
+ data.tar.gz: 919f4fdf156575a8dbacaab8158b8ef127aa2adff5f5927bcb1d25087dcc6468
5
5
  SHA512:
6
- metadata.gz: 2cb3264cd255c4a38803b352ef173f97f5e1a84ee58a7747cf1bb5951a083b708ad5963b8ac2625941f11cf33dac960a101199e001aa5e73e57c54d409ddd781
7
- data.tar.gz: 538a6e4abb95c6eba3525a03816b4db692b1948bae8fdbe43c85ce2a1baed0b209c89cbd96c018a322166dc6749b4d4f429fb53a583378cd417d8d5380a4ef15
6
+ metadata.gz: e49c1ac4c3e0ab31824c85f24c9bbb037386e06ab7d6ad12d4ed07edb4283e468ab3057f4d6a25ae5de62870c7700b84ffadae571e616a9c33618f382f0e02d4
7
+ data.tar.gz: 0270570b4771731f58367f1c6afad48708a11bdca9eb703bee8a09528d7debe6c09d0f6341ec5a50897b92ef7c5d35d681cc931c70cdd3c01badacb981b2b395
@@ -0,0 +1,111 @@
1
+ version: 2
2
+ jobs:
3
+ latest:
4
+ environment:
5
+ CC_TEST_REPORTER_ID: 15f1ab72e4d38e92cc8ffe4490022ae9bdc9265a0319c30e673ee3e4e7a5a371
6
+ docker:
7
+ - image: circleci/ruby:latest
8
+ working_directory: ~/repo
9
+ steps:
10
+ - checkout
11
+ - run:
12
+ name: ruby version
13
+ command: ruby --version
14
+ - run:
15
+ name: Setup Code Climate test-reporter
16
+ command: |
17
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
18
+ chmod +x ./cc-test-reporter
19
+ - restore_cache:
20
+ keys:
21
+ - v1-gems-latest-{{ checksum "onsi.gemspec" }}
22
+ - v1-gems-latest-
23
+ - run:
24
+ name: install gems
25
+ command: |
26
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
27
+ - save_cache:
28
+ key: v1-gems-latest-{{ checksum "onsi.gemspec" }}
29
+ paths:
30
+ - ./vendor/bundle
31
+ - run:
32
+ name: Run Specs
33
+ command: bundle exec rspec spec/**/*.rb
34
+ - run:
35
+ name: Report Coverage
36
+ command: |
37
+ ./cc-test-reporter format-coverage -t simplecov $CIRCLE_ARTIFACTS/coverage/.resultset.json
38
+ ./cc-test-reporter upload-coverage
39
+ - store_artifacts:
40
+ path: coverage/coverage.json
41
+ build_2_5:
42
+ docker:
43
+ - image: circleci/ruby:2.5
44
+ working_directory: ~/repo
45
+ steps:
46
+ - checkout
47
+ - restore_cache:
48
+ keys:
49
+ - v1-gems-build_2_5-{{ checksum "onsi.gemspec" }}
50
+ - v1-gems-build_2_5-
51
+ - run:
52
+ name: install gems
53
+ command: |
54
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
55
+ - save_cache:
56
+ key: v1-gems-build_2_5-{{ checksum "onsi.gemspec" }}
57
+ paths:
58
+ - ./vendor/bundle
59
+ - run:
60
+ name: Run Specs
61
+ command: bundle exec rspec spec/**/*.rb
62
+ build_2_4:
63
+ docker:
64
+ - image: circleci/ruby:2.4.2
65
+ working_directory: ~/repo
66
+ steps:
67
+ - checkout
68
+ - restore_cache:
69
+ keys:
70
+ - v1-gems-build_2_4-{{ checksum "onsi.gemspec" }}
71
+ - v1-gems-build_2_4-
72
+ - run:
73
+ name: install gems
74
+ command: |
75
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
76
+ - save_cache:
77
+ key: v1-gems-build_2_4-{{ checksum "onsi.gemspec" }}
78
+ paths:
79
+ - ./vendor/bundle
80
+ - run:
81
+ name: Run Specs
82
+ command: bundle exec rspec spec/**/*.rb
83
+ build_2_3:
84
+ docker:
85
+ - image: circleci/ruby:2.3.4
86
+ working_directory: ~/repo
87
+ steps:
88
+ - checkout
89
+ - restore_cache:
90
+ keys:
91
+ - v1-gems-build_2_3-{{ checksum "onsi.gemspec" }}
92
+ - v1-gems-build_2_3-
93
+ - run:
94
+ name: install gems
95
+ command: |
96
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
97
+ - save_cache:
98
+ key: v1-gems-build_2_3-{{ checksum "onsi.gemspec" }}
99
+ paths:
100
+ - ./vendor/bundle
101
+ - run:
102
+ name: Run Specs
103
+ command: bundle exec rspec spec/**/*.rb
104
+ workflows:
105
+ version: 2
106
+ specs:
107
+ jobs:
108
+ - build_2_3
109
+ - build_2_4
110
+ - build_2_5
111
+ - latest
data/.codeclimate.yml ADDED
@@ -0,0 +1,7 @@
1
+ engines:
2
+ fixme:
3
+ enabled: true
4
+ rubocop:
5
+ enabled: true
6
+ bundler-audit:
7
+ enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- onsi (0.1.0)
4
+ onsi (0.2.0)
5
5
  rails (>= 5.0, < 6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,39 +1,12 @@
1
1
  # Onsi
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/onsi`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Used to generate API responses from a rails App.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ =================================================
6
6
 
7
- ## Installation
7
+ [![CircleCI](https://circleci.com/gh/skylarsch/onsi.svg?style=svg)](https://circleci.com/gh/skylarsch/onsi)
8
8
 
9
- Add this line to your application's Gemfile:
9
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c3ee44371f7565f2709c/maintainability)](https://codeclimate.com/github/skylarsch/onsi/maintainability)
10
10
 
11
- ```ruby
12
- gem 'onsi'
13
- ```
11
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c3ee44371f7565f2709c/test_coverage)](https://codeclimate.com/github/skylarsch/onsi/test_coverage)
14
12
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install onsi
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- 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.
30
-
31
- 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).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/onsi.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -4,8 +4,15 @@ module Onsi
4
4
  module Controller
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ module ClassMethods
8
+ def render_version(version = nil)
9
+ @render_version = version if version
10
+ @render_version
11
+ end
12
+ end
13
+
7
14
  def render_resource(resource, opts = {})
8
- version = opts.delete(:version) || Model::DEFAULT_API_VERSION
15
+ version = opts.delete(:version) || self.class.render_version || Model::DEFAULT_API_VERSION
9
16
  payload = format_resource(resource, version)
10
17
  render_options = {}
11
18
  render_options[:json] = { data: payload }
data/lib/onsi/resource.rb CHANGED
@@ -2,9 +2,12 @@ module Onsi
2
2
  class Resource
3
3
  attr_reader :object, :version
4
4
 
5
+ class InvalidResourceError < StandardError; end
6
+
5
7
  def initialize(object, version = Model::DEFAULT_API_VERSION)
6
8
  @object = object
7
9
  @version = version
10
+ validate!
8
11
  end
9
12
 
10
13
  def as_json(_opts = {})
@@ -21,6 +24,11 @@ module Onsi
21
24
 
22
25
  private
23
26
 
27
+ def validate!
28
+ return if object.class.included_modules.include?(Onsi::Model)
29
+ raise InvalidResourceError, "Trying to render a #{object.class.name}. But it doesn't include Onsi::Model"
30
+ end
31
+
24
32
  def type
25
33
  object.class.api_renderer(version, for_render: true).type || object.class.name.underscore
26
34
  end
data/lib/onsi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Onsi
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skylar Schipper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-13 00:00:00.000000000 Z
11
+ date: 2018-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -149,6 +149,8 @@ executables: []
149
149
  extensions: []
150
150
  extra_rdoc_files: []
151
151
  files:
152
+ - ".circleci/config.yml"
153
+ - ".codeclimate.yml"
152
154
  - ".gitignore"
153
155
  - ".rspec"
154
156
  - ".rubocop.yml"