embark-journey 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4686df29e65a3ebc8fac2f42b1323cfa15ec0599
4
- data.tar.gz: 4328300152c187737623cc8fd2d79bab78647bdb
3
+ metadata.gz: e3998c199ed52d9b9c1c18b8a232a3448588b039
4
+ data.tar.gz: 837e0d85bf8f77bc7dac887f43143ff38580ef8d
5
5
  SHA512:
6
- metadata.gz: 3eb44d831384d966eac83eea6a56bb3ce96bddd37a9aca8c6c91fdfc210eeb27e74aee166b5ddda1755b38609ca04171105677c7688ee44641cca12b3a1e87bf
7
- data.tar.gz: 6f1d3487bfdbdcd3ed5410a78a280159843a81e09730b69dba21d1c30a7c9d7faf0ad30f3a2fbc34ae98a4bdf19771813fccbec04ca064c5a2fb682b66a7873e
6
+ metadata.gz: 50afca97c3f70db7b65c98599441f5c7566e051511a39771228dde204e3c26b08ddb82bea5dc852a75a17e9069597a5a7b0d9c6fd4b2eecd438b4aa708d5ab5e
7
+ data.tar.gz: 77efa8e28f9da152bdcccea89fd400df1cd15f1f1687901aa7528cd6c67cafe7e77f5c1b3d1b9415fbfa0e167b640c1f1df743bc158c683c888b960d58a51670
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --format documentation
@@ -7,9 +7,18 @@ module Journey::Resource::AttributeLoading
7
7
  def load(attributes, remove_root = false, persisted = false)
8
8
  # 'data' is a reserved key in ActiveResource,
9
9
  # but Journey uses it for the Oplog
10
-
11
10
  attributes['content'] = attributes.delete('data')
12
- super(attributes, remove_root, persisted)
11
+
12
+ super(attributes, remove_root, persisted).tap do
13
+
14
+ # allow enum_sets to be loaded by key (rather than index)
15
+ # by auto-converting them on initialization
16
+ if enum_sets = self.class.instance_variable_get(:@enum_sets)
17
+ enum_sets.each do |enum_attr|
18
+ send("#{enum_attr}=", send(enum_attr))
19
+ end
20
+ end
21
+ end
13
22
  end
14
23
  end
15
24
 
@@ -5,8 +5,11 @@ module Journey::Resource::EnumSets
5
5
 
6
6
  included do
7
7
  def self.enum_set(attr, collection=[])
8
+ (@enum_sets ||= []) << attr
9
+
8
10
  collection_const_name = attr.to_s.pluralize.upcase.to_sym
9
- const_set collection_const_name, collection.freeze
11
+ const_set collection_const_name, collection.freeze
12
+
10
13
  define_method "#{attr}_values" do
11
14
  self.class.const_get(collection_const_name)
12
15
  end
@@ -22,6 +25,16 @@ module Journey::Resource::EnumSets
22
25
  end
23
26
  end
24
27
 
28
+ define_method "#{attr}=" do |value|
29
+ attributes[attr.to_s] = value.map do |member|
30
+ if member.is_a?(Fixnum)
31
+ member
32
+ else
33
+ self.class.const_get(collection_const_name).index(member)
34
+ end
35
+ end
36
+ end
37
+
25
38
  define_method "add_#{attr}" do |value|
26
39
  attr_values = send("#{attr}_values")
27
40
 
@@ -34,7 +47,7 @@ module Journey::Resource::EnumSets
34
47
  if (0..attr_values.size-1).include? value_index
35
48
  (attributes[attr.to_s] ||= []) << value_index
36
49
  else
37
- raise "Invalid enum '#{value}' for '#{attr}'"
50
+ raise "Invalid enum_set value: '#{value}' for '#{attr}'"
38
51
  end
39
52
  end
40
53
  end
@@ -4,7 +4,7 @@ module Journey::Resource::Search
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- def self.search(q)
7
+ def self.search(q) # TODO add opts here
8
8
  instantiate_collection format.decode(post(:search, q: q).body)
9
9
  end
10
10
  end
@@ -2,7 +2,7 @@ module Journey
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 17
5
+ TINY = 18
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
8
8
  end
@@ -80,15 +80,16 @@ describe Journey::Resource do
80
80
  r = klass.create(name: 'X')
81
81
  expect(r).to be_persisted
82
82
  r.asset_type = ['ATM']
83
- r.save
83
+ expect(r.save).to be true
84
+
84
85
  r = klass.find(r.id)
85
- expect(r.asset_type).to eq(['ATM'])
86
+ expect(r.asset_type).to eq ['ATM']
86
87
  end
87
88
 
88
- it 'remembers enum values' do
89
- r = klass.create(name: 'X', asset_type: ['ATM', 'ABM'])
89
+ it 'remembers enum_set values' do
90
+ r = klass.create(name: 'X', asset_type: ['ABM', 'ATM'])
90
91
  r = klass.find(r.id)
91
- expect(r.asset_type).to eq ['ATM', 'ABM']
92
+ expect(r.asset_type).to eq ['ABM', 'ATM']
92
93
  end
93
94
 
94
95
  it 'defaults to empty array' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embark-journey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Davey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-24 00:00:00.000000000 Z
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr