can_be 0.3.0 → 0.4.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96fd1a3e11e100b1e23387fc4cb12190f923dcda
4
+ data.tar.gz: d6626f43fe163be43885e2964d688e8c48b46c64
5
+ SHA512:
6
+ metadata.gz: a4ce981d6434b8d00be2fe95c882cbda8dae6fce2efa9be782e9beaaa140fafaee79c2f7ee842cd8239169c2c3bede8c2350acdf34378f614a436a43dfa46d51
7
+ data.tar.gz: 6e39c99d3af0b993a96f07a798d6cf289bfc1268f4661c72671662d3e20dc4f6846955a77619635822f14432c792fee4aa7ba4c5e67d1da8f5e457cc2a503abd
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
17
  log/*.log
18
+ .idea
@@ -1,9 +1,16 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - 2.0.0
4
5
  - 1.9.3
5
6
  - 1.9.2
6
7
 
7
8
  gemfile:
8
9
  - gemfiles/3.1.gemfile
9
10
  - gemfiles/3.2.gemfile
11
+ - gemfiles/4.0.gemfile
12
+
13
+ matrix:
14
+ exclude:
15
+ rvm: 1.9.2
16
+ gemfile: gemfiles/4.0.gemfile
@@ -1,3 +1,9 @@
1
+ ## [Version 0.5.0](https://github.com/mstarkman/can_be)
2
+
3
+ ## [Version 0.4.0](https://github.com/mstarkman/can_be/tree/v0.4.0)
4
+
5
+ * Updated code to work with Rails 4.0.0beta1
6
+
1
7
  ## [Version 0.3.0](https://github.com/mstarkman/can_be/tree/v0.3.0)
2
8
 
3
9
  * Allowed the options to be specified inside the can_be method call block
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ can_be_env = ENV['CAN_BE_ENV'] || '3.2'
4
+
5
+ unless ENV['CAN_BE_ENV'].nil?
6
+ eval(File.read(File.join(File.dirname(__FILE__), 'gemfiles', "#{can_be_env}.gemfile")), binding)
7
+ end
8
+
3
9
  # Specify your gem's dependencies in can_be.gemspec
4
10
  gemspec
11
+
@@ -1,48 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- can_be (0.3.0)
5
- activerecord (~> 3.1)
6
- activesupport (~> 3.1)
4
+ can_be (0.4.0)
5
+ activerecord (>= 3.1)
6
+ activesupport (>= 3.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.11)
12
- activesupport (= 3.2.11)
11
+ activemodel (3.2.13)
12
+ activesupport (= 3.2.13)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.11)
15
- activemodel (= 3.2.11)
16
- activesupport (= 3.2.11)
14
+ activerecord (3.2.13)
15
+ activemodel (= 3.2.13)
16
+ activesupport (= 3.2.13)
17
17
  arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.11)
20
- i18n (~> 0.6)
19
+ activesupport (3.2.13)
20
+ i18n (= 0.6.1)
21
21
  multi_json (~> 1.0)
22
22
  arel (3.0.2)
23
23
  builder (3.0.4)
24
- coderay (1.0.8)
24
+ coderay (1.0.9)
25
25
  database_cleaner (0.9.1)
26
- diff-lcs (1.1.3)
26
+ diff-lcs (1.2.3)
27
27
  i18n (0.6.1)
28
28
  method_source (0.8.1)
29
- multi_json (1.5.0)
30
- pry (0.9.10)
29
+ multi_json (1.7.2)
30
+ pry (0.9.12)
31
31
  coderay (~> 1.0.5)
32
32
  method_source (~> 0.8)
33
- slop (~> 3.3.1)
34
- rake (10.0.2)
35
- rspec (2.12.0)
36
- rspec-core (~> 2.12.0)
37
- rspec-expectations (~> 2.12.0)
38
- rspec-mocks (~> 2.12.0)
39
- rspec-core (2.12.0)
40
- rspec-expectations (2.12.0)
41
- diff-lcs (~> 1.1.3)
42
- rspec-mocks (2.12.0)
43
- slop (3.3.3)
44
- sqlite3 (1.3.6)
45
- tzinfo (0.3.35)
33
+ slop (~> 3.4)
34
+ rake (10.0.4)
35
+ rspec (2.13.0)
36
+ rspec-core (~> 2.13.0)
37
+ rspec-expectations (~> 2.13.0)
38
+ rspec-mocks (~> 2.13.0)
39
+ rspec-core (2.13.1)
40
+ rspec-expectations (2.13.0)
41
+ diff-lcs (>= 1.1.3, < 2.0)
42
+ rspec-mocks (2.13.1)
43
+ slop (3.4.4)
44
+ sqlite3 (1.3.7)
45
+ tzinfo (0.3.37)
46
46
 
47
47
  PLATFORMS
48
48
  ruby
data/README.md CHANGED
@@ -6,7 +6,7 @@ Here is a blog post that will describe more of the rationale behind the CanBe ge
6
6
 
7
7
  ## Versioning
8
8
 
9
- I will be following [Semantic Versioning](http://semver.org/) as closely as possible. The `master` branch will be the latest development version and may not match the version of the code you are using. There is a git tag for each released version. The [CHANGELOG.md](https://github.com/mstarkman/can_be/blob/master/CHANGELOG.md) will contain the correct links to each version.
9
+ I will be following [Semantic Versioning](http://semver.org/) as closely as possible. The `master` branch will be the latest development version and may not match the version of the code you are using. There is a git tag for each released version. The [CHANGELOG.md](CHANGELOG.md) will contain the correct links to each version.
10
10
 
11
11
  ## Installation
12
12
 
@@ -26,9 +26,9 @@ And then execute:
26
26
 
27
27
  The documentation for the basic implementation of CanBe can be found in this readme. Here is the documentation for the other features.
28
28
 
29
- * [Different Attributes per CanBe Type (details)](https://github.com/mstarkman/can_be/blob/master/docs/details.md)
30
- * [Keeping Details History When Changing CanBe Types](https://github.com/mstarkman/can_be/blob/master/docs/history.md)
31
- * [Custom RSpec Matchers](https://github.com/mstarkman/can_be/blob/master/docs/rspec_matcher.md)
29
+ * [Different Attributes per CanBe Type (details)](docs/details.md)
30
+ * [Keeping Details History When Changing CanBe Types](docs/history.md)
31
+ * [Custom RSpec Matchers](docs/rspec_matcher.md)
32
32
 
33
33
  ## Database Configuration (via migrations)
34
34
 
@@ -45,7 +45,7 @@ class AddCanBeTypeToAddresses < ActiveRecord::Migration
45
45
  end
46
46
  ```
47
47
 
48
- **NOTE:** Examples of the database migrations can be found in the [`spec/support/schema.rb`](https://github.com/mstarkman/can_be/blob/master/spec/support/schema.rb) file.
48
+ **NOTE:** Examples of the database migrations can be found in the [`spec/support/schema.rb`](spec/support/schema.rb) file.
49
49
 
50
50
  ## Model Configuration
51
51
 
@@ -82,7 +82,7 @@ class Person < ActiveRecord::Base
82
82
  end
83
83
  ```
84
84
 
85
- **NOTE:** Examples of the model configurations can be found in the [`spec/support/models.rb`](https://github.com/mstarkman/can_be/blob/master/spec/support/models.rb) file.
85
+ **NOTE:** Examples of the model configurations can be found in the [`spec/support/models.rb`](spec/support/models.rb) file.
86
86
 
87
87
  ## Usage
88
88
 
@@ -134,4 +134,4 @@ Methods are also defined on your CanBe model that will find all of the records f
134
134
 
135
135
  ## License
136
136
 
137
- See [LICENSE.txt](https://github.com/mstarkman/can_be/blob/master/LICENSE.txt).
137
+ See [LICENSE.txt](LICENSE.txt).
@@ -12,10 +12,11 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = %q{CanBe allows you to track the type of your ActiveRecord model in a consistent simple manner. With just a little configuration on your part, each type of record can contain different attributes that are specifc to that type of record. From a data modelling perspective this is preferred over ActiveRecord STI since you will not have many columns in your database that have null values. Under the hood, CanBe uses one-to-one Polymorphic Associations to accomplish the different attributes per type.}
13
13
  gem.homepage = ""
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
15
+ gem.required_ruby_version = '>= 1.9.2'
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
19
20
 
20
21
  gem.add_development_dependency('rspec', '~> 2.0')
21
22
  gem.add_development_dependency('sqlite3')
@@ -23,6 +24,6 @@ Gem::Specification.new do |gem|
23
24
  gem.add_development_dependency('rake')
24
25
  gem.add_development_dependency('pry')
25
26
 
26
- gem.add_dependency("activerecord", "~> 3.1")
27
- gem.add_dependency("activesupport", "~> 3.1")
27
+ gem.add_dependency("activerecord", ">= 3.1")
28
+ gem.add_dependency("activesupport", ">= 3.1")
28
29
  end
@@ -30,7 +30,7 @@ class AddCanBeDetailsToAddresses < ActiveRecord::Migration
30
30
  end
31
31
  ```
32
32
 
33
- **NOTE:** Examples of the database migrations can be found in the [`spec/support/schema.rb`](https://github.com/mstarkman/can_be/blob/master/spec/support/schema.rb) file.
33
+ **NOTE:** Examples of the database migrations can be found in the [`spec/support/schema.rb`](../spec/support/schema.rb) file.
34
34
 
35
35
  ## Models ##
36
36
 
@@ -71,7 +71,7 @@ class HomeAddressDetail < ActiveRecord::Base
71
71
  end
72
72
  ```
73
73
 
74
- **NOTE:** Examples of the model configurations can be found in the [`spec/support/models.rb`](https://github.com/mstarkman/can_be/blob/master/spec/support/models.rb) file.
74
+ **NOTE:** Examples of the model configurations can be found in the [`spec/support/models.rb`](../spec/support/models.rb) file.
75
75
 
76
76
  ## Accessing the Details
77
77
 
@@ -1,6 +1,6 @@
1
1
  # Keeping Details History When Changing CanBe Types #
2
2
 
3
- CanBe provides a history facility that will allow the [details](https://github.com/mstarkman/can_be/blob/master/docs/details.md) data to be preserved when switching between CanBe types. This way if you switch back to a CanBe type that was previously used, the specific data for the new CanBe type will still be available.
3
+ CanBe provides a history facility that will allow the [details](details.md) data to be preserved when switching between CanBe types. This way if you switch back to a CanBe type that was previously used, the specific data for the new CanBe type will still be available.
4
4
 
5
5
  ## Database Migrations ##
6
6
 
@@ -16,7 +16,7 @@ create_table :address_can_be_histories, :force => true do |t|
16
16
  end
17
17
  ```
18
18
 
19
- **NOTE:** Examples of the database migrations can be found in the [`spec/support/schema.rb`](https://github.com/mstarkman/can_be/blob/master/spec/support/schema.rb) file.
19
+ **NOTE:** Examples of the database migrations can be found in the [`spec/support/schema.rb`](../spec/support/schema.rb) file.
20
20
 
21
21
  ## Models ##
22
22
 
@@ -4,8 +4,8 @@ Included in this gem are a set of matchers for RSpec that can be used to ensure
4
4
 
5
5
  `require 'can_be/rspec/matchers'`
6
6
 
7
- You can then use the `implement_can_be` matcher as follows. There are a number of fluent methods that you can use as well. These methods can be seen in the [`spec/can_be/rspec/matchers/can_be_matcher_spec.rb`](https://github.com/mstarkman/can_be/blob/master/spec/can_be/rspec/matchers/can_be_matcher_spec.rb) file.
7
+ You can then use the `implement_can_be` matcher as follows. There are a number of fluent methods that you can use as well. These methods can be seen in the [`spec/can_be/rspec/matchers/can_be_matcher_spec.rb`](../spec/can_be/rspec/matchers/can_be_matcher_spec.rb) file.
8
8
 
9
9
  `Address.should implement_can_be(:home_address, :work_address, :vacation_address)`
10
10
 
11
- Examples of the `implement_can_be_detail` matcher can be found in the [`spec/can_be/rspec/matchers/can_be_detail_matcher_spec.rb`](https://github.com/mstarkman/can_be/blob/master/spec/can_be/rspec/matchers/can_be_detail_matcher_spec.rb) file.
11
+ Examples of the `implement_can_be_detail` matcher can be found in the [`spec/can_be/rspec/matchers/can_be_detail_matcher_spec.rb`](../spec/can_be/rspec/matchers/can_be_detail_matcher_spec.rb) file.
@@ -3,5 +3,9 @@ source "http://rubygems.org"
3
3
  gem "activerecord", "~> 3.1.0"
4
4
  gem "activesupport", "~> 3.1.0"
5
5
 
6
- gemspec :path=>"../"
6
+ if File.dirname(__FILE__).split('/').last == 'gemfiles'
7
+ gemspec path: '../'
8
+ else
9
+ gemspec
10
+ end
7
11
 
@@ -3,5 +3,9 @@ source "http://rubygems.org"
3
3
  gem "activerecord", "~> 3.2.0"
4
4
  gem "activesupport", "~> 3.2.0"
5
5
 
6
- gemspec :path=>"../"
6
+ if File.dirname(__FILE__).split('/').last == 'gemfiles'
7
+ gemspec path: '../'
8
+ else
9
+ gemspec
10
+ end
7
11
 
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "activerecord", "~> 4.0.0.beta1"
4
+ gem "activesupport", "~> 4.0.0.beta1"
5
+ gem "database_cleaner", "~>1.0.0.RC1"
6
+
7
+ if File.dirname(__FILE__).split('/').last == 'gemfiles'
8
+ gemspec path: '../'
9
+ else
10
+ gemspec
11
+ end
12
+
@@ -95,7 +95,7 @@ module CanBe
95
95
 
96
96
  def define_details
97
97
  @klass.class_eval do
98
- belongs_to self.can_be_config.details_name.to_sym, polymorphic: true, autosave: true, dependent: :destroy
98
+ belongs_to self.can_be_config.details_name.to_sym, polymorphic: true, autosave: true
99
99
 
100
100
  after_initialize do |model|
101
101
  model.can_be_processor.initialize_details
@@ -104,6 +104,10 @@ module CanBe
104
104
  after_save do |model|
105
105
  model.can_be_processor.clean_details
106
106
  end
107
+
108
+ after_destroy do |model|
109
+ model.can_be_processor.destroy_details
110
+ end
107
111
  end
108
112
  end
109
113
 
@@ -90,6 +90,10 @@ module CanBe
90
90
  history_model_class.where(can_be_model_id: @model.id, can_be_details_type: details_type).destroy_all
91
91
  end
92
92
 
93
+ def destroy_details
94
+ @model.send(@details_name).destroy
95
+ end
96
+
93
97
  private
94
98
  def has_details?
95
99
  @model.respond_to?(@details_name) && @model.respond_to?(@details_id) && @model.respond_to?(@details_type)
@@ -105,8 +109,7 @@ module CanBe
105
109
  @model.send("#{@details_name}=", details_for(t))
106
110
  end
107
111
  else
108
- @model.send("#{@details_id}=", nil)
109
- @model.send("#{@details_type}=", nil)
112
+ @model.send("#{@details_name}=", nil)
110
113
  end
111
114
  end
112
115
 
@@ -1,3 +1,3 @@
1
1
  module CanBe
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_be
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mark Starkman
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
11
+ date: 2013-04-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,97 +27,85 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: database_cleaner
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: pry
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: activerecord
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ~>
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '3.1'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ~>
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '3.1'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: activesupport
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ~>
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '3.1'
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ~>
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '3.1'
126
111
  description: CanBe allows you to track the type of your ActiveRecord model in a consistent
@@ -148,6 +133,7 @@ files:
148
133
  - docs/rspec_matcher.md
149
134
  - gemfiles/3.1.gemfile
150
135
  - gemfiles/3.2.gemfile
136
+ - gemfiles/4.0.gemfile
151
137
  - lib/can_be.rb
152
138
  - lib/can_be/builder.rb
153
139
  - lib/can_be/builder/can_be.rb
@@ -178,33 +164,26 @@ files:
178
164
  - spec/support/schema.rb
179
165
  homepage: ''
180
166
  licenses: []
167
+ metadata: {}
181
168
  post_install_message:
182
169
  rdoc_options: []
183
170
  require_paths:
184
171
  - lib
185
172
  required_ruby_version: !ruby/object:Gem::Requirement
186
- none: false
187
173
  requirements:
188
- - - ! '>='
174
+ - - '>='
189
175
  - !ruby/object:Gem::Version
190
- version: '0'
191
- segments:
192
- - 0
193
- hash: -227341645228978432
176
+ version: 1.9.2
194
177
  required_rubygems_version: !ruby/object:Gem::Requirement
195
- none: false
196
178
  requirements:
197
- - - ! '>='
179
+ - - '>='
198
180
  - !ruby/object:Gem::Version
199
181
  version: '0'
200
- segments:
201
- - 0
202
- hash: -227341645228978432
203
182
  requirements: []
204
183
  rubyforge_project:
205
- rubygems_version: 1.8.23
184
+ rubygems_version: 2.0.0
206
185
  signing_key:
207
- specification_version: 3
186
+ specification_version: 4
208
187
  summary: CanBe allows you to track the type of your ActiveRecord model in a consistent
209
188
  simple manner. With just a little configuration on your part, each type of record
210
189
  can contain different attributes that are specifc to that type of record. From