frenchy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frenchy/model.rb +12 -4
- data/lib/frenchy/version.rb +1 -1
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 931d5b6b257afcf71c97aa158f1cbed36e466991
|
4
|
+
data.tar.gz: 764c993fcab9b80d3960a9fb76b7c56abd833f04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44b3e312031783089e903ad9729b8bbd3c3a867ae5275a03db61d046e4f6c8e99267aff95eea23fa0e66faffaf7812f4531f9defbbf3488b538a6d5981e0aef3
|
7
|
+
data.tar.gz: 9375a0660f5a6f60100e5f513b6cfa67ace92dbdd3776344d484b0bd9387dc9f87645a1423f93859e56bef936572170bd19360b2d5dff990ff40e04e504db798
|
data/lib/frenchy/model.rb
CHANGED
@@ -2,9 +2,10 @@ module Frenchy
|
|
2
2
|
module Model
|
3
3
|
def self.included(base)
|
4
4
|
base.class_eval do
|
5
|
-
cattr_accessor :fields
|
5
|
+
cattr_accessor :fields, :defaults
|
6
6
|
|
7
7
|
self.fields = {}
|
8
|
+
self.defaults = {}
|
8
9
|
end
|
9
10
|
|
10
11
|
base.extend(ClassMethods)
|
@@ -12,7 +13,7 @@ module Frenchy
|
|
12
13
|
|
13
14
|
# Create a new instance of this model with the given attributes
|
14
15
|
def initialize(attrs={})
|
15
|
-
attrs.each do |k,v|
|
16
|
+
self.class.defaults.merge(attrs).each do |k,v|
|
16
17
|
if self.class.fields[k.to_sym]
|
17
18
|
send("#{k}=", v)
|
18
19
|
end
|
@@ -80,11 +81,11 @@ module Frenchy
|
|
80
81
|
end
|
81
82
|
when :integer
|
82
83
|
define_method("#{name}=") do |v|
|
83
|
-
set(name, v
|
84
|
+
set(name, Integer(v), options)
|
84
85
|
end
|
85
86
|
when :float
|
86
87
|
define_method("#{name}=") do |v|
|
87
|
-
set(name, v
|
88
|
+
set(name, Float(v), options)
|
88
89
|
end
|
89
90
|
when :bool
|
90
91
|
define_method("#{name}=") do |v|
|
@@ -102,10 +103,12 @@ module Frenchy
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
when :array
|
106
|
+
options[:default] ||= []
|
105
107
|
define_method("#{name}=") do |v|
|
106
108
|
set(name, Array(v), options)
|
107
109
|
end
|
108
110
|
when :hash
|
111
|
+
options[:default] ||= {}
|
109
112
|
define_method("#{name}=") do |v|
|
110
113
|
set(name, Hash[v], options)
|
111
114
|
end
|
@@ -116,6 +119,7 @@ module Frenchy
|
|
116
119
|
|
117
120
|
define_method("#{name}=") do |v|
|
118
121
|
if options[:many]
|
122
|
+
options[:default] ||= []
|
119
123
|
set(name, Frenchy::Collection.new(Array(v).map {|vv| klass.new(vv)}))
|
120
124
|
else
|
121
125
|
set(name, klass.new(v))
|
@@ -125,6 +129,10 @@ module Frenchy
|
|
125
129
|
|
126
130
|
self.fields[name.to_sym] = options
|
127
131
|
|
132
|
+
if options[:default]
|
133
|
+
self.defaults[name.to_sym] = options[:default]
|
134
|
+
end
|
135
|
+
|
128
136
|
attr_reader name.to_sym
|
129
137
|
end
|
130
138
|
end
|
data/lib/frenchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frenchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Coene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '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
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: http
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Frenchy's got the goods
|
@@ -115,7 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .gitignore
|
118
|
+
- ".gitignore"
|
119
119
|
- Gemfile
|
120
120
|
- LICENSE.txt
|
121
121
|
- README.md
|
@@ -140,17 +140,17 @@ require_paths:
|
|
140
140
|
- lib
|
141
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
|
-
- -
|
148
|
+
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.0
|
153
|
+
rubygems_version: 2.2.0
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Frenchy's got the goods
|