hashie_data_mapper 0.1.5
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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +43 -0
- data/Rakefile +12 -0
- data/hashie_data_mapper.gemspec +26 -0
- data/lib/hashie_data_mapper.rb +5 -0
- data/lib/hashie_data_mapper/ignore_undeclared.rb +39 -0
- data/lib/hashie_data_mapper/version.rb +3 -0
- data/spec/hashie_data_mapper/ignore_undeclared_spec.rb +23 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +12 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cfe88cf5412623f0cb73c54a4fcf7dd19afdeee
|
4
|
+
data.tar.gz: cfe7dfef8878e68ad4c07616304c73615aa1c9f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37f6d74ff2890b0aeffca74c3fe296f213af8a0f388c79702170788507da2c4af093078a207107e1363ebb873f0fd3210607ed257369905b6c64d8657f80e6d4
|
7
|
+
data.tar.gz: 2caad4b695c35b2f3d07576ac690ee6ecd259029a44b22cb3f9cca27d78e4f6a715a3d8ead2b2342d400d833095af703e84d0b3d70274dbe7a3e22825dc13d2d
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
.idea
|
15
|
+
.ruby-gemset
|
16
|
+
.ruby-version
|
17
|
+
Gemfile.lock
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Michael Amor Righi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Hashie Data Mapper [](https://travis-ci.org/righi/hashie_data_mapper) [](https://gemnasium.com/righi/hashie_data_mapper)
|
2
|
+
==================
|
3
|
+
|
4
|
+
An extension to the Hashie Ruby Gem for Working with Data Mappers.
|
5
|
+
|
6
|
+
This is hopefully just a temporary project, pending the merge into
|
7
|
+
Hashie of this pull request: https://github.com/intridea/hashie/pull/131
|
8
|
+
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
Add this to your Gemfile:
|
14
|
+
|
15
|
+
gem 'hashie_data_mapper', '~> 0.1.4'
|
16
|
+
|
17
|
+
|
18
|
+
Usage
|
19
|
+
-----
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'hashie'
|
23
|
+
require 'hashie_data_mapper'
|
24
|
+
|
25
|
+
class Person < Trash
|
26
|
+
include HashieDataMapper::IgnoreUndeclared
|
27
|
+
|
28
|
+
property :first_name
|
29
|
+
property :last_name
|
30
|
+
end
|
31
|
+
|
32
|
+
user_data = {
|
33
|
+
:first_name => 'Freddy',
|
34
|
+
:last_name => 'Nostrils',
|
35
|
+
:email => 'freddy@example.com'
|
36
|
+
}
|
37
|
+
|
38
|
+
p = Person.new(user_data) # 'email' is silently ignored
|
39
|
+
|
40
|
+
p.first_name # => 'Freddy'
|
41
|
+
p.last_name # => 'Nostrils'
|
42
|
+
p.email # => NoMethodError
|
43
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'hashie_data_mapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hashie_data_mapper"
|
8
|
+
spec.version = HashieDataMapper::VERSION
|
9
|
+
spec.authors = ["Michael Amor Righi"]
|
10
|
+
spec.email = ["michael@righi.me"]
|
11
|
+
spec.description = %q{Extensions to make Hashie more ideal for building data mappers}
|
12
|
+
spec.summary = %q{Hashie for data mappers}
|
13
|
+
spec.homepage = 'https://github.com/righi/hashie_data_mapper'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency 'rake', '~> 0.9.2'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.5'
|
24
|
+
|
25
|
+
spec.add_dependency 'hashie', '>= 1.2.0'
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module HashieDataMapper
|
2
|
+
# IgnoreUndeclared is a simple mixin that silently ignores
|
3
|
+
# undeclared properties on initialization instead of
|
4
|
+
# raising an error. This is useful when using a Trash to
|
5
|
+
# capture a subset of a larger hash.
|
6
|
+
#
|
7
|
+
# Note that attempting to retrieve an undeclared property
|
8
|
+
# will still raise a NoMethodError, even if a value for
|
9
|
+
# that property was provided at initialization.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# class Person < Trash
|
13
|
+
# include HashieDataMapper::IgnoreUndeclared
|
14
|
+
#
|
15
|
+
# property :first_name
|
16
|
+
# property :last_name
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# user_data = {
|
20
|
+
# :first_name => 'Freddy',
|
21
|
+
# :last_name => 'Nostrils',
|
22
|
+
# :email => 'freddy@example.com'
|
23
|
+
# }
|
24
|
+
#
|
25
|
+
# p = Person.new(user_data) # 'email' is silently ignored
|
26
|
+
#
|
27
|
+
# p.first_name # => 'Freddy'
|
28
|
+
# p.last_name # => 'Nostrils'
|
29
|
+
# p.email # => NoMethodError
|
30
|
+
module IgnoreUndeclared
|
31
|
+
def initialize_attributes(attributes)
|
32
|
+
attributes.each_pair do |att, value|
|
33
|
+
if self.class.property?(att) || (self.class.respond_to?(:translations) && self.class.translations.include?(att.to_sym))
|
34
|
+
self[att] = value
|
35
|
+
end
|
36
|
+
end if attributes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HashieDataMapper::IgnoreUndeclared do
|
4
|
+
class ForgivingTrash < Hashie::Trash
|
5
|
+
include HashieDataMapper::IgnoreUndeclared
|
6
|
+
property :city
|
7
|
+
property :state, :from => :provence
|
8
|
+
end
|
9
|
+
|
10
|
+
subject{ ForgivingTrash }
|
11
|
+
|
12
|
+
it 'should silently ignore undeclared properties on initialization' do
|
13
|
+
expect{ subject.new(:city => 'Toronto', :provence => 'ON', :country => 'Canada') }.to_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should work with translated properties (with symbol keys)' do
|
17
|
+
expect(subject.new(:provence => 'Ontario').state).to eq('Ontario')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should work with translated properties (with string keys)' do
|
21
|
+
expect(subject.new('provence' => 'Ontario').state).to eq('Ontario')
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hashie_data_mapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Amor Righi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-07 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
description: Extensions to make Hashie more ideal for building data mappers
|
70
|
+
email:
|
71
|
+
- michael@righi.me
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- hashie_data_mapper.gemspec
|
85
|
+
- lib/hashie_data_mapper.rb
|
86
|
+
- lib/hashie_data_mapper/ignore_undeclared.rb
|
87
|
+
- lib/hashie_data_mapper/version.rb
|
88
|
+
- spec/hashie_data_mapper/ignore_undeclared_spec.rb
|
89
|
+
- spec/spec.opts
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/righi/hashie_data_mapper
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.0
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Hashie for data mappers
|
115
|
+
test_files:
|
116
|
+
- spec/hashie_data_mapper/ignore_undeclared_spec.rb
|
117
|
+
- spec/spec.opts
|
118
|
+
- spec/spec_helper.rb
|