flowlink_data 0.2.1 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f85858abd782c8abbc8cc23f5e5ae06dad6e7ccd
4
- data.tar.gz: 1f2a112880bc727d5ee8e506a2ac2389200ff72f
3
+ metadata.gz: 69925cf26513fecb4c9d171e95fdbeff97f83073
4
+ data.tar.gz: 606610ac873e22d40503da6c6481e1bcc2e73640
5
5
  SHA512:
6
- metadata.gz: 591c1843a8b82b511da748b6635624bd0a2210416a4d6a1247f8dee9c469cda61d8cbb43c03b3bb9026df537aa7731ffbd7a8843b8f47985e085f887202b9eb3
7
- data.tar.gz: 9872e362b0618108c778b87d07fdc27471c864887aec6418cfa0785bfadfe23a2963818af788ca70d1a73f61e048bec8c69ffb666a012225be72c4603ba1eca4
6
+ metadata.gz: 062f10a60be77181135c17995fa6d4041f99f8b2fdb1d4155e232b3a35a65d0a0a7a4777be7199670fed660c511c2180adeb48c8c47aeec70453dbe0bbbf9f09
7
+ data.tar.gz: 37ce125cd1402571358075770623f4b96ad41b8240a13a5a3d832702a8945d1794d6c9be7526862017ab4365eaffa1dddbc58ff2690fac3d00c0acefc2fc2de1
@@ -1,5 +1,5 @@
1
1
  class FieldMethod
2
- attr_accessor :method_name, :args
2
+ attr_reader :method_name, :args, :block
3
3
 
4
4
  def self.multi_new(methods)
5
5
  methods.map do |m|
@@ -13,11 +13,15 @@ class FieldMethod
13
13
  end
14
14
 
15
15
  def initialize(method_name, *args)
16
- @method_name = method_name.to_sym
17
- @args = args.to_a.flatten
16
+ @method_name = method_name.to_sym
17
+ @args = args.to_a.flatten
18
+ @block, @args = @args.partition { |arg| arg.is_a? Proc }
19
+ @block = @block[0]
18
20
  end
19
21
 
20
22
  def merge(list)
23
+ # This will put itself into a list of other FieldMethods and overwrite
24
+ # an existing FM with the same name
21
25
  list.delete_if { |o_fm| o_fm.method_name == method_name }
22
26
  list << self
23
27
  end
@@ -25,6 +29,21 @@ class FieldMethod
25
29
  def to_a
26
30
  [method_name] + args
27
31
  end
32
+
33
+ def send_to(sendable)
34
+ # can't just splat because procs have to be treated with kids gloves >:/
35
+ # TODO: use #to_a and reduce cases/enforce SRP on regular arg assembley
36
+ case
37
+ when !block && !args.empty?
38
+ sendable.send(method_name, *args)
39
+ when block && args.empty?
40
+ sendable.send(method_name, &block)
41
+ when block && !args.empty?
42
+ sendable.send(method_name, *args, &block)
43
+ when !block && args.empty?
44
+ sendable.send(method_name)
45
+ end
46
+ end
28
47
  end
29
48
 
30
49
  module Flowlink
@@ -37,7 +56,7 @@ module Flowlink
37
56
  defaults = FieldMethod.multi_new(fields)
38
57
  f_methods = FieldMethod.merge(overrides, defaults)
39
58
 
40
- Hash[f_methods.map { |f| [f.method_name.to_s, send(*f.to_a)] }]
59
+ Hash[f_methods.map { |fm| [fm.method_name.to_s, fm.send_to(self)] }]
41
60
  end
42
61
 
43
62
  alias to_message to_hash
@@ -48,8 +67,7 @@ module Flowlink
48
67
  end
49
68
 
50
69
  def fields
51
- # TODO: @fields ||= self.class.fields ???
52
- self.class.fields
70
+ @fields ||= self.class.fields
53
71
  end
54
72
  end
55
73
  end
@@ -1,3 +1,3 @@
1
1
  module Flowlink
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowlink_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cooper LeBrun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  A framework for getting Flowlink objects from other sources. For example: