vending-machine 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/vend/resource.rb CHANGED
@@ -10,9 +10,9 @@ module Vend
10
10
 
11
11
  alias_method :initialize_virtus, :initialize
12
12
  def initialize attributes={}
13
- if attributes[:store_object]
14
- @store = store_object
15
- end
13
+ current_attribute_set = attribute_set
14
+ self.extend(Virtus)
15
+ attribute_set.merge(current_attribute_set)
16
16
  initialize_virtus attributes
17
17
  end
18
18
 
@@ -33,5 +33,36 @@ module Vend
33
33
  order_direction direction
34
34
  end
35
35
 
36
+ ##
37
+ # Instance Methods
38
+ def build_variant attributes = {}
39
+ unless attributes[:sku]
40
+ # Increment or Append to sku
41
+ attributes[:sku] = (
42
+ sku.match(/[\d]+$/) ?
43
+ sku.gsub(/[\d]+$/){|match| match.to_i + 1} :
44
+ sku + '-1'
45
+ )
46
+ end
47
+
48
+ attributes[:handle] = handle unless attributes[:handle]
49
+
50
+ new_attributes = attributes.dup.delete_if do |attribute, value|
51
+ %w{ created_at updated_at id }.include?(attribute)
52
+ end.merge attributes
53
+
54
+ new_attributes[:store] = store
55
+
56
+ self.class.new new_attributes
57
+ end
58
+
59
+ def create_variant sku
60
+ build_variant(sku).save
61
+ end
62
+
63
+ def create_variant! sku
64
+ build_variant(sku).save!
65
+ end
66
+
36
67
  end
37
68
  end
data/lib/vend/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vend
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vending-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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: 2012-12-15 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday