cells 4.1.5 → 4.1.6

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: ac9cc75f99da78dcad2d164973de3e4258a5d79d
4
- data.tar.gz: 8043f9990c1a7414fe80edac59664243f0aa1f76
3
+ metadata.gz: b0cd2efb3cdf312f2c529647f9188b4e7e6639bd
4
+ data.tar.gz: 756d7e0d6e612d62d8750fb152f0ddfb238f6e47
5
5
  SHA512:
6
- metadata.gz: 11a8edb6918e0b4b3eb0436dd52a230d40642e362c8342dc000c04fd7a140d78e34debacc9b0e713ee662869e6d9d4a2a079fbc531e4e019456f514d80ace5b7
7
- data.tar.gz: 71e754860b9534b399e342a47140bca8fdc86dc97208f11d2f82b33ff61ebf31f31d66da3838dbd51f7310ba9b59fd7e6251b555f043c189ce20a6fd18e7be9b
6
+ metadata.gz: 7fd5589f420bf75a25d03fd8c9e986cc4566cfd332457b58213f07a7f21b29087d0224bfb79977ebaae003bd998ff086edec71552bafb8ebb58973f71a9bf4a8
7
+ data.tar.gz: 00d6fab903c9a92c29fb8c0398185f663ee9f6bc6c0235d56816b11115bedda4d9f20eae629d6aded51b11a458ee0e83172f3950312abd8cbb3b937bd4ac32d2
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 4.1.6
2
+
3
+ * Use `Declarative::Option` and `Declarative::Builder` instead of `uber`'s. This allows removing the `uber` version restriction.
4
+
1
5
  ## 4.1.5
2
6
 
3
7
  * Fix a bug where nested calls of `cell(name, context: {...})` would ignore the new context elements, resulting in the old context being passed on. By adding `Context::[]` the new elements are now properly merged into a **new context hash**. This means that adding elements to the child context won't leak up into the parent context anymore.
data/Gemfile CHANGED
@@ -6,3 +6,5 @@ gem "benchmark-ips"
6
6
  gem "minitest-line"
7
7
 
8
8
  gemspec
9
+
10
+ # gem "uber", path: "../uber"
data/README.md CHANGED
@@ -360,9 +360,13 @@ Builders allow instantiating different cell classes for different models and opt
360
360
 
361
361
  ```ruby
362
362
  class CommentCell < Cell::ViewModel
363
+ include ::Cell::Builder
364
+
363
365
  builds do |model, options|
364
- PostCell if model.is_a?(Post)
365
- CommentCell if model.is_a?(Comment)
366
+ case model
367
+ when Post; PostCell
368
+ when Comment; CommentCell
369
+ end
366
370
  end
367
371
  ```
368
372
 
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ["apotonick@gmail.com"]
12
12
  spec.homepage = "https://github.com/apotonick/cells"
13
13
  spec.summary = %q{View Models for Ruby and Rails.}
14
- spec.description = %q{Cells replaces partials and helpers with OOP view models, giving you proper encapsulation, inheritance, testability and a cleaner view architecture.}
14
+ spec.description = %q{View Models for Ruby and Rails, replacing helpers and partials while giving you a clean view architecture with proper encapsulation.}
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files`.split("\n")
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "uber", ">= 0.1.0", "< 0.2.0"
22
+ spec.add_dependency "uber", "< 0.2.0"
23
+ spec.add_dependency "declarative-option", "< 0.2.0"
24
+ spec.add_dependency "declarative-builder", "< 0.2.0"
23
25
  spec.add_dependency "tilt", ">= 1.4", "< 3"
24
26
 
25
27
  spec.add_development_dependency "rake"
@@ -1,6 +1,5 @@
1
1
  require "tilt"
2
2
  require "uber/inheritable_attr"
3
- require "uber/delegates"
4
3
  require "cell/version"
5
4
 
6
5
  module Cell
@@ -1,15 +1,15 @@
1
- require "uber/builder"
1
+ require "declarative/builder"
2
2
 
3
3
  module Cell
4
4
  module Builder
5
5
  def self.included(base)
6
- base.send :include, Uber::Builder
6
+ base.send :include, Declarative::Builder
7
7
  base.extend ClassMethods
8
8
  end
9
9
 
10
10
  module ClassMethods
11
11
  def build(*args)
12
- build!(self, *args).new(*args) # Uber::Builder#build!.
12
+ build!(self, *args).new(*args) # Declarative::Builder#build!.
13
13
  end
14
14
  end
15
15
  end
@@ -1,4 +1,4 @@
1
- require 'uber/options'
1
+ require "declarative/options"
2
2
 
3
3
  module Cell
4
4
  module Caching
@@ -10,19 +10,19 @@ module Cell
10
10
  inheritable_attr :conditional_procs
11
11
  inheritable_attr :cache_options
12
12
 
13
- self.version_procs = {}
13
+ self.version_procs = {}
14
14
  self.conditional_procs = {}
15
- self.cache_options = Uber::Options.new({})
15
+ self.cache_options = {}
16
16
  end
17
17
  end
18
18
 
19
19
  module ClassMethods
20
20
  def cache(state, *args, &block)
21
- options = args.last.is_a?(Hash) ? args.pop : {} # I have to admit, Array#extract_options is a brillant tool.
21
+ options = args.last.is_a?(Hash) ? args.pop : {} # I have to admit, Array#extract_options is a brilliant tool.
22
22
 
23
- self.conditional_procs[state] = Uber::Options::Value.new(options.delete(:if) || true)
24
- self.version_procs[state] = Uber::Options::Value.new(args.first || block)
25
- self.cache_options[state] = Uber::Options.new(options)
23
+ conditional_procs[state] = Declarative::Option(options.delete(:if) || true, instance_exec: true)
24
+ version_procs[state] = Declarative::Option(args.first || block, instance_exec: true)
25
+ cache_options[state] = Declarative::Options(options, instance_exec: true)
26
26
  end
27
27
 
28
28
  # Computes the complete, namespaced cache key for +state+.
@@ -37,17 +37,16 @@ module Cell
37
37
  private
38
38
 
39
39
  def expand_cache_key(key)
40
- key.join("/") # TODO: test me!
40
+ key.join("/")
41
41
  end
42
42
  end
43
43
 
44
-
45
44
  def render_state(state, *args)
46
45
  state = state.to_sym
47
46
  return super(state, *args) unless cache?(state, *args)
48
47
 
49
- key = self.class.state_cache_key(state, self.class.version_procs[state].evaluate(self, *args))
50
- options = self.class.cache_options.eval(state, self, *args)
48
+ key = self.class.state_cache_key(state, self.class.version_procs[state].(self, *args))
49
+ options = self.class.cache_options[state].(self, *args)
51
50
 
52
51
  fetch_from_cache_for(key, options) { super(state, *args) }
53
52
  end
@@ -57,7 +56,7 @@ module Cell
57
56
  end
58
57
 
59
58
  def cache?(state, *args)
60
- perform_caching? and state_cached?(state) and self.class.conditional_procs[state].evaluate(self, *args)
59
+ perform_caching? and state_cached?(state) and self.class.conditional_procs[state].(self, *args)
61
60
  end
62
61
 
63
62
  private
@@ -66,10 +65,8 @@ module Cell
66
65
  true
67
66
  end
68
67
 
69
- def fetch_from_cache_for(key, options)
70
- cache_store.fetch(key, options) do
71
- yield
72
- end
68
+ def fetch_from_cache_for(key, options, &block)
69
+ cache_store.fetch(key, options, &block)
73
70
  end
74
71
 
75
72
  def state_cached?(state)
@@ -1,3 +1,3 @@
1
1
  module Cell
2
- VERSION = "4.1.5"
2
+ VERSION = "4.1.6"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require "uber/delegates"
2
+
1
3
  module Cell
2
4
  class ViewModel
3
5
  extend Abstract
@@ -0,0 +1,32 @@
1
+ require "test_helper"
2
+
3
+ # TODO: test caching without rails
4
+
5
+ class CacheTest < Minitest::Spec
6
+ STORE = Class.new(Hash) do
7
+ def fetch(key, options, &block)
8
+ self[key] || self[key] = yield
9
+ end
10
+ end.new
11
+
12
+ module Cache
13
+ def show
14
+ "#{@model}"
15
+ end
16
+
17
+ def cache_store
18
+ STORE
19
+ end
20
+ end
21
+
22
+ class Index < Cell::ViewModel
23
+ cache :show
24
+ include Cache
25
+ end
26
+
27
+ it do
28
+ Index.new(1).().must_equal("1")
29
+ Index.new(2).().must_equal("1")
30
+ end
31
+ end
32
+
metadata CHANGED
@@ -1,22 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5
4
+ version: 4.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: declarative-option
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
20
31
  - - "<"
21
32
  - !ruby/object:Gem::Version
22
33
  version: 0.2.0
@@ -24,9 +35,20 @@ dependencies:
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
- - - ">="
38
+ - - "<"
28
39
  - !ruby/object:Gem::Version
29
- version: 0.1.0
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: declarative-builder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
30
52
  - - "<"
31
53
  - !ruby/object:Gem::Version
32
54
  version: 0.2.0
@@ -92,8 +114,8 @@ dependencies:
92
114
  - - ">="
93
115
  - !ruby/object:Gem::Version
94
116
  version: 0.0.4
95
- description: Cells replaces partials and helpers with OOP view models, giving you
96
- proper encapsulation, inheritance, testability and a cleaner view architecture.
117
+ description: View Models for Ruby and Rails, replacing helpers and partials while
118
+ giving you a clean view architecture with proper encapsulation.
97
119
  email:
98
120
  - apotonick@gmail.com
99
121
  executables: []
@@ -131,6 +153,7 @@ files:
131
153
  - lib/cells.rb
132
154
  - lib/tasks/cells.rake
133
155
  - test/builder_test.rb
156
+ - test/cache_test.rb
134
157
  - test/cell_benchmark.rb
135
158
  - test/cell_test.rb
136
159
  - test/concept_test.rb