active-redis 0.0.1

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.
Files changed (3) hide show
  1. data/lib/active-redis.rb +39 -0
  2. data/readme.md +107 -0
  3. metadata +69 -0
@@ -0,0 +1,39 @@
1
+ class ActiveRedis
2
+
3
+ include DataMapper::Resource
4
+
5
+ property :id, Serial
6
+
7
+ def to_param
8
+ id.to_s
9
+ end
10
+
11
+ def self.find_by_param_name(param_name)
12
+ first(:param_name => param_name)
13
+ end
14
+
15
+ def find(args)
16
+ get(args)
17
+ end
18
+
19
+ def self.model_name
20
+ @_model_name ||= ActiveModel::Name.new(self)
21
+ end
22
+
23
+ def to_key
24
+ new? ? nil : [id]
25
+ end
26
+
27
+ def persisted?
28
+ new? ? false : true
29
+ end
30
+
31
+ def self.parse_date_time(hash)
32
+ datetime = DateTime.new(hash["datetime(1i)"].to_i, hash['datetime(2i)'].to_i, hash['datetime(3i)'].to_i, hash["datetime(4i)"].to_i, hash["datetime(5i)"].to_i)
33
+ end
34
+
35
+ def to_s
36
+ self.id
37
+ end
38
+
39
+ end
@@ -0,0 +1,107 @@
1
+ # Active Redis
2
+
3
+ Active Redis is a helper class, that helps you use rails helpers with [Datamapper](http://datamapper.org/) on top of the [Datamapper Redis](https://github.com/arbarlow/dm-redis-adapter) adapter.
4
+
5
+ With this gem, you can easily have Redis in Rails and still user form_for and the path_helpers and pretty much everything else..
6
+
7
+
8
+ # Installing
9
+
10
+ There are some dependencies, heres a gem file for a typical app.
11
+ Note the use of my git repo's as they contain certain patches to get it all working
12
+
13
+ source 'http://rubygems.org'
14
+
15
+ gem 'rails'
16
+ gem 'mongrel', '>= 1.2.0.pre2'
17
+
18
+ gem 'dm-core', '~> 1.0.2'
19
+ gem 'dm-redis-adapter', :git => "git@github.com:arbarlow/dm-redis-adapter.git"
20
+ gem 'dm-serializer', '~> 1.0.2'
21
+ gem 'dm-timestamps', '~> 1.0.2'
22
+ gem 'dm-validations', '~> 1.0.2'
23
+ gem 'dm-devise', '~> 1.1.4'
24
+
25
+ gem 'active-redis', :git => "git@github.com:arbarlow/active-redis.git"
26
+ gem "dm-paperclip", :git => "git@github.com:arbarlow/dm-paperclip.git"
27
+ gem 's3'
28
+
29
+ You need an initialiser that looks like this...
30
+
31
+ DataMapper.setup(:default, {:adapter => "redis"})
32
+
33
+ I suggest you now read [Datamapper](http://datamapper.org/) and the [Datamapper Redis](https://github.com/arbarlow/dm-redis-adapter) docs, to see about finds etc.
34
+
35
+
36
+ # Compatibility
37
+
38
+ Thats right, you've guessed it, this can work with devise and paperclip and s3! Its all there. Please do write more.
39
+
40
+ # Usage
41
+
42
+ A typical model in rails might look like this...
43
+
44
+ class Post < ActiveRedis
45
+
46
+ belongs_to :user
47
+
48
+ has n, :comments
49
+
50
+ property :param_name, String, :index => true
51
+ property :title, String
52
+ property :body, Text
53
+ property :created_at, DateTime
54
+
55
+ end
56
+
57
+ This would give you URL's like '/posts/1' to get pretty URL's add the following to your model..
58
+
59
+ before :save, :create_param_name
60
+
61
+ def create_param_name
62
+ self.param_name = self.title.parameterize
63
+ true
64
+ end
65
+
66
+ def to_param
67
+ param_name
68
+ end
69
+
70
+
71
+ # Paperclip
72
+
73
+ As promised, paperclip goodness, using my port of the gem, it also works in 1.9.2 and using the s3 gem means, European buckets!
74
+
75
+ In an initialiser, configure paperclip..
76
+
77
+ Paperclip.configure do |config|
78
+ config.root = Rails.root # the application root to anchor relative urls (defaults to Dir.pwd)
79
+ config.env = Rails.env # server env support, defaults to ENV['RACK_ENV'] or 'development'
80
+ #config.use_dm_validations = true # validate attachment sizes and such, defaults to false
81
+ #config.processors_path = 'lib/pc' # relative path to look for processors, defaults to 'lib/paperclip_processors'
82
+ end
83
+
84
+ And then in your model
85
+
86
+ include Paperclip::Resource
87
+
88
+ has_attached_file :picture, :styles => { :medium => "300x300>", :thumb => "100x100>" },
89
+ :storage => :s3,
90
+ :s3_credentials => "#{Rails.root.to_s}/config/aws.yml",
91
+ :path => "posts/:id/:style.:extension",
92
+ :default_url => "/paperclips/posts/:style/missing.png"
93
+
94
+ You can either use file storage, or the aws/s3 gem, or the s3 gem, which will let you use European buckets..
95
+
96
+ To use the s3 gem with your application, you need to have an initialiser which attaches the s3 gem to paperclip
97
+
98
+ You can get this here [Paperclip S3](https://github.com/arbarlow/paperclip-s3). Put this in an initialiser..
99
+
100
+
101
+ # Devise
102
+
103
+ Yup, authenticate via Redis.
104
+
105
+ Firstly. Make a database.yml. But just put some rubbish in there. Its not needed, but [Datamapper Devise](https://github.com/jm81/dm-devise) needs one to run the generator.
106
+ Follow the usual devise steps and your good to go!
107
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active-redis
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Alex Barlow
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-13 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Easy datamapper methods to use redis in rails
23
+ email:
24
+ - alexbarlowis@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - lib/active-redis.rb
33
+ - readme.md
34
+ has_rdoc: true
35
+ homepage: https://github.com/arbarlow/active-redis
36
+ licenses:
37
+ - ISC
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Easy datamapper methods to use redis in rails
68
+ test_files: []
69
+