seory 0.0.1 → 0.0.2

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: 596af9785f1ff0011c40d7816efbe7ab4bfbdc4e
4
- data.tar.gz: e7f043fea0dcebf5175e085e74c7d5340435bda2
3
+ metadata.gz: 255ce5bf7ad7b79b1c1ba7b647c83bae44377685
4
+ data.tar.gz: 93d4ddd0a609d7403cb616da854ad06ce95ed540
5
5
  SHA512:
6
- metadata.gz: 96abaeb3e7afed6dd3efa2f4e8686ddffc3e6d3e2f2e7c7db348b53d063cb8882eed21ed0c0e0c414cedb936077e16a2021629501ebcecdb15174bc4f0b0c434
7
- data.tar.gz: a9e4f15b2ab04800148b5378b7e88476e8241b0829e003407f1de4b705aef185ecb4c80c8b9d324e0562d639b4acdcb7f5667778f395beda378b2ade400412c0
6
+ metadata.gz: 593351c2bba8912fd3aa0b1500ba53ee22c88b39c6475936b0ad362ab482cce9004112387ef1b7803bedb638f850a844472a4496dcc65f0d5401b8614ff76a60
7
+ data.tar.gz: 6813ee8c151970d98042038433febb0f646f12f961ec5ae3e61e062471b64da92d15573bedaef7d534af5eb2798dff3f5754b9dd3240c14c9f67848478d83438
data/lib/seory.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "seory/version"
2
2
 
3
3
  module Seory
4
+ CONTENTS = %w[title h1 h2 meta_description meta_keywords canonical_url image_url].map(&:to_sym)
5
+
4
6
  class Error < RuntimeError
5
7
  end
8
+
9
+ autoload :Dsl, 'seory/dsl'
6
10
  end
data/lib/seory/dsl.rb CHANGED
@@ -1,19 +1,17 @@
1
+ require 'seory'
1
2
  require 'seory/page_contents'
2
- require 'seory/runtime'
3
+ require 'seory/repository'
3
4
 
4
5
  module Seory
5
6
  module Dsl
6
- extend self
7
7
 
8
8
  def describe(&block)
9
- [].tap do |repositories|
10
- Descriptor.new(repositories).instance_exec(&block)
11
- end
9
+ @repository = Repository.new
10
+ Descriptor.new(@repository).describe(&block)
12
11
  end
13
12
 
14
13
  def lookup(controller)
15
- page_contents = repositories.detect {|page| page.match?(controller) }
16
- Seory::Runtime.new(page_contents, controller)
14
+ @repository.lookup(controller)
17
15
  end
18
16
 
19
17
  class PageContentsBuilder
@@ -27,7 +25,7 @@ module Seory
27
25
  @page_contents
28
26
  end
29
27
 
30
- Seory::Runtime::CONTENTS.each do |name|
28
+ Seory::CONTENTS.each do |name|
31
29
  define_method(name) do |val = nil, &block|
32
30
  @page_contents.define(name, val, &block)
33
31
  end
@@ -35,12 +33,18 @@ module Seory
35
33
  end
36
34
 
37
35
  class Descriptor
38
- def initialize(repositories)
39
- @repositories = repositories
36
+ def initialize(repository)
37
+ @repository = repository
38
+ end
39
+
40
+ def describe(&block)
41
+ instance_exec(&block)
42
+
43
+ @repository
40
44
  end
41
45
 
42
46
  def match(*conditions, &def_builder)
43
- @repositories << PageContentsBuilder.new(*conditions).build!(&def_builder)
47
+ @repository << PageContentsBuilder.new(*conditions).build!(&def_builder)
44
48
  end
45
49
 
46
50
  def default(&def_builder)
@@ -0,0 +1,18 @@
1
+ require 'seory/runtime'
2
+
3
+ module Seory
4
+ class Repository
5
+ def initialize
6
+ @store = []
7
+ end
8
+
9
+ def <<(page_contents)
10
+ @store << page_contents
11
+ end
12
+
13
+ def lookup(controller)
14
+ page_contents = @store.detect {|page| page.match?(controller) }
15
+ Seory::Runtime.new(page_contents, controller)
16
+ end
17
+ end
18
+ end
data/lib/seory/runtime.rb CHANGED
@@ -5,8 +5,6 @@ module Seory
5
5
  class Runtime
6
6
  delegate :action_name, to: :controller
7
7
 
8
- CONTENTS = %w[title h1 h2 meta_description meta_keywords canonical_url image_url].map(&:to_sym)
9
-
10
8
  attr_reader :controller
11
9
 
12
10
  def initialize(page_contents, controller)
@@ -14,7 +12,7 @@ module Seory
14
12
  @controller = controller
15
13
  end
16
14
 
17
- CONTENTS.each do |name|
15
+ Seory::CONTENTS.each do |name|
18
16
  define_method(name) { calculate_content_for(name) }
19
17
  end
20
18
 
data/lib/seory/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seory
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,8 +2,9 @@ require 'spec_helper'
2
2
  require 'seory/dsl'
3
3
 
4
4
  describe Seory::Dsl do
5
+ let(:seory_class) { Object.new.extend(Seory::Dsl) }
5
6
  before do
6
- Seory::Dsl.describe do
7
+ seory_class.describe do
7
8
  match 'products#index' do
8
9
  title 'My Great Product'
9
10
  h1 'Great Product Name'
@@ -16,7 +17,7 @@ describe Seory::Dsl do
16
17
  end
17
18
  end
18
19
 
19
- subject(:seory) { Seory::Dsl.lookup(controller) }
20
+ subject(:seory) { seory_class.lookup(controller) }
20
21
 
21
22
  context 'at products#index' do
22
23
  let(:controller) { double('controller', controller_name: 'products', action_name: 'index') }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - moro
@@ -69,6 +69,7 @@ files:
69
69
  - lib/seory.rb
70
70
  - lib/seory/dsl.rb
71
71
  - lib/seory/page_contents.rb
72
+ - lib/seory/repository.rb
72
73
  - lib/seory/runtime.rb
73
74
  - lib/seory/version.rb
74
75
  - seory.gemspec