friendly-attributes 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ### 0.5.0
5
+
6
+ * (ihoka) Added configurable active_record_key to the FriendlyDetails model. active_record_key affects the name of the generated Friendly index table and the attribute in which the ActiveRecord model ID is stored. It defaults to :active_record_id.
7
+
8
+ ### 0.4.0
9
+
10
+ * (ihoka) Added #attributes method to FriendlyAttributes::Details base class.
11
+
4
12
  ### 0.3.2
5
13
 
6
14
  * (ihoka) Added description to spec matcher.
@@ -3,9 +3,14 @@ module FriendlyAttributes
3
3
  def friendly_details(*args, &block)
4
4
  klass = args.shift
5
5
  options = args.extract_options!
6
+ attributes = args.extract_options!
7
+ if attributes.empty?
8
+ attributes = options
9
+ options = {}
10
+ end
6
11
 
7
12
  delegate_options = proc {
8
- options.each do |key, value|
13
+ attributes.each do |key, value|
9
14
  if Array === value
10
15
  value.each { |v| delegated_attribute v, key }
11
16
  else
@@ -14,7 +19,7 @@ module FriendlyAttributes
14
19
  end
15
20
  }
16
21
 
17
- DetailsDelegator.new(klass, self, &block).tap do |dd|
22
+ DetailsDelegator.new(klass, self, options, &block).tap do |dd|
18
23
  dd.instance_eval(&delegate_options)
19
24
  end
20
25
  end
@@ -2,7 +2,7 @@ module FriendlyAttributes
2
2
  class Details
3
3
  class << self
4
4
  def find_or_build_by_active_record_id(active_record_id)
5
- active_record_id && first(:active_record_id => active_record_id) || new(:active_record_id => active_record_id)
5
+ active_record_id && first(active_record_key => active_record_id) || new(active_record_key => active_record_id)
6
6
  end
7
7
  end
8
8
 
@@ -4,16 +4,21 @@ module FriendlyAttributes
4
4
 
5
5
  delegate :attribute, :indexes, :to => :friendly_model
6
6
 
7
- def initialize(friendly_model, ar_model, &block)
7
+ def initialize(friendly_model, ar_model, options={}, &block)
8
8
  @ar_model = ar_model
9
9
  @friendly_model = friendly_model
10
10
 
11
+ _active_record_key = options.delete(:active_record_key) || :active_record_id
12
+
11
13
  friendly_model.instance_eval do
12
14
  include Friendly::Document
13
-
14
- attribute :active_record_id, Integer
15
- indexes :active_record_id
15
+
16
+ attribute _active_record_key, Integer
17
+ indexes _active_record_key
18
+
19
+ cattr_accessor :active_record_key
16
20
  end
21
+ friendly_model.active_record_key = _active_record_key
17
22
 
18
23
  ar_model.class_eval do
19
24
  cattr_accessor :friendly_model
@@ -14,7 +14,7 @@ module FriendlyAttributes
14
14
 
15
15
  def update_friendly_details
16
16
  return unless details_present?
17
- details.active_record_id = id unless details.active_record_id == id
17
+ details.send(:"#{details.active_record_key}=", id) unless details.send(details.active_record_key) == id
18
18
  details.save if details.changed?
19
19
  end
20
20
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly-attributes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Istvan Hoka
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-25 00:00:00 +02:00
18
+ date: 2010-11-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency