voight_kampff 0.1.0 → 0.1.1

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,11 @@
1
+ namespace :voight_kampff do
2
+
3
+ desc 'Import a new uesr_agents.yml file'
4
+ task :import_user_agents, :url do |t, args|
5
+ args.with_defaults :url => 'http://www.user-agents.org/allagents.xml'
6
+ agents = VoightKampff::UserAgentsParser.new(args[:url])
7
+ file = File.open(Rails.root.join('config','user_agents.yml'), 'w')
8
+ file.write(agents.to_yaml)
9
+ end
10
+
11
+ end
data/lib/voight_kampff.rb CHANGED
@@ -7,6 +7,7 @@ module VoightKampff
7
7
  class << self
8
8
 
9
9
  def root
10
+ require 'pathname'
10
11
  Pathname.new File.expand_path '..', File.dirname(__FILE__)
11
12
  end
12
13
 
@@ -24,6 +24,7 @@ module VoightKampff
24
24
 
25
25
  def has_type?(*types)
26
26
  return nil if agent.empty?
27
+
27
28
  types.any? do |type|
28
29
  @types.include? type
29
30
  end
@@ -65,10 +66,20 @@ module VoightKampff
65
66
  private
66
67
 
67
68
  def load_agents
68
- rel_path = ['config', 'user_agents.yml']
69
- abs_path = Rails.root.join(*rel_path)
70
- abs_path = VoightKampff.root.join(*rel_path) unless File.exists? abs_path
71
- @@agents ||= YAML.load(File.open(abs_path, 'r'))
69
+ @@agents ||= []
70
+ if @@agents.empty?
71
+
72
+ base_paths = [VoightKampff.root]
73
+ base_paths << Rails.root if defined? Rails
74
+ rel_path = ['config', 'user_agents.yml']
75
+
76
+ base_paths.any? do |base_path|
77
+ if File.exists? base_path.join(*rel_path)
78
+ @@agents = YAML.load(File.open(base_path.join(*rel_path), 'r'))
79
+ end
80
+ end
81
+
82
+ end
72
83
  end
73
84
 
74
85
  end
@@ -1,5 +1,5 @@
1
1
  module VoightKampff
2
2
 
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voight_kampff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Crownoble
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-11 00:00:00 Z
18
+ date: 2011-05-16 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Voight-Kampff is a Ruby gem that detects bots, spiders, crawlers and replicants
@@ -34,6 +34,7 @@ files:
34
34
  - lib/voight_kampff/version.rb
35
35
  - lib/voight_kampff/test.rb
36
36
  - lib/voight_kampff/engine.rb
37
+ - lib/tasks/voight_kampff.rake
37
38
  homepage: https://github.com/adamcrown/Voight-Kampff
38
39
  licenses: []
39
40