attr_default 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/README.rdoc +2 -3
- data/lib/attr_default/railtie.rb +18 -0
- data/lib/attr_default/version.rb +1 -1
- data/test/test_attr_default.rb +4 -3
- metadata +27 -15
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'hobosupport', '0.9.103', :path => '../web/vendor/gems/hobosupport-0.9.103'
|
4
|
-
gem 'hobofields', '0.9.103', :path => '../web/vendor/gems/hobofields-0.9.103'
|
3
|
+
# gem 'hobosupport', '0.9.103', :path => '../web/vendor/gems/hobosupport-0.9.103'
|
4
|
+
# gem 'hobofields', '0.9.103', :path => '../web/vendor/gems/hobofields-0.9.103'
|
5
5
|
|
6
6
|
# Specify your gem's dependencies in attr_default.gemspec
|
7
7
|
gemspec
|
data/README.rdoc
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
= AttrDefault
|
2
2
|
|
3
3
|
Dynamic Ruby defaults for ActiveRecord attributes.
|
4
|
-
These are
|
5
|
-
This allows dynamic defaults to depend on attributes that are assigned after initialization, or on other dynamic defaults.
|
4
|
+
These defaults are evaluated just in time, allowing dynamic defaults to depend on attributes that are assigned after initialization, or on other dynamic defaults.
|
6
5
|
|
7
6
|
Example:
|
8
7
|
|
@@ -45,7 +44,7 @@ The +attr_default+ macro takes 2 arguments:
|
|
45
44
|
|
46
45
|
+attr_default+ can be used for persistent or non-persistent attributes.
|
47
46
|
|
48
|
-
=== Timing of Default
|
47
|
+
=== Timing of Default Evaluation
|
49
48
|
|
50
49
|
Defaults are lazy computed, just in time, whenever the first of these happens:
|
51
50
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AttrDefault
|
2
|
+
# Rails 3 initialization
|
3
|
+
def self.initialize_railtie
|
4
|
+
ActiveSupport.on_load :active_record do
|
5
|
+
AttrDefault.initialize_active_record_extensions
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.initialize_active_record_extensions
|
10
|
+
ActiveRecord::Base.extend(AttrDefault::ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Railtie < Rails::Railtie
|
14
|
+
initializer 'attr_default.insert_into_active_record' do
|
15
|
+
AttrDefault.initialize_railtie
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/attr_default/version.rb
CHANGED
data/test/test_attr_default.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
WANT_RAILS_VERSION = "~> #{ENV.fetch('WANT_RAILS_VERSION', '
|
1
|
+
WANT_RAILS_VERSION = "~> #{ENV.fetch('WANT_RAILS_VERSION', '3.0.15')}"
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
gem 'rails', WANT_RAILS_VERSION
|
@@ -48,8 +48,8 @@ ActiveRecord::Base.connection.create_table(:test_numbers, :force => true) do |t|
|
|
48
48
|
end
|
49
49
|
|
50
50
|
if defined?(Rails::Railtie)
|
51
|
-
|
52
|
-
|
51
|
+
AttrDefault.initialize_railtie
|
52
|
+
AttrDefault.initialize_active_record_extensions
|
53
53
|
end
|
54
54
|
|
55
55
|
class TestUser < ActiveRecord::Base
|
@@ -253,3 +253,4 @@ class AttrDefaultTest < Test::Unit::TestCase
|
|
253
253
|
assert_equal "supersecret", user.password
|
254
254
|
end
|
255
255
|
end
|
256
|
+
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_default
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Colin Kelley
|
@@ -15,56 +16,63 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2012-
|
19
|
-
default_executable:
|
19
|
+
date: 2012-12-22 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: rake
|
23
|
-
prerelease: false
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
25
24
|
requirements:
|
26
25
|
- - ">="
|
27
26
|
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
|
+
prerelease: false
|
31
32
|
type: :runtime
|
33
|
+
name: rake
|
32
34
|
version_requirements: *id001
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
|
-
name: rails
|
35
|
-
prerelease: false
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
37
38
|
requirements:
|
38
39
|
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
40
42
|
segments:
|
41
43
|
- 0
|
42
44
|
version: "0"
|
45
|
+
prerelease: false
|
43
46
|
type: :runtime
|
47
|
+
name: rails
|
44
48
|
version_requirements: *id002
|
45
49
|
- !ruby/object:Gem::Dependency
|
46
|
-
name: sqlite3
|
47
|
-
prerelease: false
|
48
50
|
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
49
52
|
requirements:
|
50
53
|
- - ">="
|
51
54
|
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
52
56
|
segments:
|
53
57
|
- 0
|
54
58
|
version: "0"
|
59
|
+
prerelease: false
|
55
60
|
type: :development
|
61
|
+
name: sqlite3
|
56
62
|
version_requirements: *id003
|
57
63
|
- !ruby/object:Gem::Dependency
|
58
|
-
name: hobofields
|
59
|
-
prerelease: false
|
60
64
|
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
61
66
|
requirements:
|
62
67
|
- - ">="
|
63
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
64
70
|
segments:
|
65
71
|
- 0
|
66
72
|
version: "0"
|
73
|
+
prerelease: false
|
67
74
|
type: :development
|
75
|
+
name: hobofields
|
68
76
|
version_requirements: *id004
|
69
77
|
description: Dynamic Ruby defaults for ActiveRecord attributes
|
70
78
|
email:
|
@@ -83,9 +91,9 @@ files:
|
|
83
91
|
- Rakefile
|
84
92
|
- attr_default.gemspec
|
85
93
|
- lib/attr_default.rb
|
94
|
+
- lib/attr_default/railtie.rb
|
86
95
|
- lib/attr_default/version.rb
|
87
96
|
- test/test_attr_default.rb
|
88
|
-
has_rdoc: true
|
89
97
|
homepage: https://github.com/RingRevenue/attr_default
|
90
98
|
licenses: []
|
91
99
|
|
@@ -95,23 +103,27 @@ rdoc_options: []
|
|
95
103
|
require_paths:
|
96
104
|
- lib
|
97
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
98
107
|
requirements:
|
99
108
|
- - ">="
|
100
109
|
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
101
111
|
segments:
|
102
112
|
- 0
|
103
113
|
version: "0"
|
104
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
105
116
|
requirements:
|
106
117
|
- - ">="
|
107
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
108
120
|
segments:
|
109
121
|
- 0
|
110
122
|
version: "0"
|
111
123
|
requirements: []
|
112
124
|
|
113
125
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.8.24
|
115
127
|
signing_key:
|
116
128
|
specification_version: 3
|
117
129
|
summary: "Dynamic Ruby defaults for ActiveRecord attributes. These are lazy evaluated just in time: when first accessed, or just before validation or save. This allows dynamic defaults to depend on attributes that are assigned after initialization, or on other dynamic defaults."
|