lazy_resource 0.2.0 → 0.3.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.
- data/Gemfile +1 -0
- data/README.md +6 -0
- data/lib/lazy_resource/resource.rb +13 -1
- data/lib/lazy_resource/version.rb +1 -1
- data/spec/fixtures/user.rb +1 -0
- data/spec/lazy_resource/resource_spec.rb +23 -0
- metadata +3 -3
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -109,6 +109,12 @@ the version number. If you want to maintain your own version, go for it,
|
|
109
109
|
but put it in a separate commit so I can ignore it when I merge the rest
|
110
110
|
of your stuff in.
|
111
111
|
|
112
|
+
## It's alpha, yo
|
113
|
+
|
114
|
+
I'm not using this in production anywhere (yet), so use at your own
|
115
|
+
risk. It's got a pretty comprehensive test suite, but I'm sure there
|
116
|
+
are at least a few bugs. If you find one, [report it](https://github.com/ahlatimer/lazy_resource/issues).
|
117
|
+
|
112
118
|
## Recognition
|
113
119
|
|
114
120
|
Thanks to:
|
@@ -193,7 +193,19 @@ module LazyResource
|
|
193
193
|
elsif attribute_type.include?(LazyResource::Resource)
|
194
194
|
value = value.as_json
|
195
195
|
elsif attribute_type == DateTime
|
196
|
-
|
196
|
+
if options[:include_time_ago_in_words] && defined?(TwitterCldr)
|
197
|
+
hash[:"#{attribute_name}_in_words"] = (DateTime.now - (DateTime.now - value).to_f).localize.ago.to_s
|
198
|
+
end
|
199
|
+
|
200
|
+
if options[:strftime]
|
201
|
+
value = self.send(attribute_name).strftime(options[:strftime])
|
202
|
+
end
|
203
|
+
|
204
|
+
if options[attribute_name.to_sym] && options[attribute_name.to_sym][:strftime]
|
205
|
+
value = self.send(attribute_name).strftime(options[attribute_name.to_sym][:strftime])
|
206
|
+
end
|
207
|
+
|
208
|
+
value = value.to_s unless value.is_a?(String)
|
197
209
|
end
|
198
210
|
|
199
211
|
hash[attribute_name.to_sym] = value
|
data/spec/fixtures/user.rb
CHANGED
@@ -227,6 +227,29 @@ describe LazyResource::Resource do
|
|
227
227
|
user = User.load(params)
|
228
228
|
user.as_json.should == params
|
229
229
|
end
|
230
|
+
|
231
|
+
it 'converts dates to strings using the strftime parameter' do
|
232
|
+
params = { :id => 1, :created_at => DateTime.now }
|
233
|
+
user = User.load(params)
|
234
|
+
params[:created_at] = params[:created_at].strftime("%D")
|
235
|
+
user.as_json(:strftime => '%D').should == params
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'converts dates to strings for the passed parameter' do
|
239
|
+
params = { :id => 1, :created_at => DateTime.now.to_s, :updated_at => DateTime.now }
|
240
|
+
user = User.load(params)
|
241
|
+
params[:updated_at] = params[:updated_at].strftime("%D")
|
242
|
+
user.as_json(:updated_at => { :strftime => "%D" }).should == params
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'adds a _in_words for datetimes when include_time_ago_in_words option is set' do
|
246
|
+
require 'twitter_cldr'
|
247
|
+
|
248
|
+
params = { :id => 1, :created_at => DateTime.now.to_s }
|
249
|
+
user = User.load(params)
|
250
|
+
params[:created_at_in_words] = "1 second ago"
|
251
|
+
user.as_json(:include_time_ago_in_words => true).should == params
|
252
|
+
end
|
230
253
|
end
|
231
254
|
|
232
255
|
describe '.find' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: -2886530034829089377
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
segments:
|
143
143
|
- 0
|
144
|
-
hash:
|
144
|
+
hash: -2886530034829089377
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
147
|
rubygems_version: 1.8.24
|