amfetamine 0.2.7 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use ruby-1.9.3-p0
1
+ rvm use ruby-1.9.3-p125
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 0.2.8
2
+ - Attributes are now set dynamically. This OVERIDES anything you set on 'amfetamine_attributes'. This should reduce a lot of bloat.
@@ -59,6 +59,21 @@ module Amfetamine
59
59
  end
60
60
  end
61
61
 
62
+ # Sets attributes dynamically
63
+ def set_dynamic_attributes(attrs = [])
64
+ klass = class << self;self end # Get reference to eigenklass
65
+
66
+ attrs.each do |attr|
67
+ klass.send(:define_method, "#{attr}=") do |arg|
68
+ @attributes[attr.to_s] = arg
69
+ end
70
+
71
+ klass.send(:define_method, "#{attr}") do
72
+ @attributes[attr.to_s]
73
+ end
74
+ end
75
+ end
76
+
62
77
  def self.amfetamine_configure(hash)
63
78
  hash.each do |k,v|
64
79
  self.send("#{k.to_s}=", v)
@@ -99,6 +114,7 @@ module Amfetamine
99
114
  def initialize(args={})
100
115
  super
101
116
  @attributes = {}
117
+ self.set_dynamic_attributes(args.keys)
102
118
  self.cache_key = self.class.recent_cache_key # Shows how this object was retrieved from cache
103
119
  args.each { |k,v| self.send("#{k}=", v) }
104
120
  @notsaved = true
@@ -1,3 +1,3 @@
1
1
  module Amfetamine
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.9"
3
3
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ # Let's create a new class for our experiments
4
+ class Dummy2 < Amfetamine::Base
5
+ def initialize(args={})
6
+ @@children << self
7
+ super(args)
8
+ end
9
+
10
+ def self.children
11
+ @@children ||= []
12
+ end
13
+ end
14
+
15
+ describe "Dynamic Attributes" do
16
+ let(:dummy) {build(:dummy2)}
17
+
18
+ it "should set attributes dynamically" do
19
+ Dummy2.prevent_external_connections! do |r|
20
+ r.get {dummy}
21
+ dummy.should respond_to(:title=)
22
+ dummy.should respond_to(:title)
23
+ dummy.should respond_to(:description=)
24
+ dummy.should respond_to(:description)
25
+ end
26
+ end
27
+ end
28
+
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,9 @@ require 'json'
19
19
  def build(object)
20
20
  {
21
21
  :dummy => lambda { Dummy.new({:title => 'Dummy', :description => 'Crash me!', :id => Dummy.children.length + 1})},
22
- :child => lambda { Child.new({:title => 'Child', :description => 'Daddy!', :id => Child.children.length + 1}) }
22
+ :child => lambda { Child.new({:title => 'Child', :description => 'Daddy!', :id => Child.children.length + 1}) },
23
+ :dummy2 => lambda { Dummy2.new({:title => 'Dummy2', :description => 'Daddy!', :id => Dummy2.children.length + 1}) }
24
+
23
25
  }[object].call
24
26
  end
25
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amfetamine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-05 00:00:00.000000000 Z
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70146243904100 !ruby/object:Gem::Requirement
16
+ requirement: &70289859075780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70146243904100
24
+ version_requirements: *70289859075780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard
27
- requirement: &70146243903420 !ruby/object:Gem::Requirement
27
+ requirement: &70289859098680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70146243903420
35
+ version_requirements: *70289859098680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard-rspec
38
- requirement: &70146243902840 !ruby/object:Gem::Requirement
38
+ requirement: &70289859096520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70146243902840
46
+ version_requirements: *70289859096520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ruby_gntp
49
- requirement: &70146243902160 !ruby/object:Gem::Requirement
49
+ requirement: &70289859094680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70146243902160
57
+ version_requirements: *70289859094680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: httparty
60
- requirement: &70146243901740 !ruby/object:Gem::Requirement
60
+ requirement: &70289859121340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70146243901740
68
+ version_requirements: *70289859121340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
- requirement: &70146243901320 !ruby/object:Gem::Requirement
71
+ requirement: &70289859116520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70146243901320
79
+ version_requirements: *70289859116520
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &70146243900880 !ruby/object:Gem::Requirement
82
+ requirement: &70289859126980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70146243900880
90
+ version_requirements: *70289859126980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: simplecov-rcov
93
- requirement: &70146243900460 !ruby/object:Gem::Requirement
93
+ requirement: &70289859143560 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70146243900460
101
+ version_requirements: *70289859143560
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: dalli
104
- requirement: &70146243900040 !ruby/object:Gem::Requirement
104
+ requirement: &70289859157120 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70146243900040
112
+ version_requirements: *70289859157120
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: activesupport
115
- requirement: &70146243899620 !ruby/object:Gem::Requirement
115
+ requirement: &70289859201020 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70146243899620
123
+ version_requirements: *70289859201020
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: activemodel
126
- requirement: &70146243899200 !ruby/object:Gem::Requirement
126
+ requirement: &70289859196160 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *70146243899200
134
+ version_requirements: *70289859196160
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: json
137
- requirement: &70146243915160 !ruby/object:Gem::Requirement
137
+ requirement: &70289859209260 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *70146243915160
145
+ version_requirements: *70289859209260
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rake
148
- requirement: &70146243914740 !ruby/object:Gem::Requirement
148
+ requirement: &70289859230280 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :runtime
155
155
  prerelease: false
156
- version_requirements: *70146243914740
156
+ version_requirements: *70289859230280
157
157
  description: Wraps REST to objects, provides caching and makes your app go Bzzz!
158
158
  email:
159
159
  - timon@exvo.com
@@ -164,6 +164,7 @@ files:
164
164
  - .gitignore
165
165
  - .rspec
166
166
  - .rvmrc
167
+ - CHANGELOG
167
168
  - Gemfile
168
169
  - README.md
169
170
  - Rakefile
@@ -187,6 +188,7 @@ files:
187
188
  - spec/amfetamine/callbacks_spec.rb
188
189
  - spec/amfetamine/conditions_spec.rb
189
190
  - spec/amfetamine/dummy_spec.rb
191
+ - spec/amfetamine/dynamic_attributes_spec.rb
190
192
  - spec/amfetamine/relationships_spec.rb
191
193
  - spec/amfetamine/rest_helpers_spec.rb
192
194
  - spec/amfetamine/rspec_matchers_spec.rb
@@ -210,15 +212,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
210
212
  - - ! '>='
211
213
  - !ruby/object:Gem::Version
212
214
  version: '0'
215
+ segments:
216
+ - 0
217
+ hash: -352518428123018875
213
218
  required_rubygems_version: !ruby/object:Gem::Requirement
214
219
  none: false
215
220
  requirements:
216
221
  - - ! '>='
217
222
  - !ruby/object:Gem::Version
218
223
  version: '0'
224
+ segments:
225
+ - 0
226
+ hash: -352518428123018875
219
227
  requirements: []
220
228
  rubyforge_project: amfetamine
221
- rubygems_version: 1.8.10
229
+ rubygems_version: 1.8.16
222
230
  signing_key:
223
231
  specification_version: 3
224
232
  summary: Wraps REST to objects
@@ -228,6 +236,7 @@ test_files:
228
236
  - spec/amfetamine/callbacks_spec.rb
229
237
  - spec/amfetamine/conditions_spec.rb
230
238
  - spec/amfetamine/dummy_spec.rb
239
+ - spec/amfetamine/dynamic_attributes_spec.rb
231
240
  - spec/amfetamine/relationships_spec.rb
232
241
  - spec/amfetamine/rest_helpers_spec.rb
233
242
  - spec/amfetamine/rspec_matchers_spec.rb
@@ -239,4 +248,3 @@ test_files:
239
248
  - spec/helpers/active_model_lint.rb
240
249
  - spec/helpers/fakeweb_responses.rb
241
250
  - spec/spec_helper.rb
242
- has_rdoc: