midas-inactive_record 1.0.0

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/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 1.0.0 2009-04-03
2
+
3
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ inactive_record.gemspec
7
+ lib/inactive_record.rb
8
+ lib/inactive_record/base.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ spec/inactive_record/base_spec.rb
13
+ spec/inactive_record_spec.rb
14
+ spec/spec.opts
15
+ spec/spec_helper.rb
16
+ tasks/rspec.rake
data/PostInstall.txt ADDED
@@ -0,0 +1,5 @@
1
+
2
+ For more information on inactive_record, see http://github.com/midas/inactive_record/tree/master
3
+
4
+
5
+
data/README.rdoc ADDED
@@ -0,0 +1,73 @@
1
+ = inactive_record
2
+
3
+ http://github.com/midas/inactive_record/tree/master
4
+
5
+
6
+ == DESCRIPTION:
7
+
8
+ InactiveRecord gives you many of the features you know and love from ActiveRecord without the need for a backing
9
+ database table.
10
+
11
+
12
+ == FEATURES:
13
+
14
+ * An initialize method that accepts an attribute hash, including the Rails Date/Time select methods (ie. start_date(1i), etc...)
15
+ * A to_xml method that accepts the same options as its respective ActiveRecord method
16
+ * All validations work when you call valid?, excluding validates_uniqueness_of
17
+ * Supports errors_for method (when validations fail, just render the new or edit form as you mormaly would)
18
+ * Works with Rails 2.3
19
+
20
+
21
+ ==PROBLEMS:
22
+
23
+
24
+ == INSTALL:
25
+
26
+ sudo gem install midas-inactive_record
27
+
28
+
29
+ == USE:
30
+
31
+ Add gem requirement to your environment.rb file:
32
+
33
+ config.gem 'midas-inactive_record', :version => '1.0.0', :lib => 'inactive_record', :source => 'http://gems.github.com'
34
+
35
+ Create a model class:
36
+
37
+ class Thing < InactiveRecord::Base
38
+ attr_accessor :name, :begin_date, :end_date
39
+ validates_presence_of :name, :begin_date, :end_date
40
+ end
41
+
42
+ Now you can use errors_for, etc in your forms.
43
+
44
+
45
+ == REQUIREMENTS:
46
+
47
+ * ActiveRecord >= 2.2.0
48
+
49
+
50
+ == LICENSE:
51
+
52
+ (The MIT License)
53
+
54
+ Copyright (c) 2009 C. Jason Harrelson (midas)
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining
57
+ a copy of this software and associated documentation files (the
58
+ 'Software'), to deal in the Software without restriction, including
59
+ without limitation the rights to use, copy, modify, merge, publish,
60
+ distribute, sublicense, and/or sell copies of the Software, and to
61
+ permit persons to whom the Software is furnished to do so, subject to
62
+ the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be
65
+ included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
68
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
70
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/inactive_record'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('inactive_record', InactiveRecord::VERSION) do |p|
7
+ p.developer('C. Jason Harrelson', 'cjharrelson@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ # p.extra_deps = [
12
+ # ['activesupport','>= 2.0.2'],
13
+ # ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"],
16
+ ['activerecord', ">= 2.2.0"]
17
+ ]
18
+
19
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
20
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
21
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
22
+ p.rsync_args = '-av --delete --ignore-errors'
23
+ end
24
+
25
+ require 'newgem/tasks' # load /tasks/*.rake
26
+ Dir['tasks/**/*.rake'].each { |t| load t }
27
+
28
+ # TODO - want other tests/tasks run by default? Add them to the list
29
+ # task :default => [:spec, :features]
@@ -0,0 +1,141 @@
1
+ require 'active_record'
2
+ require 'active_record/base'
3
+
4
+ module InactiveRecord
5
+
6
+ class Base
7
+
8
+ def initialize( attributes={} )
9
+ unless attributes.nil?
10
+ # Fix any dates/times from rails date_select
11
+ keys = attributes.keys
12
+ date_keys = keys.grep(/(1i)/)
13
+ time_keys = keys.grep(/(4i)/)
14
+ date_keys.each do |date_key|
15
+ key = date_key.to_s.gsub( /\(1i\)/, '' )
16
+ num = keys.grep( /#{key.to_s}/ ).size
17
+ if num == 3
18
+ # Date
19
+ attributes[key.to_sym] = Date.civil( attributes.delete( "#{key}(1i)".to_sym ).to_i,
20
+ attributes.delete( "#{key}(2i)".to_sym ).to_i, attributes.delete( "#{key}(3i)".to_sym ).to_i )
21
+ elsif num == 5
22
+ #DateTime
23
+ attributes[key.to_sym] = DateTime.civil( attributes.delete( "#{key}(1i)".to_sym ).to_i,
24
+ attributes.delete( "#{key}(2i)".to_sym ).to_i, attributes.delete( "#{key}(3i)".to_sym ).to_i,
25
+ attributes.delete( "#{key}(4i)".to_sym ).to_i, attributes.delete( "#{key}(5i)".to_sym ).to_i )
26
+ elsif num == 6
27
+ #DateTime
28
+ attributes[key.to_sym] = DateTime.civil( attributes.delete( "#{key}(1i)".to_sym ).to_i,
29
+ attributes.delete( "#{key}(2i)".to_sym ).to_i, attributes.delete( "#{key}(3i)".to_sym ).to_i,
30
+ attributes.delete( "#{key}(4i)".to_sym ).to_i, attributes.delete( "#{key}(5i)".to_sym ).to_i,
31
+ attributes.delete( "#{key}(6i)".to_sym ).to_i )
32
+ end
33
+ end
34
+
35
+ attributes.each do |key, value|
36
+ self.instance_variable_set("@#{key}", value)
37
+ end
38
+ end
39
+ yield self if block_given?
40
+ end
41
+
42
+ def [](key)
43
+ instance_variable_get("@#{key}")
44
+ end
45
+
46
+ def method_missing( method_id, *args )
47
+ if md = /_before_type_cast$/.match(method_id.to_s)
48
+ attr_name = md.pre_match
49
+ return self[attr_name] if self.respond_to?(attr_name)
50
+ end
51
+ super
52
+ end
53
+
54
+ # Instructions on how to build xml for an object.
55
+ #
56
+ # *options*
57
+ # :only - A symbol or array of symbols of instance variable names to include in the xml.
58
+ # :except - A symbol or array of symbols of instance variable names to exclude in the xml.
59
+ # :skip_instruct - If true, output the document type, otherwise do not.
60
+ # :skip_types - (not yet) If true, do not output types of variables that are not strings.
61
+ # :include - (not yet) First level associations to include.
62
+ # :dasherize - If true, convert underscored variable names to dasherized variable names.
63
+ #
64
+ def to_xml( options={} )
65
+ options[:indent] ||= 2
66
+ except = options[:except]
67
+ only = options[:only]
68
+ throw 'Both the :except and :only options cannot be used simultaneously.' if !except.nil? && !only.nil?
69
+
70
+ except = Array.new << except.to_sym if except.is_a?( String )
71
+ except = Array.new << except if except.is_a?( Symbol )
72
+ only = Array.new << only.to_sym if only.is_a?( String )
73
+ only = Array.new << only if only.is_a?( Symbol )
74
+
75
+ dasherize = options[:dasherize]
76
+ dasherize = true unless !dasherize.nil?
77
+
78
+ xml = options[:builder] ||= Builder::XmlMarkup.new( :indent => options[:indent] )
79
+ xml.instruct! unless options[:skip_instruct]
80
+ xml.tag!( self.class.to_s.underscore ) do
81
+ self.instance_variables.each do |var|
82
+ var_name = var.to_s.gsub( /@/, '' )
83
+ var_name = var_name.dasherize if dasherize
84
+ if only
85
+ xml.tag!( var_name, self.instance_variable_get( var ) ) if only.include?( var_name ) || only.include?( var_name.to_sym )
86
+ elsif except
87
+ xml.tag!( var_name, self.instance_variable_get( var ) ) unless except.include?( var_name ) || except.include?( var_name.to_sym )
88
+ else
89
+ xml.tag!( var_name, self.instance_variable_get( var ) )
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ def new_record?
96
+ true
97
+ end
98
+
99
+ def self.self_and_descendents_from_active_record
100
+ [self]
101
+ end
102
+
103
+ def self.self_and_descendants_from_active_record
104
+ [self]
105
+ end
106
+
107
+ def self.human_name
108
+
109
+ end
110
+
111
+ protected
112
+
113
+ def raise_not_implemented_error(*params)
114
+ ValidatingModel.raise_not_implemented_error(*params)
115
+ end
116
+
117
+ def self.human_attribute_name(attribute_key_name)
118
+ attribute_key_name.humanize
119
+ end
120
+
121
+ alias save raise_not_implemented_error
122
+ alias update_attribute raise_not_implemented_error
123
+ alias save! raise_not_implemented_error
124
+
125
+ public
126
+ include ActiveRecord::Validations
127
+
128
+ class << self
129
+ def raise_not_implemented_error(*params)
130
+ raise NotImplementedError
131
+ end
132
+
133
+ alias validates_uniqueness_of raise_not_implemented_error
134
+ alias create! raise_not_implemented_error
135
+ alias validate_on_create raise_not_implemented_error
136
+ alias validate_on_update raise_not_implemented_error
137
+ alias save_with_validation raise_not_implemented_error
138
+ end
139
+
140
+ end
141
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'inactive_record/base'
5
+
6
+ module InactiveRecord
7
+ VERSION = '1.0.0'
8
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
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/inactive_record.rb'}"
9
+ puts "Loading inactive_record gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
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 ADDED
@@ -0,0 +1,14 @@
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)
File without changes
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'inactive_record'
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: midas-inactive_record
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - C. Jason Harrelson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.0
44
+ version:
45
+ description: InactiveRecord gives you many of the features you know and love from ActiveRecord without the need for a backing database table.
46
+ email:
47
+ - cjharrelson@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - PostInstall.txt
56
+ - README.rdoc
57
+ files:
58
+ - History.txt
59
+ - Manifest.txt
60
+ - PostInstall.txt
61
+ - README.rdoc
62
+ - Rakefile
63
+ - lib/inactive_record.rb
64
+ - lib/inactive_record/base.rb
65
+ - script/console
66
+ - script/destroy
67
+ - script/generate
68
+ - spec/inactive_record/base_spec.rb
69
+ - spec/inactive_record_spec.rb
70
+ - spec/spec.opts
71
+ - spec/spec_helper.rb
72
+ - tasks/rspec.rake
73
+ has_rdoc: true
74
+ homepage: http://github.com/midas/inactive_record/tree/master
75
+ post_install_message: PostInstall.txt
76
+ rdoc_options:
77
+ - --main
78
+ - README.rdoc
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ requirements: []
94
+
95
+ rubyforge_project: inactive_record
96
+ rubygems_version: 1.2.0
97
+ signing_key:
98
+ specification_version: 2
99
+ summary: InactiveRecord gives you many of the features you know and love from ActiveRecord without the need for a backing database table.
100
+ test_files: []
101
+