reviewed_braai 0.2.3 → 0.3.0

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.
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "reviewed_braai/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "reviewed_braai"
9
+ s.version = ReviewedBraai::VERSION
10
+ s.authors = ["Kevin Incorvia"]
11
+ s.email = ["kincorvia@reviewed.com"]
12
+ s.homepage = "http://www.reviewed.com"
13
+ s.summary = "Braai matchers for Reviewed.com"
14
+
15
+ s.files = Dir["{app,config,db,lib}/**/*"] + [__FILE__, "MIT-LICENSE", "Rakefile", "README.rdoc"]
16
+
17
+ s.add_dependency "braai", ">= 1.6.2"
18
+ s.add_dependency "reviewed", ">= 0.4.0"
19
+
20
+ s.add_development_dependency "rspec"
21
+ end
@@ -7,4 +7,9 @@ require 'reviewed_braai/errors'
7
7
  require 'reviewed_braai/matchers'
8
8
 
9
9
  module ReviewedBraai
10
+
11
+ def self.logger
12
+ @logger ||= Braai.logger
13
+ end
14
+
10
15
  end
@@ -9,10 +9,8 @@ module ReviewedBraai
9
9
  end
10
10
 
11
11
  def self.log error
12
- if defined?(Rails) && defined?(Rails.logger)
13
- msg = "#{error.opts[:error_class]}: #{error.opts[:error_message]} key=#{error.opts[:key]}"
14
- Rails.logger.warn(msg)
15
- end
12
+ msg = "#{error.opts[:error_class]}: #{error.opts[:error_message]} key=#{error.opts[:key]}"
13
+ Braai.logger.warn(msg)
16
14
  end
17
15
 
18
16
  end
@@ -31,7 +29,8 @@ module ReviewedBraai
31
29
 
32
30
  @key = @opts[:key]
33
31
 
34
- Notifications.notify(self) || Notifications.log(self)
32
+ Notifications.notify(self)
33
+ Notifications.log(self)
35
34
 
36
35
  super(@opts[:error_message])
37
36
  end
@@ -8,14 +8,14 @@ module ReviewedBraai
8
8
 
9
9
  class ArticleAttachmentById < ReviewedBraai::Handlers::Base
10
10
  def perform
11
- attachment = match_attachment(:id, matches[1])
11
+ attachment = fetch_attachment_by_id(matches[1])
12
12
  ::ReviewedBraai::Attachment.new(attachment).render
13
13
  end
14
14
  end
15
15
 
16
16
  class ArticleAttachmentByName < ReviewedBraai::Handlers::Base
17
17
  def perform
18
- attachment = match_attachment(:name, matches[1])
18
+ attachment = fetch_attachment_by_name(matches[1], template.attributes[:article])
19
19
  ::ReviewedBraai::Attachment.new(attachment).render
20
20
  end
21
21
  end
@@ -2,15 +2,15 @@ module ReviewedBraai
2
2
  module Handlers
3
3
  class AttachmentsById < ReviewedBraai::Handlers::Base
4
4
  def perform
5
- attachment = match_attachment(all_attachments, :id, matches[1])
6
- ::ReviewedBraai::Attachment.new(attachment).render
5
+ attachment = fetch_attachment_by_id(matches[1])
6
+ Attachment.new(attachment).render
7
7
  end
8
8
  end
9
9
 
10
10
  class AttachmentsByName < ReviewedBraai::Handlers::Base
11
11
  def perform
12
- attachment = match_attachment(all_attachments, :name, matches[1])
13
- ::ReviewedBraai::Attachment.new(attachment).render
12
+ attachment = fetch_attachment_by_name(matches[1])
13
+ Attachment.new(attachment).render
14
14
  end
15
15
  end
16
16
  end
@@ -1,15 +1,47 @@
1
+ require 'reviewed'
2
+
1
3
  module ReviewedBraai
2
4
  module Handlers
3
5
  class Base < Braai::Handlers::Base
4
6
  include ReviewedBraai::Helpers
5
7
 
8
+ def initialize(template, key, matches)
9
+ Braai.logger.debug "#{self.class.name}: matched! - #{matches[1..-1].join(',')}" if matches
10
+ super(template, key, matches)
11
+ end
12
+
6
13
  def perform
7
- "<!-- #{key} -->"
14
+ msg = "#{self.class.to_s}: unmatched! #{key}"
15
+ Braai.logger.warn msg
16
+ "<!-- #{msg} -->"
8
17
  end
9
18
 
10
19
  def rescue_from_error(e)
11
- "<!-- #{key} -->"
20
+ msg = "#{self.class.to_s}: #{e.message} - #{key}"
21
+ Braai.logger.warn msg
22
+ "<!-- #{msg} -->"
23
+ end
24
+
25
+
26
+ protected
27
+
28
+ def fetch_attachments_by_tags tag, scope=nil
29
+ req = ::Reviewed::Request.new :resource => Reviewed::Attachment, :scope => scope
30
+ res = req.where :tags => tag
31
+ res.items
32
+ end
33
+
34
+ def fetch_attachment_by_name name, scope=nil
35
+ req = ::Reviewed::Request.new :resource => Reviewed::Attachment, :scope => scope
36
+ res = req.where :name => name
37
+ res.items.first if res.items
12
38
  end
39
+
40
+ def fetch_attachment_by_id id
41
+ req = ::Reviewed::Request.new :resource => Reviewed::Attachment
42
+ req.find id
43
+ end
44
+
13
45
  end
14
46
  end
15
47
  end
@@ -1,23 +1,24 @@
1
1
  module ReviewedBraai
2
2
  module Handlers
3
+
3
4
  class ProductVanity < ReviewedBraai::Handlers::Base
4
5
  def perform
5
- attachment = match_attachment_by_tag(primary_product.attachments, "vanity")
6
- ::ReviewedBraai::Attachment.new(attachment).render
6
+ attachments = fetch_attachments_by_tags('vanity', primary_product)
7
+ ::ReviewedBraai::Attachment.new(attachments.first).render
7
8
  end
8
9
  end
9
10
 
10
11
  class ProductAttachmentById < ReviewedBraai::Handlers::Base
11
12
  def perform
12
- attachment = match_attachment(primary_product.attachments, :id, matches[1])
13
- ::ReviewedBraai::Attachment.new(attachment).render
13
+ result = fetch_attachment_by_id(matches[1])
14
+ Attachment.new(result).render
14
15
  end
15
16
  end
16
17
 
17
18
  class ProductAttachmentByName < ReviewedBraai::Handlers::Base
18
19
  def perform
19
- attachment = match_attachment(primary_product.attachments, :name, matches[1])
20
- ::ReviewedBraai::Attachment.new(attachment).render
20
+ result = fetch_attachment_by_name(matches[1], primary_product)
21
+ Attachment.new(result).render
21
22
  end
22
23
  end
23
24
 
@@ -43,8 +44,8 @@ module ReviewedBraai
43
44
  class ProductsVanity < ReviewedBraai::Handlers::Base
44
45
  def perform
45
46
  product = match_product(:id, matches[1])
46
- attachment = match_attachment_by_tag(product.attachments, "vanity")
47
- ::ReviewedBraai::Attachment.new(attachment).render
47
+ attachments = fetch_attachments_by_tags('vanity', product)
48
+ ::ReviewedBraai::Attachment.new(attachments.first).render
48
49
  end
49
50
  end
50
51
 
@@ -58,17 +59,17 @@ module ReviewedBraai
58
59
 
59
60
  class ProductsAttachmentById < ReviewedBraai::Handlers::Base
60
61
  def perform
61
- product = match_product(:id, matches[1])
62
- attachment = match_attachment(product.attachments, :id, matches[2])
63
- ::ReviewedBraai::Attachment.new(attachment).render
62
+ result = fetch_attachment_by_id(matches[2])
63
+ Attachment.new(result).render
64
64
  end
65
65
  end
66
66
 
67
67
  class ProductsAttachmentByName < ReviewedBraai::Handlers::Base
68
68
  def perform
69
69
  product = match_product(:id, matches[1])
70
- attachment = match_attachment(product.attachments, :name, matches[2])
71
- ::ReviewedBraai::Attachment.new(attachment).render
70
+
71
+ result = fetch_attachment_by_name(matches[2], product)
72
+ Attachment.new(result).render
72
73
  end
73
74
  end
74
75
 
@@ -17,28 +17,6 @@ module ReviewedBraai
17
17
  end
18
18
  end
19
19
 
20
- def match_attachment(attachments = nil, attr, match)
21
- unless attachments
22
- attachments = all_attachments
23
- end
24
- if attachment = attachments.find { |a| a.send(attr) == match }
25
- attachment
26
- else
27
- raise ::ReviewedBraai::TagRenderError::AttachmentNotFound.new(default_args)
28
- end
29
- end
30
-
31
- def match_attachment_by_tag(attachments = nil, tag)
32
- unless attachments
33
- attachments = all_attachments
34
- end
35
- if attachment = attachments.find { |a| a.tags.include?(tag) }
36
- attachment
37
- else
38
- raise ::ReviewedBraai::TagRenderError::AttachmentNotFound.new(default_args)
39
- end
40
- end
41
-
42
20
  def match_manufacturer_spec(product = template.attributes[:article].primary_product, name)
43
21
  if spec = product.manufacturer_specs[name]
44
22
  spec
@@ -67,23 +45,6 @@ module ReviewedBraai
67
45
  end
68
46
  end
69
47
 
70
- def all_attachments
71
- attachments = []
72
- #template.attributes.values.each do |source|
73
- template.attributes.values.compact.each do |source|
74
- if (source.is_a?(Array))
75
- attachments += source.map {|x| x.attachments if x.attachments}.flatten
76
- else
77
- attachments += source.attachments if source.attachments
78
- end
79
- end
80
- # attachments.flatten! if attachments
81
- # attachments.compact! if attachments
82
- # attachments.uniq! if attachments
83
- # attachments
84
- attachments.flatten.compact.uniq
85
- end
86
-
87
48
  def default_args
88
49
  { key: key, parameters: { template: template, key: key, matches: matches } }
89
50
  end
@@ -8,7 +8,6 @@ module ReviewedBraai
8
8
  Braai::Template.map(Braai::Matchers::IterationMatcher, Braai::Handlers::Iteration)
9
9
 
10
10
  Braai::Handlers.rescue_from ReviewedBraai::TagRenderError, ->(handler, e) do
11
- # puts %{handler: #{handler.inspect}}
12
11
  value = handler.matches[1..-1].join(' ')
13
12
  "<!-- #{e.class.to_s}: #{value} -->"
14
13
  end
@@ -1,3 +1,3 @@
1
1
  module ReviewedBraai
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reviewed_braai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-18 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: braai
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.6.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: reviewed
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rspec
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +86,7 @@ files:
70
86
  - lib/reviewed_braai/version.rb
71
87
  - lib/reviewed_braai.rb
72
88
  - lib/tasks/reviewed_braai_tasks.rake
89
+ - /Users/sbeam/public_html/reviewed_braai/reviewed_braai.gemspec
73
90
  - MIT-LICENSE
74
91
  - Rakefile
75
92
  - README.rdoc
@@ -85,12 +102,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
102
  - - ! '>='
86
103
  - !ruby/object:Gem::Version
87
104
  version: '0'
105
+ segments:
106
+ - 0
107
+ hash: 4608000239477455564
88
108
  required_rubygems_version: !ruby/object:Gem::Requirement
89
109
  none: false
90
110
  requirements:
91
111
  - - ! '>='
92
112
  - !ruby/object:Gem::Version
93
113
  version: '0'
114
+ segments:
115
+ - 0
116
+ hash: 4608000239477455564
94
117
  requirements: []
95
118
  rubyforge_project:
96
119
  rubygems_version: 1.8.25