atech 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/atech/base.rb +2 -0
- data/lib/atech/configuration.rb +43 -0
- data/lib/atech/extensions/string.rb +14 -0
- data/lib/atech/helpers.rb +9 -0
- data/lib/atech/record_identifier.rb +35 -0
- data/lib/atech/user_agent.rb +58 -0
- metadata +7 -4
data/lib/atech/base.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
## This module allows you to create application specific configuration options.
|
2
|
+
## You can define a block to set your variables or you can simply set them
|
3
|
+
## on an instance of the object. The application should define this to begin
|
4
|
+
## with (`Codebase.settings = Atech::Configuration.new`) or something.
|
5
|
+
|
6
|
+
module Atech
|
7
|
+
class Configuration
|
8
|
+
|
9
|
+
attr_reader :attributes
|
10
|
+
|
11
|
+
def initialize(attributes = Hash.new)
|
12
|
+
@attributes = attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup!(&block)
|
16
|
+
block.call(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method_name, value = nil)
|
20
|
+
method_name = method_name.to_s
|
21
|
+
if method_name[-1,1] == '='
|
22
|
+
method_name.gsub!(/\=\z/, '')
|
23
|
+
attributes[method_name] = value
|
24
|
+
else
|
25
|
+
question = false
|
26
|
+
if method_name =~ /\?\z/
|
27
|
+
method_name.gsub!(/\?\z/, '')
|
28
|
+
question = true
|
29
|
+
end
|
30
|
+
|
31
|
+
if attributes.keys.include?(method_name)
|
32
|
+
if question
|
33
|
+
!!attributes[method_name]
|
34
|
+
else
|
35
|
+
attributes[method_name]
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise NoMethodError, "undefined configurtion attribute `#{method_name}' for #{self}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -37,4 +37,18 @@ class String
|
|
37
37
|
Digest::MD5.hexdigest(self)[0,length]
|
38
38
|
end
|
39
39
|
|
40
|
+
## Returns the first character of a string.
|
41
|
+
def first_character
|
42
|
+
case self[0]
|
43
|
+
when 194..223
|
44
|
+
return self[0,2]
|
45
|
+
when 224..239
|
46
|
+
return self[0,3]
|
47
|
+
when 240..244
|
48
|
+
return self[0,4]
|
49
|
+
else
|
50
|
+
return self[0,1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
40
54
|
end
|
data/lib/atech/helpers.rb
CHANGED
@@ -45,5 +45,14 @@ module Atech
|
|
45
45
|
image_tag([host,path].join, :class => options[:class], :width => options[:size], :height => options[:size])
|
46
46
|
end
|
47
47
|
|
48
|
+
## Return a set of three classes allowing you to determine the user agent of the clients computer.
|
49
|
+
## This method can be called as part of the <html> or <body> class. It will return the
|
50
|
+
## operating system, the browser's name and the version number.
|
51
|
+
def user_agent_classes
|
52
|
+
if defined?(Atech::UserAgent) && request.user_agent.is_a?(Atech::UserAgent)
|
53
|
+
"#{request.user_agent.os} #{request.user_agent.name} v#{request.user_agent.version}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
48
57
|
end
|
49
58
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
## This module allows you to automatically generate a random unique record
|
2
|
+
## for a record when it's created. This allows you to hide real IDs from your
|
3
|
+
## users if you wish/require. If you'd like to use this functionality you can
|
4
|
+
## include this within your ActiveRecord::Base.
|
5
|
+
##
|
6
|
+
## require 'atech/record_identifier'
|
7
|
+
## class ActiveRecord::Base
|
8
|
+
## include Atech::RecordIdentifier
|
9
|
+
## end
|
10
|
+
##
|
11
|
+
## asd
|
12
|
+
|
13
|
+
require 'atech/extensions/string'
|
14
|
+
|
15
|
+
module Atech
|
16
|
+
module RecordIdentifier
|
17
|
+
|
18
|
+
def to_param
|
19
|
+
self.respond_to?(:identifier) ? identifier : id.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def generate_identifier
|
25
|
+
return unless self.respond_to?(:identifier)
|
26
|
+
self.identifier = String.generate_token
|
27
|
+
logger.debug "Generated identifier for '#{self.class}' as '#{self.identifier}'"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.included(base)
|
31
|
+
base.send(:before_validation, :generate_identifier, :on => :create)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
## This module provides additional functionality to the ActionController::Request#user_agent
|
2
|
+
## method (request.user_agent to a layman). It add options for interogating the
|
3
|
+
## browser's name, operating system and version. For example.
|
4
|
+
##
|
5
|
+
## request.user_agent #=> [raw user agent string]
|
6
|
+
## request.user_agent.os #=> 'mac'
|
7
|
+
## request.user_agent.name #=> 'safari'
|
8
|
+
## request.user_agent.version #=> 5
|
9
|
+
## request.user_agent.os.windows? #=> false
|
10
|
+
## request.user_agent.os.mac? #=> true
|
11
|
+
## reuqest.user_agent.name.safari? #=> false
|
12
|
+
##
|
13
|
+
## At the moment it supoprts IE, Firefox, Safari & Chrome.
|
14
|
+
|
15
|
+
require 'active_support/string_inquirer'
|
16
|
+
|
17
|
+
if defined?(ActionController::Request)
|
18
|
+
class ActionController::Request
|
19
|
+
def user_agent
|
20
|
+
Atech::UserAgent.new(env['HTTP_USER_AGENT'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Atech
|
26
|
+
class UserAgent < String
|
27
|
+
|
28
|
+
def os
|
29
|
+
ActiveSupport::StringInquirer.new(case self
|
30
|
+
when /(windows)|(win(\d{2}))/i then :windows
|
31
|
+
when /linux/i then :linux
|
32
|
+
when /macintosh/i then :mac
|
33
|
+
else :unknown
|
34
|
+
end.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def name
|
38
|
+
ActiveSupport::StringInquirer.new(name_and_version.first.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
def version
|
42
|
+
name_and_version.last
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def name_and_version
|
48
|
+
@name_and_version ||= case self
|
49
|
+
when /MSIE (\d+)/i then [:ie, $1.to_i]
|
50
|
+
when /Firefox\/(\d+)/ then [:firefox, $1.to_i]
|
51
|
+
when /Chrome\/(\d+)/ then [:chrome, $1.to_i]
|
52
|
+
when /Version\/(\d+).*Safari\//i then [:safari, $1.to_i]
|
53
|
+
else [:unknown, 0]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 17
|
10
|
+
version: 1.0.17
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- aTech Media
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-11 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -29,11 +29,14 @@ extra_rdoc_files: []
|
|
29
29
|
|
30
30
|
files:
|
31
31
|
- lib/atech/base.rb
|
32
|
+
- lib/atech/configuration.rb
|
32
33
|
- lib/atech/extensions/controller_tests.rb
|
33
34
|
- lib/atech/extensions/seeds.rb
|
34
35
|
- lib/atech/extensions/string.rb
|
35
36
|
- lib/atech/helpers.rb
|
36
37
|
- lib/atech/network_restrictions.rb
|
38
|
+
- lib/atech/record_identifier.rb
|
39
|
+
- lib/atech/user_agent.rb
|
37
40
|
has_rdoc: true
|
38
41
|
homepage: http://github.com/atech/atech
|
39
42
|
licenses: []
|