field_serializer 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +24 -6
- data/lib/field_serializer.rb +3 -4
- data/lib/field_serializer/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35c67edd67d4a77fb624b6164547b59efaf1440c
|
4
|
+
data.tar.gz: 03034a9b2bd6fb821f320b80e1e23a3accf54f80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ae654bf02b7be05ed4d201898af6acb1159d97a161aed04812108910958cd2d98574b3dc1dfb7aebebcf14443c57dbe0bfbc6c71925e3bc3b9d862349f9e9a1
|
7
|
+
data.tar.gz: 6386530c79cf4ea076a9758672b8f94931dfff07b6f0e6c3696745381cad021eec2222eff37cea0c788b07c34a552570ca4e4ad0b9188cdf1f95238f8edcecc0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
|
+
|
8
|
+
## [0.3.0](https://github.com/everypolitician/field_serializer/compare/v0.2.0...v0.3.0) - 2016-12-02
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- There is now a proper README with some basic documentation.
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
|
16
|
+
- Inheritance now works as expected. Previously subclasses weren't getting the
|
17
|
+
fields from the parent class. [#7](https://github.com/everypolitician/field_serializer/pull/7).
|
18
|
+
|
19
|
+
## [0.2.0](https://github.com/everypolitician/field_serializer/compare/v0.1.0...v0.2.0) - 2016-10-28
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- There is now a hard requirement for Ruby >= 2.1. This is because we're using
|
24
|
+
required keyword arguments, which were introduced in Ruby 2.1.
|
25
|
+
- Fields are now defined as methods behind the scenes. This means you can call
|
26
|
+
them like normal methods from other fields.
|
27
|
+
|
28
|
+
## 0.1.0 - 2016-09-28
|
29
|
+
|
30
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# FieldSerializer
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Ruby module which allows you to specify a set of fields that you'd like
|
4
|
+
serialized in the `#to_h` method. We ([EveryPolitician](http://everypolitician.org/))
|
5
|
+
are using this library in our scrapers to make them more declarative. It allows
|
6
|
+
us to specify which fields we'd like to be scraped from a page without coupling
|
7
|
+
ourselves to how the page is fetched or where the data ends up being stored.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,7 +24,24 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
require 'field_serializer'
|
29
|
+
|
30
|
+
class Person
|
31
|
+
include FieldSerializer
|
32
|
+
|
33
|
+
field :name do
|
34
|
+
'Alice'
|
35
|
+
end
|
36
|
+
|
37
|
+
field :fruit do
|
38
|
+
:apple
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
puts Person.new.to_h
|
43
|
+
# => { :name => "Alice", :fruit => :apple }
|
44
|
+
```
|
26
45
|
|
27
46
|
## Development
|
28
47
|
|
@@ -32,5 +51,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
51
|
|
33
52
|
## Contributing
|
34
53
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/everypolitician/field_serializer.
|
data/lib/field_serializer.rb
CHANGED
@@ -5,11 +5,10 @@ module FieldSerializer
|
|
5
5
|
klass.extend(ClassMethods)
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(options = {})
|
9
|
-
options.each { |o, v| define_singleton_method(o) { v } }
|
10
|
-
end
|
11
|
-
|
12
8
|
module ClassMethods
|
9
|
+
def inherited(subclass)
|
10
|
+
subclass.fields.concat(fields)
|
11
|
+
end
|
13
12
|
|
14
13
|
def fields
|
15
14
|
@fields ||= []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: field_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- EveryPolitician team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.5.
|
95
|
+
rubygems_version: 2.5.2
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Define a set of fields and serialize them to a hash.
|