operators-serializer 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
  SHA1:
3
- metadata.gz: 7fa59a45288e736078a64062b05c25f3e9ba3a0a
4
- data.tar.gz: 7beef084a4c0e237db1f971853d7723be5a50553
3
+ metadata.gz: ddc22412d3e693d0458a4a538bca22748f732f30
4
+ data.tar.gz: 81f6c8a2097d013c15ad167e3ae1a0d3f0f62e94
5
5
  SHA512:
6
- metadata.gz: e59c9485acbb1600ec2799803e4ebb25b3a9e2d43fee4f5d46c128471e662d32b4f239f9cbf2f14d9951698613e7babd1e59c37f626d3056fe4ea3c46a3e718e
7
- data.tar.gz: 317d682817b84e9d6a5ded1b512d3f70f8c049608aafdc074eb70d4533929cf5c5ab354ea1721790aba64d62cec4556bd60ddc7de4ef3ecc72d5f42173fed00e
6
+ metadata.gz: 51f535320e9da06dc5029d42191c22f6ba61ef97442ff9be0199772fd0c832412111a6f40fcb04d2e02865d3aecc54b7d80725ce25b7f390a38514dc4232ae79
7
+ data.tar.gz: 79a18ad4add0bacdfccc67a358d0747135ccc6b5d26dfefe86cd588e0771c92886d46c80507cb84d334d21e3a54d2393a3913ec3639aca6d69c98084ca1296e8
data/.codeclimate.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: false
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ - ruby
10
+ fixme:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ ratings:
15
+ paths:
16
+ - "**.rb"
17
+ exclude_paths:
18
+ - spec/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Operators::Serializer
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/operators/serializer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ [![Code Climate](https://codeclimate.com/github/operators-rb/operators-serializer/badges/gpa.svg)](https://codeclimate.com/github/operators-rb/operators-serializer)
4
+ [![CircleCI](https://circleci.com/gh/operators-rb/operators-serializer.svg?style=shield&circle-token=9542c2160ff69e57c6e71e2cd2d8ebfb5ec2abb4)](https://circleci.com/gh/operators-rb/operators-serializer)
6
5
 
7
6
  ## Installation
8
7
 
@@ -12,27 +11,36 @@ Add this line to your application's Gemfile:
12
11
  gem 'operators-serializer'
13
12
  ```
14
13
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install operators-serializer
22
-
23
14
  ## Usage
24
15
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
16
+ ```ruby
17
+ class UserSerializer < Operators::Serializer
18
+ def as_json
19
+ {
20
+ id: id,
21
+ name: name,
22
+ email: email
23
+ }
24
+ end
25
+ end
26
+ ```
30
27
 
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).
28
+ **Usage in Rails controllers**
29
+ ```ruby
30
+ class UsersController < ApplicationController
31
+ def index
32
+ @users = UserSerializer.serialize_collection(User.all)
33
+ end
34
+
35
+ def show
36
+ @user = UserSerializer.new(User.find_by(id: params[:id])).as_json
37
+ end
38
+ end
39
+ ```
32
40
 
33
41
  ## Contributing
34
42
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/operators-serializer.
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/operators-rb/operators-serializer.
36
44
 
37
45
 
38
46
  ## License
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.4
@@ -0,0 +1 @@
1
+ require "operators/serializer"
@@ -1,7 +1,15 @@
1
- require "operators/serializer/version"
2
-
3
1
  module Operators
4
- module Serializer
5
- # Your code goes here...
2
+ class Serializer < SimpleDelegator
3
+ def self.serialize_collection(collection, *args)
4
+ collection.map { |r| new(r).as_json(*args) }
5
+ end
6
+
7
+ def as_json(*)
8
+ raise 'Not implemented'
9
+ end
10
+
11
+ def to_json(*)
12
+ as_json.to_json
13
+ end
6
14
  end
7
15
  end
@@ -1,16 +1,15 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'operators/serializer/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "operators-serializer"
8
- spec.version = Operators::Serializer::VERSION
7
+ spec.version = "0.2.0"
9
8
  spec.authors = ["Kirill Shevchenko"]
10
9
  spec.email = ["hello@kirillshevch.com"]
11
10
 
12
- spec.summary = %q{operators-serializer}
13
- spec.description = %q{operators-serializer}
11
+ spec.summary = %q{You don’t need Active Model Serializers}
12
+ spec.description = spec.summary
14
13
  spec.homepage = "http://operators-rb.org"
15
14
  spec.license = "MIT"
16
15
 
@@ -23,4 +22,6 @@ Gem::Specification.new do |spec|
23
22
 
24
23
  spec.add_development_dependency "bundler", "~> 1.13"
25
24
  spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.5.0"
26
+ spec.add_development_dependency "byebug", "~> 3.5.0"
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: operators-serializer
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
  - Kirill Shevchenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,22 +38,51 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: operators-serializer
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.5.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.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.5.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.5.0
69
+ description: You don’t need Active Model Serializers
42
70
  email:
43
71
  - hello@kirillshevch.com
44
72
  executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
76
+ - ".codeclimate.yml"
48
77
  - ".gitignore"
78
+ - ".rspec"
49
79
  - Gemfile
50
80
  - LICENSE.txt
51
81
  - README.md
52
82
  - Rakefile
53
- - bin/console
54
- - bin/setup
83
+ - circle.yml
84
+ - lib/operators-serializer.rb
55
85
  - lib/operators/serializer.rb
56
- - lib/operators/serializer/version.rb
57
86
  - operators-serializer.gemspec
58
87
  homepage: http://operators-rb.org
59
88
  licenses:
@@ -75,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
104
  version: '0'
76
105
  requirements: []
77
106
  rubyforge_project:
78
- rubygems_version: 2.5.1
107
+ rubygems_version: 2.5.2
79
108
  signing_key:
80
109
  specification_version: 4
81
- summary: operators-serializer
110
+ summary: You don’t need Active Model Serializers
82
111
  test_files: []
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "operators/serializer"
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
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- module Operators
2
- module Serializer
3
- VERSION = "0.1.0"
4
- end
5
- end