eyra 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fd56f950107144b5b5950e15c703494a5d52faa
4
+ data.tar.gz: e2de13023bf9d94583ab0aa35ce460aede475654
5
+ SHA512:
6
+ metadata.gz: 740e3e2f800ef1f8450d5d473ab2100851dd6aa2da1ce05e466b6e0b51ee8cd275609c74f11f98ca51d6c487ef173fd009ddbe0e34645de9910a8f54df211a7b
7
+ data.tar.gz: 2c3f8e3fcd1e0e896e8743a9ef411e576e30d5fb3c258301849271af7579374aeb19c119318d4974fe305c72197f79a9ea5679f3b20726f7e76444cc2e6cd406
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eyra.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Eyra
2
+
3
+ serializer for Ruby Objects
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'eyra'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install eyra
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class MovieSerializer
25
+ include Eyra
26
+
27
+ field :title,type: String
28
+ field :year,type: Integer
29
+
30
+ dump_format :year_in_hex do
31
+ year.to_i.to_s(16)
32
+ end
33
+ end
34
+
35
+ MovieSerialize.new(@movie).to_json # { movie: 'The fight club', year: 1999,year_in_hex: "7cf" }
36
+ ```
37
+
38
+
39
+ ### Benchmarks
40
+ wip
41
+
42
+ ### Alternatives
43
+
44
+ * `https://github.com/netflix/fast_jsonapi`
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marianogabriels/eyra.
49
+
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 "eyra"
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
data/eyra.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eyra/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eyra"
8
+ spec.version = Eyra::VERSION
9
+ spec.authors = ["Mariano"]
10
+ spec.email = ["marianogabriels@gmail.com"]
11
+
12
+ spec.summary = %q{ruby serialization/deserialization tool}
13
+ spec.homepage = "https://github.com/marianogabriels/eyra"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against " \
20
+ "public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.14"
31
+ spec.add_development_dependency "byebug"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
data/lib/eyra.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'byebug'
2
+ require "eyra/version"
3
+
4
+ module Eyra
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.fields = []
8
+ end
9
+
10
+ attr_reader :object
11
+ attr_accessor :fields
12
+
13
+ def initialize(object)
14
+ @object = object
15
+ end
16
+
17
+ def as_json
18
+ json = {}
19
+ self.class.fields.each { |field| json[field.name.to_s] = field.serialize(object) }
20
+ json
21
+ end
22
+
23
+ module ClassMethods
24
+ attr_accessor :fields
25
+
26
+ def dump_format(name,opts={},&block)
27
+ field = @fields.find{|e| e.name == name }
28
+ field.opts[:dump_format] = block
29
+ end
30
+
31
+ def field(name, opts={})
32
+ field = Field.new(name,opts)
33
+ @fields << field
34
+ self.class_eval do |klass|
35
+ define_method name do
36
+ return field.serialize(@object)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+
44
+ class Field
45
+ attr_accessor :name,:opts
46
+ Field::Mapping = {
47
+ "String" => lambda {|value| value.to_s },
48
+ "Integer" => lambda{|value| value.to_i },
49
+ "Float" => lambda{|value| value.to_f },
50
+ "Boolean" => lambda{|value| !!(value) }
51
+ }
52
+
53
+ def initialize(name,opts)
54
+ @name = name
55
+ @opts = opts
56
+ end
57
+
58
+ def serialize(object)
59
+ return value unless (opts[:type])
60
+ serializer = Field::Mapping[opts[:type].to_s]
61
+ opts[:dump_format] ? opts[:dump_format].call(object) : serializer.call(object.send(name))
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module Eyra
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eyra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mariano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-16 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: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.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.0'
69
+ description:
70
+ email:
71
+ - marianogabriels@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - eyra.gemspec
85
+ - lib/eyra.rb
86
+ - lib/eyra/version.rb
87
+ homepage: https://github.com/marianogabriels/eyra
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: ruby serialization/deserialization tool
110
+ test_files: []