opto-model 0.1.1 → 0.2.0

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: d7c83427e75851b3d86750010b5b8f3ffffc81c8
4
- data.tar.gz: 9a231b97d7c15fe3aa59592b0b511d5d79faefc0
3
+ metadata.gz: f80b35c3e68b4b6e9043dfdfeb74ca859467149f
4
+ data.tar.gz: 27c341eb48634ce7e5955ba609d09b5783158a91
5
5
  SHA512:
6
- metadata.gz: 5a01e85569e88ef783986e3eab9ba32fff3705413ab903bf0fff8e54778bc91840da6af6d26fe4592a001dcf4dc0433995587d0416f3e37a630424f8a75d53e8
7
- data.tar.gz: 34aa891072f587807d09852345eab957d03466d79c9ae22451b9b42f25c289db6f9eaa21c639f548cdace75170115e9978371207b130b373ead8a26c4ae70ef0
6
+ metadata.gz: 3af9c69f9aeec0d50bc9ef8d07a2d61932622655902e62c9d89ebf4705cf55478e565da23fab470d50fbbbb1284d00d9816d0fdd955f4a38230594ced2790e0e
7
+ data.tar.gz: b4b11b52c17ed4039779f9760e557f4ac620659bafff3e9881b234fd85789d1779032e959a0bd806e9e84af533f8054d463d90f914233e1cf2210fee511484ea
data/.travis.yml CHANGED
@@ -5,7 +5,7 @@ rvm:
5
5
  - 2.2.3
6
6
  - 2.3.1
7
7
  - 2.3.3
8
- - 2.4.0-preview3
8
+ - 2.4.0
9
9
  - jruby-9.1.5.0
10
10
  env:
11
11
  - secure: "l6a3qDbzbCGmVuIcIq2n5rOCUztdumytt4mK/TkUIcCv36ZfYSlF1uWgFfPGg1vPsVFn6bexBL09/7RGMJl4iVyorluOJiwMxKixuOes6VHfuoi/fqW3yxFXL4tdWscAN6HfUtbCByxiH6BnbEKRuhr/C/crhNkZDnsT9GdBVOep9xYJ3L5T9cjWbceH1wk8+8i4OuchMwXPyh5Ybf3KsRqebN+IACSQW64OAgyYIncGVPOobo7Wm7/aNT/rN6MuA7gB9r4QWg17kbeP3V6Rc/G0R1P8vlJg7vq4tHMvEmuFtGF2UTAxQV8/C1AWrfdwonG3GWd0kFT8MDCW+vXvwavsiS5Ke5O7IvXqyhb0HzKTGVB3WqyQNJEVaCaHW+0JRO3mijVQFTfqfAScSF1nDpYsNkX0RhO8El58cNDPG8JcR8TMDyOIH/qbcF9RDNE3n/Es/QaTk8j+5ZTZffTFLQ+LogEnBRa3xUeb8FX23gmTk8a7sfkNpuQ9eRxl7nCCFBYWoe9viBpUsXiuGw1O+gSQAQjV/BcTopMLU6mpIf+1hLu5lUe+9mFvpzlyfXO+t8C7c9AF8g5h4lUPG/P5NsfS5OOWURxguIsBicaNro/D4S+HTQ+A47q9vy5vzIa05vYZ0rXYzczZs6J0ffSXN0Ns0h+L35s36TuXazHdGbY="
@@ -37,6 +37,16 @@ module Opto
37
37
  end
38
38
  end
39
39
  self.send(relation).members
40
+ elsif args.kind_of?(Hash)
41
+ self.send(relation).clear
42
+ args.each do |k,v|
43
+ if v.kind_of?(Hash)
44
+ self.send(relation).new(k => v)
45
+ else
46
+ raise TypeError, "Expected an instance of Hash"
47
+ end
48
+ end
49
+ self.send(relation).members
40
50
  elsif args.nil?
41
51
  self.send(relation).clear
42
52
  else
@@ -8,7 +8,8 @@ module Opto
8
8
  extend Forwardable
9
9
 
10
10
  def initialize(parent, target_class, as, options = {})
11
- @parent, @target_class, @as, @options = parent, target_class, as, options
11
+ @parent, @target_class, @as = parent, target_class, as
12
+ @options = { key_is: :name }.merge(options)
12
13
  @members = []
13
14
  end
14
15
 
@@ -33,6 +34,10 @@ module Opto
33
34
  end
34
35
 
35
36
  def new(*args)
37
+ if args.first.kind_of?(Hash) && args.size == 1 && args.first[args.first.keys.first].kind_of?(Hash)
38
+ key = args.first.keys.first
39
+ args = [args.first[key].merge(options[:key_is] => key.kind_of?(Symbol) ? key.to_s : key)]
40
+ end
36
41
  target = target_class.new(*args)
37
42
  members << target
38
43
  target
@@ -52,7 +57,7 @@ module Opto
52
57
  result.empty? ? {} : { as => result }
53
58
  end
54
59
 
55
- def_delegators :members, *::Array.instance_methods - [:__send__, :object_id, :to_h]
60
+ def_delegators :members, *::Array.instance_methods - [:__send__, :object_id, :to_h, :__id__]
56
61
  end
57
62
  end
58
63
  end
@@ -8,7 +8,8 @@ module Opto
8
8
  extend Forwardable
9
9
 
10
10
  def initialize(parent, target_class, as, target = nil, options = {})
11
- @parent, @target_class, @as, @target, @options = parent, target_class, as, target, options
11
+ @parent, @target_class, @as, @target = parent, target_class, as, target
12
+ @options = { key_is: :name }.merge(options)
12
13
  end
13
14
 
14
15
  def association_errors
@@ -32,6 +33,10 @@ module Opto
32
33
  end
33
34
 
34
35
  def new(*args)
36
+ if args.first.kind_of?(Hash) && args.size == 1 && args.first[args.first.keys.first].kind_of?(Hash)
37
+ key = args.first.keys.first
38
+ args = [args.first[key].merge(options[:key_is] => key.kind_of?(Symbol) ? key.to_s : key)]
39
+ end
35
40
  @target = target_class.new(*args)
36
41
  end
37
42
 
@@ -1,5 +1,5 @@
1
1
  module Opto
2
2
  module Model
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opto-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kimmo Lehto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler