tracks-attributes 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
  [![Build Status](https://travis-ci.org/leopoldodonnell/tracks-attributes.png?branch=master)](https://travis-ci.org/leopoldodonnell/tracks-attributes)
3
3
  [![Dependency Status](https://gemnasium.com/leopoldodonnell/tracks-attributes.png)](https://gemnasium.com/leopoldodonnell/tracks-attributes)
4
4
  [![Code Climate](https://codeclimate.com/github/leopoldodonnell/tracks-attributes.png)](https://codeclimate.com/github/leopoldodonnell/tracks-attributes)
5
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/tracks-attributes.png)](http://badge.fury.io/rb/tracks-attributes)
6
+
5
7
  # TracksAttributes
6
8
 
7
9
  TracksAttributes adds the ability to track ActiveRecord and Object level attributes.
@@ -11,6 +13,10 @@ needs to return JSON or XML. This module extends ActiveRecord::Base with the *tr
11
13
  been called the class is extended with the ability to track attributes through *attr_accessor*, *attr_reader*, and *attr_writer*.
12
14
  Plain old Ruby classes may also use *TracksAttributes* by including it as a module first.
13
15
 
16
+ *Note:* The necessity for this gem is born out of the clash between ActiveRecord attribute handling and PORO attributes. Using
17
+ Object#instance_variables just doesn't return the correct list for marshaling data effectively, nor produce values for computed
18
+ attributes.
19
+
14
20
  ## Enhanced JSON and XML processing
15
21
 
16
22
  Beyond the ability to track your attributes, this gem simplifies your use of converting your objects to an from JSON or XML.
@@ -40,13 +46,19 @@ puts "#{fred2.name} loves #{fred2.favorite_food}"
40
46
  Both the JSON and XML take the same options as their Hash and ActiveRecord counterparts so you can still
41
47
  use *:only* and *:includes* in your code as needed.
42
48
 
49
+ ### Current Limitations
50
+
51
+ If you have a nested set of classes they will still appear as attributes that are Hashes. I hope to
52
+ resolve this in an upcoming version.
53
+
43
54
  ## Add Validations To Non Active Record Attributes
44
55
 
45
56
  To add ActiveModel::Validations to your class just initialize your class with *tracks_attributes* as
46
57
 
47
58
  ```ruby
48
59
  tracks_attributes :validates => true
49
- ```
60
+ ```
61
+
50
62
  ## Installation
51
63
 
52
64
  Add the following to your Gemfile
@@ -1,3 +1,3 @@
1
1
  module TracksAttributes
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -74,7 +74,8 @@ module TracksAttributes
74
74
 
75
75
  # Return a hash all of the accessor symbols and their values
76
76
  def all_attributes
77
- attributes.merge Hash[accessors.collect {|v| [v, send(v.to_s)] if respond_to? "#{v}".to_sym}]
77
+ the_attrs = Hash[accessors.collect {|v| [v, send(v.to_s)] if respond_to? "#{v}".to_sym}]
78
+ (respond_to?(:attributes) && attributes.merge(the_attrs)) || the_attrs
78
79
  end
79
80
 
80
81
  # Set all attributes with hash of symbols and their values and returns instance
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracks-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails