penetration 0.0.2 → 0.0.3

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: 6ac13b50b64421eadc08fa06ed7b7665e4244128
4
- data.tar.gz: 55dcd26a869dc7a6d136da8d5fc9706e9f3b53f2
3
+ metadata.gz: f3e40af3e34491dc2d7890e468f05c1eb14b3081
4
+ data.tar.gz: a671ff2af62cdca648d5e33f2472a20e70459d10
5
5
  SHA512:
6
- metadata.gz: 549402c53b676440b6d8eddea6676befd62ce95af464c9aa22003c6cc40665052f46ba067e54675d892f8705f301438988da3386faf0cf9e9b3f047defc4719c
7
- data.tar.gz: 133e6ad41618feb36c38d8d457cab73a5ee04a1c4ed9ee0e6f7d80cdbffd57307f10ca6b1d0c023372e3a71b8da3d3946b2ee4ae6cdb1531d2d482b4c96a7328
6
+ metadata.gz: eea25a0c7401a3001da97f8d9f829294a6d7c24866dc73daf2c89bafb68a5e015abf2eb92ada8e453b6d62627b36b0d45ced7e27fe442051342064c1c4d39ca5
7
+ data.tar.gz: 608d0dc8db4428bfa4a420ec208c1fbfcbf43b733981684ef3bb02b3233f8b3c4b213cc4f369373b1184186cc393503d3881ca1c77b62591d78b2fed1cd78783
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- penetration (0.0.2)
4
+ penetration (0.0.3)
5
5
  rails (~> 4.0)
6
6
 
7
7
  GEM
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/mmmpa/penetration.svg)](https://travis-ci.org/mmmpa/penetration)
2
+ [![Coverage Status](https://coveralls.io/repos/mmmpa/penetration/badge.svg?branch=master)](https://coveralls.io/r/mmmpa/penetration?branch=master)
3
+ [![Code Climate](https://codeclimate.com/github/mmmpa/penetration/badges/gpa.svg)](https://codeclimate.com/github/mmmpa/penetration)
4
+
5
+ # Penetration
6
+
7
+ Viewの末尾にテキストを挿入する。
data/Rakefile CHANGED
@@ -5,6 +5,8 @@ rescue LoadError
5
5
  end
6
6
 
7
7
  require 'rdoc/task'
8
+ require "bundler/gem_tasks"
9
+ require 'rspec/core/rake_task'
8
10
 
9
11
  RDoc::Task.new(:rdoc) do |rdoc|
10
12
  rdoc.rdoc_dir = 'rdoc'
@@ -14,8 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
16
  rdoc.rdoc_files.include('lib/**/*.rb')
15
17
  end
16
18
 
17
-
18
-
19
-
20
19
  Bundler::GemHelper.install_tasks
21
20
 
21
+ task :default => :spec
22
+ RSpec::Core::RakeTask.new
@@ -1,3 +1,3 @@
1
1
  module Penetration
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/penetration.rb CHANGED
@@ -4,12 +4,26 @@ module Penetration
4
4
  end
5
5
 
6
6
  class Caller
7
- class << self
8
- def penetrate(session, session_name, element)
9
- session[session_name] ||= []
10
- session[session_name] << element
11
- session[session_name].compact
12
- end
7
+ def initialize(session, session_name)
8
+ @session = session
9
+ @session_name = session_name
10
+ @session[@session_name] ||= []
11
+ end
12
+
13
+ def current_session
14
+ @session[@session_name]
15
+ end
16
+
17
+ def add_raw(raw)
18
+ add(:raw, raw)
19
+ end
20
+
21
+ def add_preset(preset)
22
+ add(:preset, preset)
23
+ end
24
+
25
+ def add(mode, element)
26
+ current_session << [mode, element]
13
27
  end
14
28
  end
15
29
 
@@ -26,13 +40,15 @@ module Penetration
26
40
  class Core
27
41
  def initialize(session, text = nil, &block)
28
42
  @session = session
29
- Caller.penetrate(@session, :rough_penetration, text) if text
43
+ @caller = Caller.new(@session, :rough_penetration)
44
+ @caller.add_raw(text) if text
30
45
  instance_eval(&block) if block_given?
31
46
  end
32
47
 
33
48
  def method_missing(name, *rest)
34
- preset = Preset.find(name)
35
- Caller.penetrate(@session, :rough_penetration, preset.is_a?(Proc) ? preset.(*rest) : preset)
49
+ if Preset.find(name)
50
+ @caller.add_preset([name, *rest].flatten)
51
+ end
36
52
  end
37
53
  end
38
54
 
@@ -49,8 +65,21 @@ module Penetration
49
65
 
50
66
  def render
51
67
  return '' if (elements = @session.delete(:rough_penetration)).nil?
52
-
53
- elements.flatten.join.html_safe
68
+ elements.map do |element|
69
+ case element.first.to_sym
70
+ when :raw
71
+ element.last
72
+ when :preset
73
+ preset = Preset.find(element.last.first)
74
+ if preset.is_a?(Proc)
75
+ element.last[1] ? preset.(element.last[1]) : preset.()
76
+ else
77
+ preset
78
+ end
79
+ else
80
+ # do nothing
81
+ end
82
+ end.compact.join.html_safe
54
83
  end
55
84
  end
56
85
 
@@ -1,9 +1,9 @@
1
-
2
-
3
1
  class PenetrationsController < ApplicationController
4
2
  Penetration.configure do
5
3
  preset(:notify) { 'peenetrated notification!' }
4
+ preset(:too_long) { 'peenetrated notification!' * 500 }
6
5
  preset(:alert) { ->(message) { "peenetrated #{message}" } }
6
+ preset(:no_param) { -> { "peenetrated noparam!" } }
7
7
  end
8
8
 
9
9
  def index
@@ -11,23 +11,45 @@ class PenetrationsController < ApplicationController
11
11
 
12
12
  def dynamic
13
13
  penetrate 'peenetrated penetration!'
14
+ render :index
15
+ end
16
+
17
+ def dynamic_too_long
18
+ penetrate 'peenetrated penetration!' * 500
19
+ render json: {}
14
20
  end
15
21
 
16
22
  def tag
17
23
  penetrate '<strong>peenetrated penetration!</strong>'
18
- render :dynamic
24
+ render :index
19
25
  end
20
26
 
21
27
  def preset
22
28
  penetrate {
23
29
  notify
24
30
  }
31
+ render :index
32
+ end
33
+
34
+ def preset_too_long
35
+ penetrate {
36
+ too_long
37
+ }
38
+ render json: {}
39
+ end
40
+
41
+ def with_no_param
42
+ penetrate {
43
+ no_param
44
+ }
45
+ render :index
25
46
  end
26
47
 
27
48
  def with_param
28
49
  penetrate {
29
50
  alert 'alert!'
30
51
  }
52
+ render :index
31
53
  end
32
54
 
33
55
  def double
@@ -35,6 +57,7 @@ class PenetrationsController < ApplicationController
35
57
  alert 'alert1!'
36
58
  alert 'alert2!'
37
59
  }
60
+ render :index
38
61
  end
39
62
  end
40
63
 
@@ -1,8 +1,11 @@
1
1
  Dummy::Application.routes.draw do
2
2
  get 'penetrations/index'
3
3
  get 'penetrations/dynamic'
4
+ get 'penetrations/dynamic_too_long'
4
5
  get 'penetrations/tag'
5
6
  get 'penetrations/preset'
7
+ get 'penetrations/preset_too_long'
8
+ get 'penetrations/with_no_param'
6
9
  get 'penetrations/with_param'
7
10
  get 'penetrations/double'
8
11
  end
@@ -15,6 +15,12 @@ describe 'Penetrations', type: :request do
15
15
  expect(response.body).to include('peenetrated penetration!')
16
16
  end
17
17
 
18
+ it do
19
+ expect{
20
+ get '/penetrations/dynamic_too_long'
21
+ }.to raise_exception(ActionDispatch::Cookies::CookieOverflow)
22
+ end
23
+
18
24
  it do
19
25
  get '/penetrations/tag'
20
26
  expect(response.body).to include('<strong>peenetrated penetration!</strong>')
@@ -25,6 +31,17 @@ describe 'Penetrations', type: :request do
25
31
  expect(response.body).to include('peenetrated notification!')
26
32
  end
27
33
 
34
+ it do
35
+ get '/penetrations/preset_too_long'
36
+ get '/penetrations/index'
37
+ expect(response.body).to include('peenetrated notification!' * 10)
38
+ end
39
+
40
+ it do
41
+ get '/penetrations/with_no_param'
42
+ expect(response.body).to include('peenetrated noparam!')
43
+ end
44
+
28
45
  it do
29
46
  get '/penetrations/with_param'
30
47
  expect(response.body).to include('peenetrated alert!')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: penetration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmmpa
@@ -164,6 +164,7 @@ files:
164
164
  - Gemfile
165
165
  - Gemfile.lock
166
166
  - MIT-LICENSE
167
+ - README.md
167
168
  - Rakefile
168
169
  - lib/penetration.rb
169
170
  - lib/penetration/version.rb
@@ -182,11 +183,7 @@ files:
182
183
  - spec/dummy/app/models/.keep
183
184
  - spec/dummy/app/models/concerns/.keep
184
185
  - spec/dummy/app/views/layouts/application.html.erb
185
- - spec/dummy/app/views/penetrations/double.html.erb
186
- - spec/dummy/app/views/penetrations/dynamic.html.erb
187
186
  - spec/dummy/app/views/penetrations/index.html.erb
188
- - spec/dummy/app/views/penetrations/preset.html.erb
189
- - spec/dummy/app/views/penetrations/with_param.html.erb
190
187
  - spec/dummy/bin/bundle
191
188
  - spec/dummy/bin/rails
192
189
  - spec/dummy/bin/rake
@@ -1,2 +0,0 @@
1
- <h1>Penetrations#double</h1>
2
- <p>Find me in app/views/penetrations/double.html.erb</p>
@@ -1,2 +0,0 @@
1
- <h1>Penetrations#dynamic</h1>
2
- <p>Find me in app/views/penetrations/dynamic.html.erb</p>
@@ -1,2 +0,0 @@
1
- <h1>Penetrations#preset</h1>
2
- <p>Find me in app/views/penetrations/preset.html.erb</p>
@@ -1,2 +0,0 @@
1
- <h1>Penetrations#with_param</h1>
2
- <p>Find me in app/views/penetrations/with_param.html.erb</p>