ohm-find_by 0.0.2

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 (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +36 -0
  3. data/lib/ohm/find_by.rb +22 -0
  4. metadata +69 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bruno Aguirre
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ = ohm-find_by
2
+
3
+ This is just a fast implementation of AR find_by_{attr} for Ohm
4
+
5
+ class Post < Ohm::Model
6
+ attribute :name
7
+ attribute :author
8
+
9
+ index :name
10
+ end
11
+
12
+ With that Ohm::Model in mind now you can do this:
13
+
14
+ Post.create :name => "My first Post", :author => "elCuervo"
15
+ => #<Post:1 name="My first Post" author="elCuervo">
16
+ Post.find_by_name "My first Post"
17
+ => #<Set (Post): ["1"]>
18
+
19
+ Also checks the existence of the index before searching so:
20
+
21
+ Post.find_by_author "elCuervo"
22
+ => Ohm::Model::IndexNotFound
23
+
24
+ == Note on Patches/Pull Requests
25
+
26
+ * Fork the project.
27
+ * Make your feature addition or bug fix.
28
+ * Add tests for it. This is important so I don't break it in a
29
+ future version unintentionally.
30
+ * Commit, do not mess with rakefile, version, or history.
31
+ (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)
32
+ * Send me a pull request. Bonus points for topic branches.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2010 Bruno Aguirre. See LICENSE for details.
@@ -0,0 +1,22 @@
1
+ module Ohm
2
+ class Model
3
+ FIND_BY_METHOD = /^find_by_/
4
+
5
+ def self.method_missing(method, *args, &block)
6
+ if method.to_s =~ FIND_BY_METHOD
7
+ index = method.to_s[8..-1].to_sym
8
+ raise(IndexNotFound, index) unless self.indices.include?(index)
9
+ self.find(index => args)
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def self.respond_to?(method)
16
+ return true if method =~ FIND_BY_METHOD
17
+ super
18
+ end
19
+
20
+ end
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohm-find_by
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - elcuervo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-06 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ohm
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: A simple way of having a find_by implementation in Ohm
28
+ email:
29
+ - yo@brunoaguirre.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - LICENSE
38
+ - README.md
39
+ - lib/ohm/find_by.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/elcuervo/ohm-find_by
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.6.2
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: find_by AR style to Ohm
68
+ test_files: []
69
+