ironhide 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ tags
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in ironhide.gemspec
4
+ gemspec
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ironhide (0.0.1)
5
+ httpclient (>= 2.1.5.2)
6
+ rails (>= 2.3)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.0)
13
+ actionpack (= 3.0.0)
14
+ mail (~> 2.2.5)
15
+ actionpack (3.0.0)
16
+ activemodel (= 3.0.0)
17
+ activesupport (= 3.0.0)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.4.1)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.12)
23
+ rack-test (~> 0.5.4)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.0)
26
+ activesupport (= 3.0.0)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.4.1)
29
+ activerecord (3.0.0)
30
+ activemodel (= 3.0.0)
31
+ activesupport (= 3.0.0)
32
+ arel (~> 1.0.0)
33
+ tzinfo (~> 0.3.23)
34
+ activeresource (3.0.0)
35
+ activemodel (= 3.0.0)
36
+ activesupport (= 3.0.0)
37
+ activesupport (3.0.0)
38
+ addressable (2.2.2)
39
+ arel (1.0.1)
40
+ activesupport (~> 3.0.0)
41
+ builder (2.1.2)
42
+ crack (0.1.8)
43
+ diff-lcs (1.1.2)
44
+ erubis (2.6.6)
45
+ abstract (>= 1.0.0)
46
+ httpclient (2.1.5.2)
47
+ i18n (0.4.1)
48
+ mail (2.2.5)
49
+ activesupport (>= 2.3.6)
50
+ mime-types
51
+ treetop (>= 1.4.5)
52
+ mime-types (1.16)
53
+ polyglot (0.3.1)
54
+ rack (1.2.1)
55
+ rack-mount (0.6.13)
56
+ rack (>= 1.0.0)
57
+ rack-test (0.5.4)
58
+ rack (>= 1.0)
59
+ rails (3.0.0)
60
+ actionmailer (= 3.0.0)
61
+ actionpack (= 3.0.0)
62
+ activerecord (= 3.0.0)
63
+ activeresource (= 3.0.0)
64
+ activesupport (= 3.0.0)
65
+ bundler (~> 1.0.0)
66
+ railties (= 3.0.0)
67
+ railties (3.0.0)
68
+ actionpack (= 3.0.0)
69
+ activesupport (= 3.0.0)
70
+ rake (>= 0.8.4)
71
+ thor (~> 0.14.0)
72
+ rake (0.8.7)
73
+ rspec (2.2.0)
74
+ rspec-core (~> 2.2)
75
+ rspec-expectations (~> 2.2)
76
+ rspec-mocks (~> 2.2)
77
+ rspec-core (2.2.1)
78
+ rspec-expectations (2.2.0)
79
+ diff-lcs (~> 1.1.2)
80
+ rspec-mocks (2.2.0)
81
+ thor (0.14.0)
82
+ treetop (1.4.8)
83
+ polyglot (>= 0.3.1)
84
+ tzinfo (0.3.23)
85
+ webmock (1.6.1)
86
+ addressable (>= 2.2.2)
87
+ crack (>= 0.1.7)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bundler (>= 1.0.0)
94
+ httpclient (>= 2.1.5.2)
95
+ ironhide!
96
+ rails (>= 2.3)
97
+ rspec (>= 2.2)
98
+ webmock (>= 1.6.1)
@@ -0,0 +1,15 @@
1
+ == Ironhide
2
+
3
+ Ironhide provide extra functionalities to your rails app, which are:
4
+
5
+ * Include external web content into your view
6
+
7
+ === Includer
8
+
9
+ Includer provide a view helper method to allow you to consume web contents easily:
10
+
11
+ file_get_contents('http://github.com/felipecvo/ironhide/raw/master/README.rdoc')
12
+
13
+ == Installation
14
+
15
+ gem install ironhide
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ desc "run the spec suite"
5
+ task :spec do
6
+ system "rspec -cfs spec"
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/ironhide/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "ironhide"
6
+ s.version = Ironhide::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Felipe Oliveira"]
9
+ s.email = ["felipecvo@gmail.com"]
10
+ s.homepage = "http://rubygems.org/gems/ironhide"
11
+ s.summary = "Allows you to include an external html file inside your view."
12
+ s.description = s.summary
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "ironhide"
16
+
17
+ s.add_dependency "rails", ">= 2.3"
18
+ s.add_dependency "httpclient", ">= 2.1.5.2"
19
+
20
+ s.add_development_dependency "bundler", ">= 1.0.0"
21
+ s.add_development_dependency "rspec", ">= 2.2"
22
+ s.add_development_dependency "webmock", ">= 1.6.1"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
26
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
27
+ s.require_path = 'lib'
28
+ end
@@ -0,0 +1,13 @@
1
+ module Ironhide
2
+ class << self
3
+ def enable_helpers
4
+ require 'action_view'
5
+ ActionView::Base.send :include, Ironhide::Helpers::IncluderHelper
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ironhide/includer'
11
+ require 'ironhide/helpers/includer_helper'
12
+
13
+ Ironhide.enable_helpers
@@ -0,0 +1,9 @@
1
+ module Ironhide
2
+ module Helpers
3
+ module IncluderHelper
4
+ def file_get_contents(url)
5
+ Ironhide::Includer.get(url)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ require 'httpclient'
2
+ require 'rails'
3
+
4
+ module Ironhide
5
+ class Includer
6
+
7
+ module ClassMethods
8
+ attr_writer :default_timeout
9
+
10
+ def default_timeout
11
+ @default_timeout ||= 10.minutes
12
+ end
13
+
14
+ def get(url, timeout = default_timeout)
15
+ key = "Ironhide::Includer::#{Digest::MD5.hexdigest(url)}"
16
+ cached = Rails.cache.read(key)
17
+ return cached unless cached.nil?
18
+
19
+ response = HTTPClient.get(url)
20
+ if response.status_code == 200
21
+ content = response.body.content
22
+ Rails.cache.write(key, content, :expires_in => timeout)
23
+ content
24
+ else
25
+ nil
26
+ end
27
+ end
28
+ end
29
+
30
+ extend ClassMethods
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Ironhide
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ include Ironhide::Helpers::IncluderHelper
4
+
5
+ describe Ironhide::Helpers::IncluderHelper do
6
+ before(:each) do
7
+ @url = 'http://www.thatsite.com/full_content.html'
8
+ @expected = 'ok'
9
+ stub_request(:get, @url).to_return(:body => @expected)
10
+ end
11
+
12
+ it 'should provide helper method to get file contents' do
13
+ actual = file_get_contents(@url)
14
+
15
+ actual.should == @expected
16
+ end
17
+
18
+ it 'should be included in ActionView::Base' do
19
+ actual = ActionView::Base.new.file_get_contents(@url)
20
+
21
+ actual.should == @expected
22
+ end
23
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ironhide::Includer do
4
+ it "should get external file contents through http request" do
5
+ resource = 'http://somesite.com/resources/content.shtml'
6
+ expected = '<div><h1>title</h1><p>text to describe it</p></div>'
7
+ stub_request(:get, resource).to_return(:body => expected)
8
+
9
+ actual = Ironhide::Includer.get(resource)
10
+
11
+ WebMock.should have_requested(:get, resource)
12
+ actual.should == expected
13
+ end
14
+
15
+ it "should returns nil when response status code is not 200" do
16
+ resource = 'http://somesite.com/resources/content2.shtml'
17
+ stub_request(:get, resource).to_return(:body => 'not found', :status => 404)
18
+
19
+ actual = Ironhide::Includer.get(resource)
20
+
21
+ WebMock.should have_requested(:get, resource)
22
+ actual.should be_nil
23
+ end
24
+
25
+ it "should write response to cache" do
26
+ resource = 'http://cdn.somesite.com/cached/jquery.js'
27
+ expected = 'jquery code'
28
+ stub_request(:get, resource).to_return(:body => expected)
29
+ Rails.cache.should_receive(:write).with("Ironhide::Includer::#{Digest::MD5.hexdigest(resource)}", expected, :expires_in => 10.minutes)
30
+
31
+ actual = Ironhide::Includer.get(resource)
32
+
33
+ WebMock.should have_requested(:get, resource)
34
+ actual.should == expected
35
+ end
36
+
37
+ it "should write response to cache with custom timeout" do
38
+ resource = 'http://somesite.com/menu.html'
39
+ expected = 'menu content'
40
+ stub_request(:get, resource).to_return(:body => expected)
41
+ Rails.cache.should_receive(:write).with("Ironhide::Includer::#{Digest::MD5.hexdigest(resource)}", expected, :expires_in => 1.hour)
42
+
43
+ actual = Ironhide::Includer.get(resource, 1.hour)
44
+
45
+ WebMock.should have_requested(:get, resource)
46
+ actual.should == expected
47
+ end
48
+
49
+ it "should return content from cache" do
50
+ resource = 'http://cdn.somesite.com/cached/jquery.min.js'
51
+ expected = 'cached content'
52
+ Rails.cache.should_receive(:read).
53
+ with("Ironhide::Includer::#{Digest::MD5.hexdigest(resource)}").
54
+ and_return(expected)
55
+
56
+ actual = Ironhide::Includer.get(resource)
57
+
58
+ actual.should == expected
59
+ end
60
+
61
+ it "should have cache default timeout" do
62
+ Ironhide::Includer.default_timeout.should == 10.minutes
63
+ Ironhide::Includer.default_timeout = 20.minutes
64
+ Ironhide::Includer.default_timeout.should == 20.minutes
65
+ end
66
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'ironhide'
5
+
6
+ require 'webmock/rspec'
7
+
8
+ RSpec.configure do |config|
9
+ Class.new(Rails::Application)
10
+ Rails.application.initializers.select { |x| x.name == :initialize_cache }.first.run
11
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ironhide
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Felipe Oliveira
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-14 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 2
32
+ - 3
33
+ version: "2.3"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: httpclient
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 119
45
+ segments:
46
+ - 2
47
+ - 1
48
+ - 5
49
+ - 2
50
+ version: 2.1.5.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 0
66
+ version: 1.0.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 7
78
+ segments:
79
+ - 2
80
+ - 2
81
+ version: "2.2"
82
+ type: :development
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 13
93
+ segments:
94
+ - 1
95
+ - 6
96
+ - 1
97
+ version: 1.6.1
98
+ type: :development
99
+ version_requirements: *id005
100
+ description: Allows you to include an external html file inside your view.
101
+ email:
102
+ - felipecvo@gmail.com
103
+ executables: []
104
+
105
+ extensions: []
106
+
107
+ extra_rdoc_files: []
108
+
109
+ files:
110
+ - .gitignore
111
+ - Gemfile
112
+ - Gemfile.lock
113
+ - README.rdoc
114
+ - Rakefile
115
+ - ironhide.gemspec
116
+ - lib/ironhide.rb
117
+ - lib/ironhide/helpers/includer_helper.rb
118
+ - lib/ironhide/includer.rb
119
+ - lib/ironhide/version.rb
120
+ - spec/helpers/includer_helper_spec.rb
121
+ - spec/includer_spec.rb
122
+ - spec/spec_helper.rb
123
+ has_rdoc: true
124
+ homepage: http://rubygems.org/gems/ironhide
125
+ licenses: []
126
+
127
+ post_install_message:
128
+ rdoc_options: []
129
+
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 23
147
+ segments:
148
+ - 1
149
+ - 3
150
+ - 6
151
+ version: 1.3.6
152
+ requirements: []
153
+
154
+ rubyforge_project: ironhide
155
+ rubygems_version: 1.3.7
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: Allows you to include an external html file inside your view.
159
+ test_files: []
160
+