tarvit-helpers 0.0.18 → 0.0.19

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: 1e736059b1e4ba9be2a14c72da7181ed9ac8ff9a
4
- data.tar.gz: 15a634622c8d7f8ffcd3912019d0868af0732f81
3
+ metadata.gz: 05681b4357edadeefed8c63c26fa6d22f503858e
4
+ data.tar.gz: 0820720e92d9e22990d0cd423e735d6a3509f58e
5
5
  SHA512:
6
- metadata.gz: 3d0e930b2cd0cd563471183b86c6210243623557fabb09c8a36eebd286b6606562829804b439b3fb15fef62bd5715e5f42bbbaa638182c19f6d0b5b30120fd42
7
- data.tar.gz: 27c9eceaa2616e5ac1288e353293d6961a3862aeda69210cea0bd87475d2f403873d9a7a6f0ada8352dbde46194cd602897d5639f7d5f158940231ca22f7e629
6
+ metadata.gz: d1198afc24a8e13956e76e4237cefe9e625428b0e532de709d44260879886c1d19b5c13d70f1ef2433d3939ca31c99718597bd00f33375c4910cbf34238a3134
7
+ data.tar.gz: 31ba51b3bac58da767fc61d58be22341a0be84469a1e5d723c6ed7fe42fbc6750eec1e8d77d8ff746e3a33ed9f3eccc4abd23c650675470afd035eca74ca905f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.18
1
+ 0.0.19
@@ -1,7 +1,7 @@
1
1
  module TarvitHelpers
2
2
  module HashPresenter
3
3
  class Cached < Simple
4
- def initialize(hash, levels=[])
4
+ def initialize(hash, levels=[], parent=nil)
5
5
  super
6
6
  @cache = {}
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module TarvitHelpers
2
2
  module HashPresenter
3
3
  class Observable < Simple
4
- def initialize(hash, levels=[])
4
+ def initialize(hash, levels=[], parent=nil)
5
5
  @_hash = hash
6
6
  @_levels = levels
7
7
  end
@@ -4,11 +4,12 @@ module TarvitHelpers
4
4
  class Simple
5
5
  require 'active_support/core_ext/string'
6
6
 
7
- attr_reader :_hash, :_levels
7
+ attr_reader :_hash, :_levels, :_parent
8
8
 
9
- def initialize(hash, levels=[])
9
+ def initialize(hash, levels=[], parent=nil)
10
10
  @_hash = _prepare_keys(hash)
11
11
  @_levels = levels
12
+ @_parent = parent
12
13
  end
13
14
 
14
15
  def method_missing(m, *args)
@@ -51,7 +52,7 @@ module TarvitHelpers
51
52
  end
52
53
 
53
54
  def _new_level_presenter(value, method_name)
54
- self.class.new(value, _path(method_name))
55
+ self.class.new(value, _path(method_name), self)
55
56
  end
56
57
 
57
58
  end
@@ -4,8 +4,8 @@ module TarvitHelpers
4
4
  class WithRules < Cached
5
5
  attr_reader :_rules_holder
6
6
 
7
- def initialize(hash, levels=[], rules_holder=nil, &rules)
8
- super(hash, levels)
7
+ def initialize(hash, levels=[], parent=nil, rules_holder=nil, &rules)
8
+ super(hash, levels, parent)
9
9
  @_rules_holder = rules_holder || RulesHolder.new
10
10
  _init_rules if _rules_holder.rules.empty?
11
11
  rules.call(_rules_holder) if rules
@@ -24,7 +24,7 @@ module TarvitHelpers
24
24
  end
25
25
 
26
26
  def _new_level_presenter(value, method_name)
27
- self.class.new(value, _path(method_name), _rules_holder)
27
+ self.class.new(value, _path(method_name), self, _rules_holder)
28
28
  end
29
29
 
30
30
  def _init_rules; end
@@ -212,6 +212,10 @@ describe HashPresenter::Custom do
212
212
  rules.when([:accounts, :collections, :folder]) do |value, object|
213
213
  "folders/#{object.name}"
214
214
  end
215
+
216
+ rules.when([:accounts, :collections, :global_folder]) do |value, object|
217
+ "#{object._parent.name}/folders/#{object.name}"
218
+ end
215
219
  end
216
220
  end
217
221
 
@@ -227,6 +231,7 @@ describe HashPresenter::Custom do
227
231
  expect(account.collections[0].folder).to eq('folders/TestCollection')
228
232
  expect(account.collections[1].name).to eq('BestCollection')
229
233
  expect(account.collections[1].folder).to eq('folders/BestCollection')
234
+ expect(account.collections[1].global_folder).to eq('director/folders/BestCollection')
230
235
 
231
236
  expect(@presenter._custom_hash).to eq({
232
237
  :accounts => [
@@ -234,8 +239,8 @@ describe HashPresenter::Custom do
234
239
  :id=>1,
235
240
  :name=>'director',
236
241
  :collections=>[
237
- {:id=>42, :name=>'TestCollection', :folder=>'folders/TestCollection'},
238
- {:id=>24, :name=>'BestCollection', :folder=>'folders/BestCollection'},
242
+ {:id=>42, :name=>'TestCollection', :folder=>'folders/TestCollection', :global_folder=>'director/folders/TestCollection'},
243
+ {:id=>24, :name=>'BestCollection', :folder=>'folders/BestCollection', :global_folder=>'director/folders/BestCollection'},
239
244
  ],
240
245
  :website=>'www.johndoe.com/director'
241
246
  }
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: tarvit-helpers 0.0.18 ruby lib
5
+ # stub: tarvit-helpers 0.0.19 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tarvit-helpers"
9
- s.version = "0.0.18"
9
+ s.version = "0.0.19"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarvit-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Tarasenko