wanderlust 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Wanderlust
2
+ VERSION = "0.1.0"
3
+ end
data/lib/wanderlust.rb ADDED
@@ -0,0 +1,75 @@
1
+ require "wanderlust/version"
2
+
3
+ module Wanderlust
4
+ class << self
5
+ def ensure_timezones
6
+ return unless safe_zone?
7
+
8
+ get_mysql_connection!
9
+
10
+ import_timezones! if lacking_mysql_timezone_support?
11
+ end
12
+
13
+ def import_timezones!
14
+ sql_file_location = "#{Dir.pwd}/lib/wanderlust/timezones.sql"
15
+ sql = File.read(sql_file_location)
16
+ statements = sql.split(';')
17
+ statements.pop # empty line at the end
18
+
19
+ ::ActiveRecord::Base.transaction do
20
+ statements.each do |statement|
21
+ @conn.execute(statement)
22
+ end
23
+ end
24
+ end
25
+
26
+ def lacking_mysql_timezone_support?
27
+ # No "true" way to determine this, so let's check for at least
28
+ # 100 time zones in MySQL. Open to suggestions!
29
+ @conn.execute("select count(*) from mysql.time_zone").first.first < 100
30
+ end
31
+
32
+ def get_mysql_connection!
33
+ begin
34
+ @conn = ::ActiveRecord::Base.connection
35
+ rescue ::ActiveRecord::ConnectionNotEstablished => e
36
+ puts <<-EOF
37
+
38
+ Wanderlust will borrow an existing ActiveRecord connection as opposed to creating
39
+ and managing a new one. Please make sure that `Wanderlust.ensure_timezones` is called after
40
+ `ActiveRecord::Base.establish_connection`
41
+
42
+ EOF
43
+ raise e
44
+ end
45
+ end
46
+
47
+ def safe_zone?
48
+ unless %w(test development dev local).include? ENV['RACK_ENV']
49
+ puts <<-EOF
50
+
51
+ Careful! Since Wanderlust inserts a bunch of timezone data into
52
+ your MySQL instance, it should only be used in your local test or
53
+ development environments.
54
+
55
+ EOF
56
+ return false
57
+ end
58
+
59
+ unless defined?(::ActiveRecord)
60
+ puts <<-EOF
61
+
62
+ Sorry! Wanderlust only works with ActiveRecord at the moment
63
+
64
+ ¯\\_(ツ)_/¯
65
+
66
+ Submit a PR on Github if you'd like more robust support
67
+
68
+ EOF
69
+ return false
70
+ end
71
+
72
+ return true
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wanderlust/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wanderlust"
8
+ spec.version = Wanderlust::VERSION
9
+ spec.authors = ["Shaker Islam"]
10
+ spec.email = ["shakerislam@gmail.com"]
11
+
12
+ spec.summary = %q{MySQL Timezone support for your ActiveRecord specs}
13
+ spec.homepage = "https://github.com/shaqq/wanderlust"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "true"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "activerecord-mysql2-adapter"
26
+ spec.add_development_dependency "activerecord"
27
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wanderlust
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shaker Islam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: 'true'
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord-mysql2-adapter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - shakerislam@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/wanderlust.rb
114
+ - lib/wanderlust/timezones.sql
115
+ - lib/wanderlust/version.rb
116
+ - wanderlust.gemspec
117
+ homepage: https://github.com/shaqq/wanderlust
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.6
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: MySQL Timezone support for your ActiveRecord specs
141
+ test_files: []
142
+ has_rdoc: