johnsbrn-classy-inheritance 0.6.3 → 0.6.3.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.
data/Manifest.txt CHANGED
@@ -1,26 +1,12 @@
1
1
  History.txt
2
2
  License.txt
3
3
  Manifest.txt
4
- PostInstall.txt
5
- README
6
4
  README.txt
7
5
  Rakefile
8
- config/hoe.rb
9
- config/requirements.rb
10
6
  lib/classy-inheritance.rb
11
- lib/classy-inheritance/version.rb
12
- script/console
13
- script/destroy
14
- script/generate
15
- script/txt2html
16
- setup.rb
17
- tasks/deployment.rake
18
- tasks/environment.rake
19
- tasks/website.rake
20
7
  test/test_classy-inheritance.rb
21
8
  test/test_helper.rb
22
- website/index.html
23
- website/index.txt
24
- website/javascripts/rounded_corners_lite.inc.js
25
- website/stylesheets/screen.css
26
- website/template.html.erb
9
+ test/test_polymorphic_associations.rb
10
+ test/test_with_optional_dependency.rb
11
+ test/test_with_prefix_postfix.rb
12
+ test/test_with_standard_attributes.rb
data/README.txt CHANGED
@@ -1,32 +1,37 @@
1
- = classy-inheritance
2
-
3
- * FIX (url)
1
+ classy-inheritance
2
+ by Andrew Stone
3
+ http://stonean.com
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- FIX (describe your package)
8
-
9
- == FEATURES/PROBLEMS:
7
+ Classy Inheritance adds a depends_on class method to your ActiveRecord model so that you can define requisite objects.
10
8
 
11
- * FIX (list of features or problems)
9
+ This functionality is provided using the existing ActiveRecord methods without monkey patching any core code. Essentially, it provides an easy interface to generate code that anyone could add to their model to receive the same result. Depending on the parameters to your depends_on call, it may add some of the following methods: validates_presence_of, validates_associated, has_one or belongs_to.
12
10
 
13
11
  == SYNOPSIS:
14
12
 
15
- FIX (code sample of usage)
13
+ class User < ActiveRecord::Base
14
+ depends_on :profile, :attrs => [:first_name, :last_name, :email]
15
+ end
16
16
 
17
- == REQUIREMENTS:
17
+ # Pass-through methods to profile attributes. Now you don't have to manage
18
+ # two different objects.
19
+ @user.first_name = 'Andrew'
20
+ @user.last_name = 'Stone'
21
+ @user.email = 'andy@stonean.com'
18
22
 
19
- * FIX (list of requirements)
23
+ # Manages profile relationship for you
24
+ @user.save
20
25
 
21
26
  == INSTALL:
22
27
 
23
- * FIX (sudo gem install, anything else)
28
+ sudo gem install classy-inheritance
24
29
 
25
30
  == LICENSE:
26
31
 
27
32
  (The MIT License)
28
33
 
29
- Copyright (c) 2008 FIX
34
+ Copyright (c) 2009 Andrew Stone
30
35
 
31
36
  Permission is hereby granted, free of charge, to any person obtaining
32
37
  a copy of this software and associated documentation files (the
@@ -45,4 +50,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
50
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
51
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
52
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,4 +1,30 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
-
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'classy-inheritance'
18
+
19
+ task :default => 'spec:run'
20
+
21
+ PROJ.name = 'classy-inheritance'
22
+ PROJ.authors = 'Andrew Stone'
23
+ PROJ.email = 'andy@stonean.com'
24
+ PROJ.url = 'http://stonean.com/wiki/classy-inheritance'
25
+ PROJ.version = Stonean::ClassyInheritance::VERSION
26
+ PROJ.rubyforge.name = 'classyinherit'
27
+
28
+ PROJ.spec.opts << '--color'
29
+
30
+ # EOF
@@ -1,33 +1,9 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
-
5
- module ActiveRecord::Validations::ClassMethods
6
- def validates_associated_dependent(model_sym, options, configuration = {})
7
- configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid], :on => :save }.update(configuration)
8
-
9
- validates_each(model_sym, configuration) do |record, attr_name, value|
10
- associate = record.send(attr_name)
11
- if associate && !associate.valid?
12
- associate.errors.each do |key, value|
13
- if options[:prefix]
14
- key = (options[:prefix] == true) ? "#{model_sym}_#{key}" : "#{options[:prefix]}_#{key}"
15
- end
16
- if options[:postfix]
17
- key = (options[:postfix] == true) ? "#{key}_#{model_sym}" : "#{key}_#{options[:postfix]}"
18
- end
19
- record.errors.add(key, value)
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
26
-
27
1
  module Stonean
28
2
  module ClassyInheritance
29
- def self.included(base)
30
- base.extend Stonean::ClassyInheritance::ClassMethods
3
+ VERSION = '0.6.3.1'
4
+
5
+ def self.version
6
+ VERSION
31
7
  end
32
8
 
33
9
  module ClassMethods
@@ -48,7 +24,7 @@ module Stonean
48
24
  validates_associated_dependent model_sym, options, :if => options[:validates_associated_if]
49
25
  end
50
26
  else
51
- validates_associated_dependent model_sym, options
27
+ validates_associated_dependent model_sym, options
52
28
  end
53
29
 
54
30
  # Before save functionality to create/update the requisite object
@@ -184,7 +160,7 @@ module Stonean
184
160
  requisite_klass = eval(klass)
185
161
  unless requisite_klass.respond_to?(self.name.underscore.to_sym)
186
162
  requisite_klass.send :can_be, self.name.underscore,
187
- :as => polymorphic_name
163
+ :as => polymorphic_name
188
164
  end
189
165
  end
190
166
 
@@ -195,4 +171,32 @@ module Stonean
195
171
  end # ClassMethods
196
172
  end # ClassyInheritance module
197
173
  end # Stonean module
198
- ActiveRecord::Base.send :include, Stonean::ClassyInheritance
174
+
175
+ if Object.const_defined?("ActiveRecord") && ActiveRecord.const_defined?("Base")
176
+ module ActiveRecord::Validations::ClassMethods
177
+
178
+ def validates_associated_dependent(model_sym, options, configuration = {})
179
+ configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid], :on => :save }.update(configuration)
180
+
181
+ validates_each(model_sym, configuration) do |record, attr_name, value|
182
+ associate = record.send(attr_name)
183
+ if associate && !associate.valid?
184
+ associate.errors.each do |key, value|
185
+ if options[:prefix]
186
+ key = (options[:prefix] == true) ? "#{model_sym}_#{key}" : "#{options[:prefix]}_#{key}"
187
+ end
188
+ if options[:postfix]
189
+ key = (options[:postfix] == true) ? "#{key}_#{model_sym}" : "#{key}_#{options[:postfix]}"
190
+ end
191
+ record.errors.add(key, value) unless record.errors[key]
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+
199
+ ActiveRecord::Base.class_eval do
200
+ extend Stonean::ClassyInheritance::ClassMethods
201
+ end
202
+ end
@@ -8,10 +8,6 @@ class TestClassyInheritance < Test::Unit::TestCase
8
8
  @user = User.new
9
9
  end
10
10
 
11
- def test_active_record_should_have_classy_inheritance_included
12
- assert ActiveRecord::Base.included_modules.include?(Stonean::ClassyInheritance)
13
- end
14
-
15
11
  def test_active_record_should_respond_to_depends_on
16
12
  assert ActiveRecord::Base.respond_to?(:depends_on)
17
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnsbrn-classy-inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone
@@ -32,43 +32,17 @@ extra_rdoc_files:
32
32
  - History.txt
33
33
  - License.txt
34
34
  - Manifest.txt
35
- - PostInstall.txt
36
35
  - README.txt
37
- - website/index.txt
38
36
  files:
39
37
  - History.txt
40
38
  - License.txt
41
39
  - Manifest.txt
42
- - PostInstall.txt
43
- - README
44
40
  - README.txt
45
41
  - Rakefile
46
- - config/hoe.rb
47
- - config/requirements.rb
48
42
  - lib/classy-inheritance.rb
49
- - |-
50
- lib/classy-inhe
51
- ritance/version.rb
52
- - script/console
53
- - script/destroy
54
- - script/generate
55
- - script/txt2html
56
- - setup.rb
57
- - tasks/deployment.rake
58
- - tasks/environment.rake
59
- - tasks/website.rake
60
- - |-
61
- test/test_classy-inhe
62
- ritance.rb
43
+ - test/test_classy-inheritance.rb
63
44
  - test/test_helper.rb
64
- - website/index.html
65
- - website/index.txt
66
- - website/javascripts/rounded_corners_lite.inc.js
67
- - website/stylesheets/screen.css
68
- - website/template.html.erb
69
- - |-
70
- test/tes
71
- t_polymorphic_associations.rb
45
+ - test/test_polymorphic_associations.rb
72
46
  - test/test_with_optional_dependency.rb
73
47
  - test/test_with_prefix_postfix.rb
74
48
  - test/test_with_standard_attributes.rb
@@ -105,6 +79,4 @@ test_files:
105
79
  - test/test_polymorphic_associations.rb
106
80
  - test/test_with_optional_dependency.rb
107
81
  - test/test_with_prefix_postfix.rb
108
- - |-
109
- test/te
110
- st_with_standard_attributes.rb
82
+ - test/test_with_standard_attributes.rb
data/PostInstall.txt DELETED
File without changes
data/README DELETED
File without changes
data/config/hoe.rb DELETED
@@ -1,75 +0,0 @@
1
- require 'classy-inheritance/version'
2
-
3
- AUTHOR = 'Andrew Stone' # can also be an array of Authors
4
- EMAIL = "andy@stonean.com"
5
- DESCRIPTION = "Adds a depends_on class method to your ActiveRecord model so that you can define requisite objects."
6
- GEM_NAME = 'classy-inheritance' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'classyinherit' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
- EXTRA_DEPENDENCIES = [
11
- # ['activesupport', '>= 1.3.1']
12
- ] # An array of rubygem dependencies [name, version]
13
-
14
- @config_file = "~/.rubyforge/user-config.yml"
15
- @config = nil
16
- RUBYFORGE_USERNAME = "astone"
17
- def rubyforge_username
18
- unless @config
19
- begin
20
- @config = YAML.load(File.read(File.expand_path(@config_file)))
21
- rescue
22
- puts <<-EOS
23
- ERROR: No rubyforge config file found: #{@config_file}
24
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
- - See http://newgem.rubyforge.org/rubyforge.html for more details
26
- EOS
27
- exit
28
- end
29
- end
30
- RUBYFORGE_USERNAME.replace @config["username"]
31
- end
32
-
33
-
34
- REV = nil
35
- # UNCOMMENT IF REQUIRED:
36
- # REV = YAML.load(`svn info`)['Revision']
37
- VERS = ClassyInheritance::VERSION::STRING + (REV ? ".#{REV}" : "")
38
- RDOC_OPTS = ['--quiet', '--title', 'classy-inheritance documentation',
39
- "--opname", "index.html",
40
- "--line-numbers",
41
- "--main", "README",
42
- "--inline-source"]
43
-
44
- class Hoe
45
- def extra_deps
46
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
- @extra_deps
48
- end
49
- end
50
-
51
- # Generate all the Rake tasks
52
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
- $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
- p.developer(AUTHOR, EMAIL)
55
- p.description = DESCRIPTION
56
- p.summary = DESCRIPTION
57
- p.url = HOMEPATH
58
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
- p.test_globs = ["test/**/test_*.rb"]
60
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
-
62
- # == Optional
63
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
- #p.extra_deps = EXTRA_DEPENDENCIES
65
-
66
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
- end
68
-
69
- CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
- #PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
- PATH = RUBYFORGE_PROJECT
72
- $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
73
- #$hoe.rsync_args = '-av --delete --ignore-errors'
74
- $hoe.rsync_args = '-av --delete'
75
- $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -1,15 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe newgem rubigen].each do |req_gem|
6
- begin
7
- require req_gem
8
- rescue LoadError
9
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
- puts "Installation: gem install #{req_gem} -y"
11
- exit
12
- end
13
- end
14
-
15
- $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
data/script/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/classy-inheritance.rb'}"
9
- puts "Loading classy-inheritance gem"
10
- exec "#{irb} #{libs} --simple-prompt"
data/script/destroy DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html DELETED
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- GEM_NAME = 'classy-inheritance' # what ppl will type to install your gem
4
- RUBYFORGE_PROJECT = 'classyinherit'
5
-
6
- require 'rubygems'
7
- begin
8
- require 'newgem'
9
- require 'rubyforge'
10
- rescue LoadError
11
- puts "\n\nGenerating the website requires the newgem RubyGem"
12
- puts "Install: gem install newgem\n\n"
13
- exit(1)
14
- end
15
- require 'redcloth'
16
- require 'syntax/convertors/html'
17
- require 'erb'
18
- require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
19
-
20
- version = ClassyInheritance::VERSION::STRING
21
- download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
-
23
- def rubyforge_project_id
24
- RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
- end
26
-
27
- class Fixnum
28
- def ordinal
29
- # teens
30
- return 'th' if (10..19).include?(self % 100)
31
- # others
32
- case self % 10
33
- when 1: return 'st'
34
- when 2: return 'nd'
35
- when 3: return 'rd'
36
- else return 'th'
37
- end
38
- end
39
- end
40
-
41
- class Time
42
- def pretty
43
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
44
- end
45
- end
46
-
47
- def convert_syntax(syntax, source)
48
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
49
- end
50
-
51
- if ARGV.length >= 1
52
- src, template = ARGV
53
- template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
54
- else
55
- puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
56
- exit!
57
- end
58
-
59
- template = ERB.new(File.open(template).read)
60
-
61
- title = nil
62
- body = nil
63
- File.open(src) do |fsrc|
64
- title_text = fsrc.readline
65
- body_text_template = fsrc.read
66
- body_text = ERB.new(body_text_template).result(binding)
67
- syntax_items = []
68
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
69
- ident = syntax_items.length
70
- element, syntax, source = $1, $2, $3
71
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
72
- "syntax-temp-#{ident}"
73
- }
74
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
75
- body = RedCloth.new(body_text).to_html
76
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
77
- end
78
- stat = File.stat(src)
79
- created = stat.ctime
80
- modified = stat.mtime
81
-
82
- $stdout << template.result(binding)