has_delegates 0.5.3

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/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2006 Sean Carley <http://sean-carley.blogspot.com>
2
+ Copyright (c) 2009 Simon Hürlimann <simon.huerlimann@cyt.ch>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,16 @@
1
+ has_delegates
2
+ =============
3
+
4
+ Rails plugin providing VCard like contact and address models and helpers.
5
+
6
+ Based on code described at
7
+ http://sean-carley.blogspot.com/2006/09/activerecord-delegation-and-demeter.html
8
+
9
+ License
10
+ =======
11
+
12
+ Copyright (c) 2006 Sean Carley <http://sean-carley.blogspot.com>
13
+ Copyright (c) 2009-2010 Simon Hürlimann <simon.huerlimann@cyt.ch>
14
+ Copyright (c) 2009-2010 ZytoLabor <http://www.zyto-labor.com>
15
+
16
+ Released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ begin
7
+ GEM = "has_delegates"
8
+ AUTHOR = "Simon Hürlimann"
9
+ EMAIL = "simon.huerlimann@cyt.ch"
10
+ SUMMARY = "Rails plugin providing VCard like contact and address models and helpers."
11
+ HOMEPAGE = "http://github.com/huerlisi/has_delegates/tree/master"
12
+
13
+ gem 'jeweler', '>= 1.0.0'
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |s|
17
+ s.name = GEM
18
+ s.summary = SUMMARY
19
+ s.email = EMAIL
20
+ s.homepage = HOMEPAGE
21
+ s.description = SUMMARY
22
+ s.author = AUTHOR
23
+
24
+ s.require_path = 'lib'
25
+ s.files = %w(MIT-LICENSE README Rakefile) + Dir.glob("{lib,test,rails}/**/*")
26
+
27
+ # Runtime dependencies: When installing has_delegates these will be checked if they are installed.
28
+ # Will be offered to install these if they are not already installed.
29
+ s.add_dependency 'activesupport', '>= 2.3.0'
30
+ s.add_dependency 'actionpack', '>= 2.3.0'
31
+ end
32
+
33
+ Jeweler::GemcutterTasks.new
34
+ rescue LoadError
35
+ puts "[has_delegates:] Jeweler - or one of its dependencies - is not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
36
+ end
37
+
38
+ desc 'Default: run unit tests.'
39
+ task :default => :test
40
+
41
+ desc 'Test the has_delegates plugin.'
42
+ Rake::TestTask.new(:test) do |t|
43
+ t.libs << 'lib'
44
+ t.pattern = 'test/**/*_test.rb'
45
+ t.verbose = true
46
+ end
47
+
48
+ desc 'Generate documentation for the has_delegates plugin.'
49
+ Rake::RDocTask.new(:rdoc) do |rdoc|
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = 'HasDelegates'
52
+ rdoc.options << '--line-numbers' << '--inline-source'
53
+ rdoc.rdoc_files.include('README')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
@@ -0,0 +1,58 @@
1
+ # HasDelegates
2
+ module HasDelegates
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def belongs_to_delegate(delegate_id, options = {})
9
+ delegate_to(:belongs_to, delegate_id, options)
10
+ end
11
+
12
+ def has_one_delegate(delegate_id, options = {})
13
+ delegate_to(:has_one, delegate_id, options)
14
+ end
15
+
16
+ private
17
+
18
+ def delegate_to(macro, delegate_id, options = {})
19
+ send macro, delegate_id, options
20
+
21
+ save_callback = {:belongs_to => :before_save, :has_one => :after_save}[macro]
22
+
23
+ send save_callback do |model|
24
+ model.send(delegate_id).save
25
+ end
26
+
27
+ delegate_names = respond_to?('safe_delegate_names') ? safe_delegate_names : []
28
+ delegate_names = (delegate_names - [delegate_id]) + [delegate_id]
29
+
30
+ def_string, source_file, source_line = <<-"end_eval", __FILE__, __LINE__
31
+
32
+ def self.safe_delegate_names
33
+ #{delegate_names.inspect}
34
+ end
35
+
36
+ def safe_delegates
37
+ self.class.safe_delegate_names.collect do |delegate_name|
38
+ send(delegate_name).nil? ? send("build_\#{delegate_name}") : send(delegate_name)
39
+ end
40
+ end
41
+
42
+ def method_missing(method_id, *args)
43
+ safe_delegates.each do |delegate|
44
+ return delegate.send(method_id, *args) if delegate.respond_to?(method_id)
45
+ end
46
+ super
47
+ end
48
+
49
+ def respond_to?(*args)
50
+ safe_delegates.any? {|delegate| delegate.respond_to?(*args)} || super
51
+ end
52
+
53
+ end_eval
54
+
55
+ module_eval def_string, source_file, source_line + 1
56
+ end
57
+ end
58
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Include hook code here
2
+ require 'active_record'
3
+ require 'has_delegates'
4
+
5
+ ActiveRecord::Base.send(:include, HasDelegates)
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class HasDelegatesTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_delegates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
+ platform: ruby
6
+ authors:
7
+ - "Simon H\xC3\xBCrlimann"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-07-18 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: actionpack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ version:
35
+ description: Rails plugin providing VCard like contact and address models and helpers.
36
+ email: simon.huerlimann@cyt.ch
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ files:
44
+ - MIT-LICENSE
45
+ - README
46
+ - Rakefile
47
+ - lib/has_delegates.rb
48
+ - rails/init.rb
49
+ - test/has_delegates_test.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/huerlisi/has_delegates/tree/master
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Rails plugin providing VCard like contact and address models and helpers.
78
+ test_files:
79
+ - test/has_delegates_test.rb