acts_as_elibri_product 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,16 +32,16 @@ In this case, you should use array, where first element is name of elibri attrib
32
32
  Example:
33
33
  ```ruby
34
34
  {
35
- :title => [:title, lambda {|x| Logger.info("changing title"); return "#{x}_test"}]
35
+ :title => [:title, lambda {|product, value| Logger.info("changing title"); return "#{x}_test"}]
36
36
  }
37
37
 
38
- Important thing is that lambda need to take exactly one argument, and need to return final value of attribute to write into database.
38
+ Important thing is that lambda need to take exactly two arguments (first one will be product that are updating / creating right now, second will be value of field), and need to return final value of attribute to write into database.
39
39
  Also very important thing is that lambdas are now supported only on first level of vector (not in embedded hashes).
40
40
 
41
41
  If you want to use lambda, but don't write anything to database, you should use nil as first attribute in array. For example:
42
42
  ```ruby
43
43
  {
44
- :title => [nil, lambda {|x| Logger.info("changing title"); return "#{x}_test"}]
44
+ :title => [nil, lambda {|product, value| Logger.info("changing title") } ]
45
45
  }
46
46
 
47
47
  When dealing with embedded objects and relations, you should use embedded hashes:
@@ -44,9 +44,9 @@ module ActsAsElibriProduct
44
44
  ActsAsElibriProduct.set_objects_from_array(k, v.keys.first, v.values.first, product.send(k), db_product) if product.send(k)
45
45
  elsif v.is_a?(Array)
46
46
  if v[0].nil?
47
- v[1].call(product.send(k))
47
+ v[1].call(db_product, product.send(k))
48
48
  else
49
- db_product.send(:write_attribute, v[0], v[1].call(product.send(k)))
49
+ db_product.send(:write_attribute, v[0], v[1].call(db_product, product.send(k)))
50
50
  end
51
51
  end
52
52
  end
@@ -97,9 +97,9 @@ module ActsAsElibriProduct
97
97
  if traverse_vector[change].is_a?(Array)
98
98
  next unless check_policy_chain(self, :product, traverse_vector[change], self.send(traverse_vector[change][0]), product_updated.send(change))
99
99
  if traverse_vector[change][0].nil?
100
- traverse_vector[change][1].call(product_updated.send(change))
100
+ traverse_vector[change][1].call(self, product_updated.send(change))
101
101
  else
102
- write_attribute(traverse_vector[change][0], traverse_vector[change][1].call(product_updated.send(change)))
102
+ write_attribute(traverse_vector[change][0], traverse_vector[change][1].call(self, product_updated.send(change)))
103
103
  end
104
104
  else
105
105
  next unless check_policy_chain(self, :product, traverse_vector[change], self.send(traverse_vector[change]), product_updated.send(change))
@@ -116,9 +116,9 @@ module ActsAsElibriProduct
116
116
  if v.is_a?(Array)
117
117
  next unless check_policy_chain(self, traverse_vector[change.keys.first].keys.first, db_attrib, object.send(db_attrib), elibri_object.send(v[0]))
118
118
  if v[0].nil?
119
- v[1].call(elibri_object.send(v[0]))
119
+ v[1].call(elibri_object.send(object, v[0]))
120
120
  else
121
- object.send(:write_attribute, db_attrib, v[1].call(elibri_object.send(v[0])))
121
+ object.send(:write_attribute, db_attrib, v[1].call(object, elibri_object.send(v[0])))
122
122
  end
123
123
  else
124
124
  next unless check_policy_chain(self, traverse_vector[change.keys.first].keys.first, db_attrib, object.send(db_attrib), elibri_object.send(v))
@@ -1,3 +1,3 @@
1
1
  module ActsAsElibriProduct
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_elibri_product
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Piotr Szmielew
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-17 00:00:00 Z
18
+ date: 2012-05-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails