tarvit-helpers 0.0.11 → 0.0.12

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: 5f2117e675264e10c3128bff56b480e423672048
4
- data.tar.gz: cd965580ba89f6982bb98f6c12a3ef97cd217e1a
3
+ metadata.gz: 3a13746e7d24e16878b2c73fdf642d0fce34ae3e
4
+ data.tar.gz: ddd2d104db9c6b76848d756b63a9b741a4b12196
5
5
  SHA512:
6
- metadata.gz: 66f741c836965bf736ae7eada042a3f554574d1fb1ee4eef693261cb903af73b6d688e6081bd7c40dfe55520af370533a499605c7f5691248d21bfdb52799340
7
- data.tar.gz: ba134f8d4ae9e358c32dfac59db198548540aaffeb46428df06df9777ebabf925808f37f7c72544c91f9d9e715ad0221b3e97de6e6480ed2f1f9cb0d0da45cba
6
+ metadata.gz: 934ddc0317b7d562c4b9d4f839c0cf16865229de27608aa4a1e36c3a999293c3ac9c3bbd04a644bcb6878201dd6fa048a75007ca2e4fb8e2191b4c0f8c9b2d0e
7
+ data.tar.gz: 708e3d499006efdff36776ae8063e0781e345e641745aadd0e32c63bf98c7bea06c7860301bb736c157a25e912fb8957f06357b41d329920b798b7e0fd15060f
data/README.md CHANGED
@@ -56,6 +56,23 @@ B.value
56
56
  => 3
57
57
  ```
58
58
 
59
+ HashPresenter module allows to present hashes as pure ojects.
60
+ ```ruby
61
+ hp = HashPresenter.present({ a: 1, b: 2 })
62
+ hp.a
63
+ => 1
64
+ hp.b
65
+ => 2
66
+
67
+ original = { a: 1, b: 2 }
68
+ observer = HashPresenter.present(original, :observable)
69
+ observer.a
70
+ => 1
71
+ original[:a] = 3
72
+ observer.a
73
+ => 3
74
+ ```
75
+
59
76
 
60
77
  **Contributing to tarvit-helpers**
61
78
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
@@ -13,10 +13,10 @@ module TarvitHelpers
13
13
  class SimpleHashPresenter
14
14
  require 'active_support/core_ext/string'
15
15
 
16
- attr_reader :hash
16
+ attr_reader :_hash
17
17
 
18
18
  def initialize(hash)
19
- @hash = prepare_keys(hash)
19
+ @_hash = prepare_keys(hash)
20
20
  end
21
21
 
22
22
  def method_missing(m, *args)
@@ -27,7 +27,7 @@ module TarvitHelpers
27
27
  protected
28
28
 
29
29
  def value(method_name)
30
- res = self.hash[method_name]
30
+ res = self._hash[method_name]
31
31
  transform_value(res)
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ module TarvitHelpers
37
37
  end
38
38
 
39
39
  def accessor_method?(method_name)
40
- self.hash.keys.include?(method_name)
40
+ self._hash.keys.include?(method_name)
41
41
  end
42
42
 
43
43
  def key_to_method(key)
@@ -68,11 +68,11 @@ module TarvitHelpers
68
68
 
69
69
  class ObservableHashPresenter < SimpleHashPresenter
70
70
  def initialize(hash)
71
- @hash = hash
71
+ @_hash = hash
72
72
  end
73
73
 
74
- def hash
75
- prepare_keys(@hash)
74
+ def _hash
75
+ prepare_keys(@_hash)
76
76
  end
77
77
  end
78
78
 
@@ -10,6 +10,7 @@ module BaseHashPresenterTest
10
10
  expect(hp.b).to eq(2)
11
11
  expect(hp.c).to eq([ 3 ])
12
12
  expect(->{ hp.d }).to raise_error(NoMethodError)
13
+ expect(hp._hash.values).to eq([1, 2, [3]])
13
14
  end
14
15
 
15
16
  it 'should transform complex keys' do
@@ -2,16 +2,16 @@
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.11 ruby lib
5
+ # stub: tarvit-helpers 0.0.12 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tarvit-helpers"
9
- s.version = "0.0.11"
9
+ s.version = "0.0.12"
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"]
13
13
  s.authors = ["Vitaly Tarasenko"]
14
- s.date = "2015-10-21"
14
+ s.date = "2015-10-23"
15
15
  s.description = " Simple extensions to standard Ruby classes and useful helpers. "
16
16
  s.email = "vetal.tarasenko@gmail.com"
17
17
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarvit-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Tarasenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport