hashme 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +24 -0
- data/Gemfile.activemodel-4.x +4 -0
- data/Gemfile.activemodel-5.x +4 -0
- data/README.md +11 -4
- data/Rakefile +6 -0
- data/hashme.gemspec +1 -1
- data/lib/hashme/property.rb +6 -1
- data/lib/hashme/property_casting.rb +1 -1
- data/lib/hashme/version.rb +1 -1
- data/spec/hashme/property_casting_spec.rb +13 -1
- data/spec/hashme/property_spec.rb +5 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f50c8f90a959db106926caadbdaee800ed55073
|
4
|
+
data.tar.gz: 422d08c967c35172445489d6716b1a799f53b299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417b46455a892130eb7e4b8781dccfa7530ac10cf93d656863c78d3ebc5b59a2f81b8378acc9736944bd25062f37c65eb475ce8522b8af961b888802300318dd
|
7
|
+
data.tar.gz: 0c8c5cd1b21333070e76c6e74f9c40095c4f48117086a72be98f61db7a0201f79cfb83ac5c3468e8ebaf6bf5d52e093bc5bb88671af8a08c737bd72b8feba15b
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
gemfile:
|
3
|
+
- Gemfile.activemodel-4.x
|
4
|
+
- Gemfile.activemodel-5.x
|
5
|
+
rvm:
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1.10
|
8
|
+
- 2.2.4
|
9
|
+
- 2.3.0
|
10
|
+
- jruby
|
11
|
+
- rbx
|
12
|
+
before_install:
|
13
|
+
- gem install bundler
|
14
|
+
env:
|
15
|
+
- JRUBY_OPTS=--2.0
|
16
|
+
matrix:
|
17
|
+
allow_failures:
|
18
|
+
- rvm: rbx # Sorry, don't have time for these failures!
|
19
|
+
- rvm: 2.0.0
|
20
|
+
gemfile: Gemfile.activemodel-5.x
|
21
|
+
- rvm: 2.1.10
|
22
|
+
gemfile: Gemfile.activemodel-5.x
|
23
|
+
- rvm: jruby
|
24
|
+
gemfile: Gemfile.activemodel-5.x
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# Hashme
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/samlown/hashme.png)](https://travis-ci.org/samlown/hashme)
|
4
|
+
|
3
5
|
Hashes are great, but sometimes you need a bit more structure.
|
4
6
|
|
5
7
|
Hashme helps you create simple models that allow you to initialize and
|
6
8
|
generate hashes that you can serialize and store as you wish.
|
7
9
|
|
8
10
|
Its a bit like ActiveRecord, but without all the messy database stuff,
|
9
|
-
and of course you can nest to you're heart's content.
|
11
|
+
and of course you can nest models to you're heart's content.
|
10
12
|
|
11
13
|
A few situations where you might find Hashme useful:
|
12
14
|
|
@@ -69,13 +71,13 @@ class Kennel
|
|
69
71
|
end
|
70
72
|
|
71
73
|
# Build a kennel
|
72
|
-
kennel = Kennel.new(:name => "Goaway Kitty Home", :location => Point.new(40.333,-3.4555))
|
74
|
+
kennel = Kennel.new(:name => "Goaway Kitty Home", :location => Point.new(40.333,-3.4555), :cats => [])
|
73
75
|
|
74
76
|
# Add a kitten using an object
|
75
|
-
kennel << kitty
|
77
|
+
kennel.cats << kitty
|
76
78
|
|
77
79
|
# Add a new cat using a raw hash
|
78
|
-
kennel << {
|
80
|
+
kennel.cats << {
|
79
81
|
:name => "Felix",
|
80
82
|
:description => "Black and white"
|
81
83
|
}
|
@@ -118,6 +120,11 @@ u.errors.first # [:email, "can't be blank"]
|
|
118
120
|
|
119
121
|
## History
|
120
122
|
|
123
|
+
### 0.2.6 - 2017-09-12
|
124
|
+
|
125
|
+
* Setting ActiveModel minimum to 4.0, adding travis config to test both 4.0 and 5.0. (@samlown)
|
126
|
+
* Adding support for using `Proc` type as default values for properties (@apoloval)
|
127
|
+
|
121
128
|
### 0.2.5 - 2016-06-03 - Again!
|
122
129
|
|
123
130
|
* Adding support for deleting attributes by setting them to nil to keep output clean.
|
data/Rakefile
CHANGED
data/hashme.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activemodel", ">=
|
21
|
+
spec.add_dependency "activemodel", ">= 4.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
data/lib/hashme/property.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Hashme
|
2
2
|
class Property
|
3
3
|
|
4
|
-
attr_reader :name, :type, :
|
4
|
+
attr_reader :name, :type, :array
|
5
5
|
|
6
6
|
def initialize(name, type, opts = {})
|
7
7
|
@name = name.to_sym
|
@@ -27,6 +27,11 @@ module Hashme
|
|
27
27
|
name
|
28
28
|
end
|
29
29
|
|
30
|
+
def default
|
31
|
+
return @default.call if @default.is_a?(Proc)
|
32
|
+
@default
|
33
|
+
end
|
34
|
+
|
30
35
|
# Build a new object of the type defined by the property.
|
31
36
|
def build(owner, value)
|
32
37
|
if array && value.is_a?(Array)
|
@@ -103,7 +103,7 @@ module Hashme
|
|
103
103
|
typecast_hash_to_date(value)
|
104
104
|
elsif value.is_a?(Time) # sometimes people think date is time!
|
105
105
|
value.to_date
|
106
|
-
elsif value.to_s =~
|
106
|
+
elsif value.to_s =~ /ˆ(\d{4})[\-|\/](\d{2})[\-|\/](\d{2})$/
|
107
107
|
# Faster than parsing the date
|
108
108
|
Date.new($1.to_i, $2.to_i, $3.to_i)
|
109
109
|
else
|
data/lib/hashme/version.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class Course
|
4
4
|
include Hashme
|
5
|
-
|
5
|
+
|
6
6
|
property :title, String
|
7
7
|
property :participants, [Object]
|
8
8
|
property :ends_at, Time
|
@@ -507,6 +507,18 @@ describe Hashme::PropertyCasting do
|
|
507
507
|
expect(course.started_on.day).to eql(20)
|
508
508
|
expect(course.started_on.year).to eql(2006)
|
509
509
|
end
|
510
|
+
|
511
|
+
it 'parses date with wrong formatted year (ensure consider the beginning of string)' do
|
512
|
+
course.started_on = 'abc02016-10-03'
|
513
|
+
expect(course['started_on'].month).to eql(10)
|
514
|
+
expect(course['started_on'].day).to eql(03)
|
515
|
+
expect(course['started_on'].year).to eql(2016)
|
516
|
+
end
|
517
|
+
|
518
|
+
it 'does not typecast wrongly formatted dates (ensure consider the end of string)' do
|
519
|
+
course.started_on = '2016-10-030'
|
520
|
+
expect(course['started_on']).to be_nil
|
521
|
+
end
|
510
522
|
end
|
511
523
|
|
512
524
|
it 'does not typecast non-date values' do
|
@@ -36,6 +36,11 @@ describe Hashme::Property do
|
|
36
36
|
prop = subject.new(:name, String, :default => "Freddo")
|
37
37
|
expect(prop.default).to eql("Freddo")
|
38
38
|
end
|
39
|
+
|
40
|
+
it "should accept a default option from a Proc" do
|
41
|
+
prop = subject.new(:name, String, :default => -> { "Freddo" })
|
42
|
+
expect(prop.default).to eql("Freddo")
|
43
|
+
end
|
39
44
|
end
|
40
45
|
|
41
46
|
describe "#to_s" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Lown
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +75,10 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rspec"
|
78
|
+
- ".travis.yml"
|
78
79
|
- Gemfile
|
80
|
+
- Gemfile.activemodel-4.x
|
81
|
+
- Gemfile.activemodel-5.x
|
79
82
|
- LICENSE.txt
|
80
83
|
- README.md
|
81
84
|
- Rakefile
|
@@ -117,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
120
|
version: '0'
|
118
121
|
requirements: []
|
119
122
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.6.8
|
121
124
|
signing_key:
|
122
125
|
specification_version: 4
|
123
126
|
summary: Easily define simple models that can be easily serialized and de-serialized.
|