active_hash 0.7.8 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 2010-03-01
2
+ - Removed "extend"-related deprecations - they didn't play well with rails class loading
3
+
1
4
  2010-01-18
2
5
  - Added stub for #destroyed? method, since Rails associations now depend on it
3
6
 
data/README.md CHANGED
@@ -182,15 +182,15 @@ You can also use standard rails view helpers, like #collection_select:
182
182
 
183
183
  <%= collection_select :person, :country_id, Country.all, :id, :name %>
184
184
 
185
- If you extend the ActiveHash::Associations module, you can also create associations from your ActiveHash classes, like so:
185
+ If you include the ActiveHash::Associations module, you can also create associations from your ActiveHash classes, like so:
186
186
 
187
187
  class Country < ActiveHash::Base
188
- extend ActiveHash::Associations
188
+ include ActiveHash::Associations
189
189
  has_many :people
190
190
  end
191
191
 
192
192
  class Person < ActiveHash::Base
193
- extend ActiveHash::Associations
193
+ include ActiveHash::Associations
194
194
  belongs_to :country
195
195
  has_many :pets
196
196
  end
@@ -201,7 +201,7 @@ If you extend the ActiveHash::Associations module, you can also create associati
201
201
  Once you define a belongs to, you also get the setter method:
202
202
 
203
203
  class City < ActiveHash::Base
204
- extend ActiveHash::Associations
204
+ include ActiveHash::Associations
205
205
  belongs_to :state
206
206
  end
207
207
 
@@ -254,7 +254,7 @@ Since ActiveYaml just creates a hash from the YAML file, you will have all field
254
254
 
255
255
  ## ActiveFile
256
256
 
257
- If you store encrypted data, or you'd like to store your flat files as CSV or XML or any other format, you can easily extend ActiveHash to parse and load your file. Just add a custom ::load_file method, and define the extension you want the file to use:
257
+ If you store encrypted data, or you'd like to store your flat files as CSV or XML or any other format, you can easily include ActiveHash to parse and load your file. Just add a custom ::load_file method, and define the extension you want the file to use:
258
258
 
259
259
  class Country < ActiveFile::Base
260
260
  set_root_path "/u/data"
@@ -289,7 +289,7 @@ ActiveHash can expose its data in an Enumeration by setting constants for each r
289
289
  The field to be used as the constant is set using _enum_accessor_ which takes the name of a field as an argument.
290
290
 
291
291
  class Country < ActiveHash::Base
292
- extend ActiveHash::Enum
292
+ include ActiveHash::Enum
293
293
  self.data = [
294
294
  {:id => 1, :name => "US", :capital => "Washington, DC"},
295
295
  {:id => 2, :name => "Canada", :capital => "Ottawa"},
data/Rakefile CHANGED
@@ -10,6 +10,19 @@ begin
10
10
  gem.homepage = "http://github.com/zilkey/active_hash"
11
11
  gem.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata"]
12
12
  gem.add_dependency('activesupport', [">= 2.2.2"])
13
+ gem.post_install_message = %q{NOTE: Breaking change! Please change any extend statements to include statements:
14
+
15
+ extend ActiveHash::Associations
16
+ extend ActiveHash::Enum
17
+
18
+ becomes
19
+
20
+ include ActiveHash::Associations
21
+ include ActiveHash::Enum
22
+
23
+ Sorry for the inconvenience.
24
+
25
+ }
13
26
  end
14
27
  Jeweler::GemcutterTasks.new
15
28
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.8
1
+ 0.7.9
data/active_hash.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_hash}
8
- s.version = "0.7.8"
8
+ s.version = "0.7.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeff Dean", "Mike Dalessio", "Corey Innis", "Peter Jaros", "Brandon Keene", "Brian Takita", "Pat Nakajima", "John Pignata"]
12
- s.date = %q{2010-01-18}
12
+ s.date = %q{2010-03-01}
13
13
  s.email = %q{jeff@zilkey.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -44,6 +44,19 @@ Gem::Specification.new do |s|
44
44
  "spec/spec_helper.rb"
45
45
  ]
46
46
  s.homepage = %q{http://github.com/zilkey/active_hash}
47
+ s.post_install_message = %q{NOTE: Breaking change! Please change any extend statements to include statements:
48
+
49
+ extend ActiveHash::Associations
50
+ extend ActiveHash::Enum
51
+
52
+ becomes
53
+
54
+ include ActiveHash::Associations
55
+ include ActiveHash::Enum
56
+
57
+ Sorry for the inconvenience.
58
+
59
+ }
47
60
  s.rdoc_options = ["--charset=UTF-8"]
48
61
  s.require_paths = ["lib"]
49
62
  s.rubygems_version = %q{1.3.5}
@@ -2,12 +2,7 @@ module ActiveHash
2
2
  module Associations
3
3
 
4
4
  def self.included(base)
5
- puts %Q{DEPRECATION WARNING: include #{self} should be extend #{self} and will be removed in later versions. Called from #{caller.first}}
6
- base.extend self
7
- end
8
-
9
- def self.extended(base)
10
- base.send :extend, Methods
5
+ base.extend Methods
11
6
  end
12
7
 
13
8
  module Methods
data/lib/enum/enum.rb CHANGED
@@ -3,48 +3,56 @@ module ActiveHash
3
3
 
4
4
  DuplicateEnumAccessor = Class.new(RuntimeError)
5
5
 
6
- def enum_accessor(field_name)
7
- @enum_accessor = field_name
8
- reload
6
+ def self.included(base)
7
+ base.extend(Methods)
9
8
  end
9
+
10
+ module Methods
10
11
 
11
- def insert(record)
12
- super
13
- set_constant(record) if @enum_accessor.present?
14
- end
12
+ def enum_accessor(field_name)
13
+ @enum_accessor = field_name
14
+ reload
15
+ end
15
16
 
16
- def delete_all
17
- if @enum_accessor.present?
18
- @records.each do |record|
19
- constant = constant_for(record.attributes[@enum_accessor])
20
- remove_const(constant) if const_defined?(constant)
17
+ def insert(record)
18
+ super
19
+ set_constant(record) if @enum_accessor.present?
20
+ end
21
+
22
+ def delete_all
23
+ if @enum_accessor.present?
24
+ @records.each do |record|
25
+ constant = constant_for(record.attributes[@enum_accessor])
26
+ remove_const(constant) if const_defined?(constant)
27
+ end
21
28
  end
29
+ super
22
30
  end
23
- super
24
- end
25
31
 
26
- def set_constant(record)
27
- constant = constant_for(record.attributes[@enum_accessor])
28
- return nil if constant.blank?
32
+ def set_constant(record)
33
+ constant = constant_for(record.attributes[@enum_accessor])
34
+ return nil if constant.blank?
29
35
 
30
- unless const_defined?(constant)
31
- const_set(constant, record)
32
- else
33
- raise DuplicateEnumAccessor, "#{constant} already defined for #{self.class}" unless const_get(constant) == record
36
+ unless const_defined?(constant)
37
+ const_set(constant, record)
38
+ else
39
+ raise DuplicateEnumAccessor, "#{constant} already defined for #{self.class}" unless const_get(constant) == record
40
+ end
34
41
  end
35
- end
36
42
 
37
- private :set_constant
43
+ private :set_constant
38
44
 
39
- def constant_for(field_value)
40
- if constant = field_value.try(:dup)
41
- constant.gsub!(/[^A-Za-z]*/, "")
42
- constant.upcase!
43
- constant
45
+ def constant_for(field_value)
46
+ if constant = field_value.try(:dup)
47
+ constant.gsub!(/[^A-Za-z]*/, "")
48
+ constant.upcase!
49
+ constant
50
+ end
44
51
  end
52
+
53
+ private :constant_for
45
54
  end
46
55
 
47
- private :constant_for
48
56
  end
49
57
 
50
58
  end
@@ -1,35 +1,5 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
- describe ActiveHash::Base, "associations when included" do
4
- before do
5
- class City < ActiveHash::Base
6
- silence_stream STDOUT do
7
- include ActiveHash::Associations
8
- end
9
- end
10
-
11
- class Author < ActiveHash::Base
12
- silence_stream STDOUT do
13
- include ActiveHash::Associations
14
- end
15
- field :publisher_id
16
- field :city_id
17
- end
18
- end
19
-
20
- after do
21
- Object.send :remove_const, :City
22
- Object.send :remove_const, :Author
23
- end
24
-
25
- it "works until the deprecation period is up" do
26
- Author.belongs_to :city
27
- city = City.create!
28
- author = Author.new :city => city
29
- author.city.should == city
30
- end
31
- end
32
-
33
3
  describe ActiveHash::Base, "associations" do
34
4
 
35
5
  before do
@@ -37,11 +7,11 @@ describe ActiveHash::Base, "associations" do
37
7
  end
38
8
 
39
9
  class City < ActiveHash::Base
40
- extend ActiveHash::Associations
10
+ include ActiveHash::Associations
41
11
  end
42
12
 
43
13
  class Author < ActiveHash::Base
44
- extend ActiveHash::Associations
14
+ include ActiveHash::Associations
45
15
  end
46
16
 
47
17
  build_model :books do
@@ -6,7 +6,7 @@ describe ActiveHash::Base, "enum" do
6
6
  ActiveYaml::Base.set_root_path File.expand_path(File.dirname(__FILE__) + "/../fixtures")
7
7
 
8
8
  class Borough < ActiveYaml::Base
9
- extend ActiveHash::Enum
9
+ include ActiveHash::Enum
10
10
  fields :name, :county, :population
11
11
  enum_accessor :name
12
12
  end
@@ -24,7 +24,7 @@ describe ActiveHash::Base, "enum" do
24
24
  it "ensures that values stored in the field specified are unique" do
25
25
  lambda do
26
26
  Class.new(ActiveHash::Base) do
27
- extend ActiveHash::Enum
27
+ include ActiveHash::Enum
28
28
  self.data = [
29
29
  { :name => 'Woodford Reserve' },
30
30
  { :name => 'Bulliet Bourbon' },
@@ -37,7 +37,7 @@ describe ActiveHash::Base, "enum" do
37
37
 
38
38
  it "removes non-word characters from values before setting constants" do
39
39
  Movie = Class.new(ActiveHash::Base) do
40
- extend ActiveHash::Enum
40
+ include ActiveHash::Enum
41
41
  self.data = [
42
42
  {:name => 'Die Hard 2', :rating => '4.3'},
43
43
  {:name => 'The Informant!', :rating => '4.3'},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dean
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-01-18 00:00:00 -05:00
19
+ date: 2010-03-01 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -69,7 +69,20 @@ has_rdoc: true
69
69
  homepage: http://github.com/zilkey/active_hash
70
70
  licenses: []
71
71
 
72
- post_install_message:
72
+ post_install_message: |
73
+ NOTE: Breaking change! Please change any extend statements to include statements:
74
+
75
+ extend ActiveHash::Associations
76
+ extend ActiveHash::Enum
77
+
78
+ becomes
79
+
80
+ include ActiveHash::Associations
81
+ include ActiveHash::Enum
82
+
83
+ Sorry for the inconvenience.
84
+
85
+
73
86
  rdoc_options:
74
87
  - --charset=UTF-8
75
88
  require_paths: