logical_model 0.4.8 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,7 +3,8 @@ source "http://rubygems.org"
3
3
 
4
4
  gem "activemodel"
5
5
  gem "activesupport"
6
- gem "typhoeus", '0.5.1'
6
+ gem "typhoeus", '0.5.0.alpha'
7
+ gem "ethon", "0.4.2"
7
8
  gem "kaminari", '~> 0.13.0'
8
9
 
9
10
  group :development, :test do
@@ -27,7 +27,7 @@ GEM
27
27
  builder (3.0.0)
28
28
  diff-lcs (1.1.3)
29
29
  erubis (2.7.0)
30
- ethon (0.5.3)
30
+ ethon (0.4.2)
31
31
  ffi (~> 1.0.11)
32
32
  mime-types (~> 1.18)
33
33
  ffi (1.0.11)
@@ -50,7 +50,7 @@ GEM
50
50
  activesupport (>= 3.0.0)
51
51
  railties (>= 3.0.0)
52
52
  libnotify (0.7.1)
53
- mime-types (1.22)
53
+ mime-types (1.23)
54
54
  multi_json (1.0.4)
55
55
  rack (1.3.6)
56
56
  rack-cache (1.1)
@@ -100,8 +100,8 @@ GEM
100
100
  sqlite3 (>= 1.3.3)
101
101
  thor (0.14.6)
102
102
  tilt (1.3.3)
103
- typhoeus (0.5.1)
104
- ethon (= 0.5.3)
103
+ typhoeus (0.5.0.alpha)
104
+ ethon (~> 0.4.2)
105
105
  tzinfo (0.3.31)
106
106
 
107
107
  PLATFORMS
@@ -112,6 +112,7 @@ DEPENDENCIES
112
112
  activerecord
113
113
  activesupport
114
114
  bundler (~> 1.2.2)
115
+ ethon (= 0.4.2)
115
116
  gemcutter
116
117
  guard-rspec
117
118
  jeweler (~> 1.6.4)
@@ -124,4 +125,4 @@ DEPENDENCIES
124
125
  shoulda
125
126
  sinatra (~> 1.2.6)
126
127
  sqlite3-ruby
127
- typhoeus (= 0.5.1)
128
+ typhoeus (= 0.5.0.alpha)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.10
@@ -6,6 +6,7 @@ require 'logger'
6
6
  require 'kaminari'
7
7
  require 'ssl_support'
8
8
  require 'safe_log'
9
+ require 'logical_model/has_many_keys'
9
10
 
10
11
  # Logical Model, not persistant on DB, works through API. (replaces ActiveResource)
11
12
  #
@@ -46,6 +47,8 @@ class LogicalModel
46
47
  include SslSupport
47
48
  extend SafeLog
48
49
 
50
+ extend LogicalModel::HasManyKeys
51
+
49
52
  # include ActiveModel Modules that are usefull
50
53
  extend ActiveModel::Naming
51
54
  include ActiveModel::Conversion
@@ -123,70 +126,6 @@ class LogicalModel
123
126
  self.attributes = attributes
124
127
  end
125
128
 
126
- def self.has_many_keys=(keys)
127
- @has_many_keys = keys
128
- attr_accessor *keys
129
-
130
- keys.each do |association|
131
-
132
- # return empty array or @association variable for each association
133
- define_method association do
134
- if instance_variable_get("@#{association}").blank?
135
- instance_variable_set("@#{association}", [])
136
- end
137
-
138
- instance_variable_get("@#{association}")
139
- end
140
-
141
- # this method loads the contact attributes recieved by logical model from the service
142
- define_method "#{association}=" do |params|
143
- collection = []
144
- params.each do |attr_params|
145
- if attr_params["_type"].present?
146
- attr_class = attr_params.delete("_type").to_s.constantize
147
- else
148
- attr_class = association.to_s.singularize.camelize.constantize
149
- end
150
- collection << attr_class.new(attr_params)
151
- end
152
- instance_variable_set("@#{association}", collection)
153
- end
154
-
155
- define_method "new_#{association.to_s.singularize}" do |attr_params|
156
- if attr_params["_type"].present?
157
- clazz = attr_params.delete(:_type).constantize
158
- else
159
- clazz = association.to_s.singularize.camelize.constantize
160
- end
161
-
162
- return unless clazz
163
-
164
- temp_object = clazz.new(attr_params.merge({"#{self.json_root}_id" => self.id}))
165
- eval(association.to_s) << temp_object
166
- temp_object
167
- end
168
-
169
- # this method loads the contact attributes from the html form (using nested resources conventions)
170
- define_method "#{association}_attributes=" do |key_attributes|
171
- array = []
172
- key_attributes.each do |attr_params|
173
- attr_params.to_hash.symbolize_keys!
174
- if attr_params["_type"].present?
175
- attr_class = attr_params.delete("_type").to_s.constantize
176
- else
177
- attr_class = association.to_s.singularize.camelize.constantize
178
- end
179
- array << attr_class.new(attr_params)
180
- end
181
- instance_variable_set("@#{association}", array)
182
- end
183
- end
184
- end
185
-
186
- def self.has_many_keys
187
- @has_many_keys
188
- end
189
-
190
129
  def attributes
191
130
  attrs = self.class.attribute_keys.inject(ActiveSupport::HashWithIndifferentAccess.new) do |result,key|
192
131
  result[key] = read_attribute_for_validation(key)
@@ -0,0 +1,69 @@
1
+ class LogicalModel
2
+ module HasManyKeys
3
+
4
+ def has_many_keys=(keys)
5
+ @has_many_keys = keys
6
+ attr_accessor *keys
7
+
8
+ keys.each do |association|
9
+
10
+ # return empty array or @association variable for each association
11
+ define_method association do
12
+ if instance_variable_get("@#{association}").blank?
13
+ instance_variable_set("@#{association}", [])
14
+ end
15
+
16
+ instance_variable_get("@#{association}")
17
+ end
18
+
19
+ # this method loads the contact attributes recieved by logical model from the service
20
+ define_method "#{association}=" do |params|
21
+ collection = []
22
+ params.each do |attr_params|
23
+ if attr_params["_type"].present?
24
+ attr_class = attr_params.delete("_type").to_s.constantize
25
+ else
26
+ attr_class = association.to_s.singularize.camelize.constantize
27
+ end
28
+ collection << attr_class.new(attr_params)
29
+ end
30
+ instance_variable_set("@#{association}", collection)
31
+ end
32
+
33
+ define_method "new_#{association.to_s.singularize}" do |attr_params|
34
+ if attr_params["_type"].present?
35
+ clazz = attr_params.delete(:_type).constantize
36
+ else
37
+ clazz = association.to_s.singularize.camelize.constantize
38
+ end
39
+
40
+ return unless clazz
41
+
42
+ temp_object = clazz.new(attr_params.merge({"#{self.json_root}_id" => self.id}))
43
+ eval(association.to_s) << temp_object
44
+ temp_object
45
+ end
46
+
47
+ # this method loads the contact attributes from the html form (using nested resources conventions)
48
+ define_method "#{association}_attributes=" do |key_attributes|
49
+ array = []
50
+ key_attributes.each do |attr_params|
51
+ attr_params.to_hash.symbolize_keys!
52
+ if attr_params["_type"].present?
53
+ attr_class = attr_params.delete("_type").to_s.constantize
54
+ else
55
+ attr_class = association.to_s.singularize.camelize.constantize
56
+ end
57
+ array << attr_class.new(attr_params)
58
+ end
59
+ instance_variable_set("@#{association}", array)
60
+ end
61
+ end
62
+ end
63
+
64
+ def has_many_keys
65
+ @has_many_keys
66
+ end
67
+
68
+ end
69
+ end
@@ -3,9 +3,9 @@ module SafeLog
3
3
  # Filters api_key
4
4
  # @return [String]
5
5
  def mask_api_key(str)
6
- if use_api_key && api_key && str
6
+ if use_api_key && str
7
7
  str = str.gsub(api_key,'[SECRET]')
8
8
  end
9
9
  str
10
10
  end
11
- end
11
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "logical_model"
8
- s.version = "0.4.8"
8
+ s.version = "0.4.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dwayne Macgowan"]
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "db/development.sqlite3",
33
33
  "db/migrate/001_create_users.rb",
34
34
  "lib/logical_model.rb",
35
+ "lib/logical_model/has_many_keys.rb",
35
36
  "lib/safe_log.rb",
36
37
  "lib/ssl_support.rb",
37
38
  "lib/typhoeus_fix/array_decoder.rb",
@@ -54,7 +55,8 @@ Gem::Specification.new do |s|
54
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
56
  s.add_runtime_dependency(%q<activemodel>, [">= 0"])
56
57
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
57
- s.add_runtime_dependency(%q<typhoeus>, ["= 0.5.1"])
58
+ s.add_runtime_dependency(%q<typhoeus>, ["= 0.5.0.alpha"])
59
+ s.add_runtime_dependency(%q<ethon>, ["= 0.4.2"])
58
60
  s.add_runtime_dependency(%q<kaminari>, ["~> 0.13.0"])
59
61
  s.add_development_dependency(%q<activerecord>, [">= 0"])
60
62
  s.add_development_dependency(%q<shoulda>, [">= 0"])
@@ -72,7 +74,8 @@ Gem::Specification.new do |s|
72
74
  else
73
75
  s.add_dependency(%q<activemodel>, [">= 0"])
74
76
  s.add_dependency(%q<activesupport>, [">= 0"])
75
- s.add_dependency(%q<typhoeus>, ["= 0.5.1"])
77
+ s.add_dependency(%q<typhoeus>, ["= 0.5.0.alpha"])
78
+ s.add_dependency(%q<ethon>, ["= 0.4.2"])
76
79
  s.add_dependency(%q<kaminari>, ["~> 0.13.0"])
77
80
  s.add_dependency(%q<activerecord>, [">= 0"])
78
81
  s.add_dependency(%q<shoulda>, [">= 0"])
@@ -91,7 +94,8 @@ Gem::Specification.new do |s|
91
94
  else
92
95
  s.add_dependency(%q<activemodel>, [">= 0"])
93
96
  s.add_dependency(%q<activesupport>, [">= 0"])
94
- s.add_dependency(%q<typhoeus>, ["= 0.5.1"])
97
+ s.add_dependency(%q<typhoeus>, ["= 0.5.0.alpha"])
98
+ s.add_dependency(%q<ethon>, ["= 0.4.2"])
95
99
  s.add_dependency(%q<kaminari>, ["~> 0.13.0"])
96
100
  s.add_dependency(%q<activerecord>, [">= 0"])
97
101
  s.add_dependency(%q<shoulda>, [">= 0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logical_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.5.1
53
+ version: 0.5.0.alpha
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,23 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.1
61
+ version: 0.5.0.alpha
62
+ - !ruby/object:Gem::Dependency
63
+ name: ethon
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.4.2
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.2
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: kaminari
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -307,6 +323,7 @@ files:
307
323
  - db/development.sqlite3
308
324
  - db/migrate/001_create_users.rb
309
325
  - lib/logical_model.rb
326
+ - lib/logical_model/has_many_keys.rb
310
327
  - lib/safe_log.rb
311
328
  - lib/ssl_support.rb
312
329
  - lib/typhoeus_fix/array_decoder.rb
@@ -331,7 +348,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
331
348
  version: '0'
332
349
  segments:
333
350
  - 0
334
- hash: 365014127
351
+ hash: -711400131
335
352
  required_rubygems_version: !ruby/object:Gem::Requirement
336
353
  none: false
337
354
  requirements: