expo 0.0.6 → 0.1.1

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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/expo.rb +35 -17
  3. metadata +4 -6
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjhiNzk1N2U5NjBiMzJhNGI1Y2Q4NzM1MDg0Y2QxOTJkY2E2MGU5ZA==
5
+ data.tar.gz: !binary |-
6
+ ZGY4YmZiOWRjYmQ4ZTgyZjc5N2M3Y2RiNDZlMTk1ODc0NGMzMWFjYg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODliMjNhYTM1ZGUzYjA4NGFhODQ5NzU4ZDRhNzU1MDMyM2MxZjk1ZjlkN2E3
10
+ NjQzZDlhOTU1OTA3NTdiNmNmNDRmZjFmNDRkMWYzY2I1YjRlODcwMzRkODQ3
11
+ Yjg3ZjczMzcyZDMxYzc0MGQxMmIwZmU3YWExYTg3ODZmMzI3M2U=
12
+ data.tar.gz: !binary |-
13
+ NTdjYTk3OWU5OTkxYjAxYjZmOTAwMTE5NzE3MWFiNDFlNGFhNTZlNmEzYzg2
14
+ NDBiOTAxMGUxYzcyOWYwODMxZmViZmE0OTNlZmViZWUxMTAyMDIxZGMxNTY0
15
+ NDIyMGVjNGIzZGIwMjI2ZmE2MDBmYzAyYTQ1Y2ZhZjRiYWUzNmE=
data/lib/expo.rb CHANGED
@@ -1,14 +1,18 @@
1
1
  class Expo
2
- CALL_ORDER = [:summon, :aside, :expose, :sub_expo, :collection]
3
- CALL_IMMEDIATELY = [:summon, :aside, :expose]
2
+ CALL_ORDER = [:aside, :expose, :sub_expo, :collection]
3
+ CALL_IMMEDIATELY = [:aside, :expose]
4
4
  CALL_LATER = [:sub_expo, :collection]
5
+ TRIVIAL_PRESENTER = Class.new do
6
+ def present(object)
7
+ object
8
+ end
9
+ end.new
5
10
 
6
11
  def initialize(presenter=nil, &block)
7
12
  @presenter = presenter
8
13
  @block = block
9
14
  @message_map = {}
10
15
  @subs = {}
11
- @summons = {}
12
16
  @collections = {}
13
17
  @inner_calls = []
14
18
  end
@@ -19,19 +23,22 @@ class Expo
19
23
  end
20
24
  @object = object
21
25
  @context = context
26
+ @preso = Proxy.new(
27
+ (@presenter || TRIVIAL_PRESENTER).present(object),
28
+ object
29
+ )
22
30
  if !@block
23
31
  return {}
24
32
  end
25
- block_return = self.instance_exec object, context, &@block
33
+ block_return = self.instance_exec @preso, context, &@block
26
34
  @inner_calls.sort_by{|call| CALL_ORDER.index(call[:method])}.each do |call|
27
35
  self.send(call[:method], *call[:args], &call[:block])
28
36
  end
29
37
  exposition = {}
30
38
  @message_map.each do |k,v|
31
- receiver = (@presenter || object)
32
- exposition[v] = receiver.send(k)
39
+ # puts "sending #{k}"
40
+ exposition[v] = @preso.send(k)
33
41
  end
34
- exposition.merge!(@summons)
35
42
  exposition.merge!(@subs)
36
43
  exposition.merge!(@collections)
37
44
  if block_return
@@ -58,21 +65,23 @@ class Expo
58
65
  nil
59
66
  end
60
67
  def sub_expo_inner(object, sub_expo_passed, key)
68
+ recurse_expo = sub_expo_passed
61
69
  if sub_expo_passed == self
62
- return
70
+ recurse_expo = Expo.new(@presenter, &@block)
63
71
  end
64
- sub = sub_expo_passed.expo(object, @context)
72
+ sub = recurse_expo.expo(object, @context)
65
73
  @subs[key] = sub if sub
66
74
  nil
67
75
  end
68
76
 
69
77
  def collection_inner(key, collection, item_expo)
78
+ recurse_expo = item_expo
70
79
  if item_expo == self
71
- return
80
+ recurse_expo = Expo.new(@presenter, &@block)
72
81
  end
73
82
  collection_exposition = []
74
83
  collection.each.with_index do |item, index|
75
- collection_exposition << item_expo.expo(item, @context.merge({
84
+ collection_exposition << recurse_expo.expo(item, @context.merge({
76
85
  "#{key}_index".to_sym => index
77
86
  }))
78
87
  end
@@ -80,13 +89,8 @@ class Expo
80
89
  nil
81
90
  end
82
91
 
83
- def summon_inner(*asides)
84
- @summons = hasherize(asides) {|aside| @context[aside]}
85
- nil
86
- end
87
-
88
92
  def aside_inner(*messages)
89
- receiver = (@presenter || @object)
93
+ receiver = @preso
90
94
  last = messages.pop
91
95
  if last.is_a?(Hash)
92
96
  last.each do |k,v|
@@ -117,4 +121,18 @@ class Expo
117
121
  def hasherize(array, &block)
118
122
  Hash[*array.map{|e| [e, block.call(e)] }.flatten]
119
123
  end
124
+
125
+ class Proxy
126
+ def initialize(*objects)
127
+ @objects = objects
128
+ end
129
+
130
+ def method_missing(method, *args, &block)
131
+ # puts "missing #{method}"
132
+ @objects.detect{|obj| obj.respond_to? method}.send(
133
+ method, *args, &block
134
+ )
135
+ end
136
+
137
+ end
120
138
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Serguei Filimonov
@@ -20,26 +19,25 @@ files:
20
19
  - lib/expo.rb
21
20
  homepage: https://github.com/sergueif/expo
22
21
  licenses: []
22
+ metadata: {}
23
23
  post_install_message:
24
24
  rdoc_options: []
25
25
  require_paths:
26
26
  - lib
27
27
  required_ruby_version: !ruby/object:Gem::Requirement
28
- none: false
29
28
  requirements:
30
29
  - - ! '>='
31
30
  - !ruby/object:Gem::Version
32
31
  version: '0'
33
32
  required_rubygems_version: !ruby/object:Gem::Requirement
34
- none: false
35
33
  requirements:
36
34
  - - ! '>='
37
35
  - !ruby/object:Gem::Version
38
36
  version: '0'
39
37
  requirements: []
40
38
  rubyforge_project:
41
- rubygems_version: 1.8.24
39
+ rubygems_version: 2.0.3
42
40
  signing_key:
43
- specification_version: 3
41
+ specification_version: 4
44
42
  summary: Expo of object presentations
45
43
  test_files: []