Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 57 lines (42 sloc) 1.739 kB
911ace9 @jnunemaker Added readme.
authored
1 = Scam
2
3 Really basic model-ish thing for creating different types in your application easily.
4
5 I use this whenever I want something to do psuedo belongs to/has many relationships, but do not want to back a model with a database as the data does not change often, if ever.
6
7 == Usage
8
9 Just create a class and include scam.
10
11 class FeedTemplate
12 include Scam
13
14 attr_accessor :title, :icon, :instructions, :template, :format, :label
15
16 def expand(value)
17 url = template.gsub('{value}', URI.escape(value))
18 url = "http://#{url}" if url !~ /https?\:\/\//
19 url
20 end
21
22 def parse(body)
23 case format
24 when 'json'
25 ActiveSupport::JSON.decode(body)
26 when 'feed'
27 Feedzirra::Feed.parse(body).to_hash
28 end
29 end
30 end
31
32 FeedTemplate.create({
33 :id => 1,
34 :title => 'Twitter',
35 :label => 'Twitter Username',
36 :icon => 'twitter',
37 :instructions => 'Enter your Twitter username',
38 :format => 'json',
39 :template => 'http://twitter.com/statuses/user_timeline/{value}.json',
40 })
41
42 Attributes are just defined using attr_accessor. :id is added when you include Scam.
43
44 == Note on Patches/Pull Requests
45
46 * Fork the project.
47 * Make your feature addition or bug fix.
48 * Add tests for it. This is important so I don't break it in a
49 future version unintentionally.
50 * Commit, do not mess with rakefile, version, or history.
51 (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
52 * Send me a pull request. Bonus points for topic branches.
53
54 == Copyright
55
56 Copyright (c) 2010 John Nunemaker. See LICENSE for details.
Something went wrong with that request. Please try again.