shackles 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGZlYjI5ZDg0YmU2MDQ0MmI4YmRlYTc1ODQxODU3Zjg4NzBlNDhlOA==
5
- data.tar.gz: !binary |-
6
- ODdmYzI1NGFhN2ZjNDZjNDdhY2VhMzJkN2VlNjJhZjg0OTBhOTEwNA==
2
+ SHA1:
3
+ metadata.gz: 23205d6343336809e09e975d3be07cf530c2d190
4
+ data.tar.gz: 3f26bddb52cadf78b0ff40e4fa2c458d216d8e00
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Y2E0ZWMwY2M1ZmVlNzNmNjI3YTA1NDM4YTVlZGVlNDcwMmExMDIxNGE4ZTgw
10
- MDczNjgwNGJkMDhmYTRhMjk4YjIxZjIyMDY2NTZiYzBjNWYyZmQ2ZWE5ZTQ5
11
- MDcxMjYwZDYxZjAwMzg1OWQwYWJkOWRlN2YzMDY0YzZkYTFmNTg=
12
- data.tar.gz: !binary |-
13
- ZDA0ZDJiYmFhZTEwYzA5ZGI0NDkzYzYwMDU3YmUzNTQwNjA0ZjVkMTQ3NWQw
14
- YWNmNzk4YWJlZjdkYWUyZmVkM2IxYzdmMTc3YTBiZWYxZDQwN2Y2MGI3YjBl
15
- MTIxYTYzZjk5YmVmNmIyYjRhNTNlOTYyNDcyNWFhYmJjZDUxNzE=
6
+ metadata.gz: e11d0cce5aa33ef195fdc5559f0da888981806fa0b16929100cff327f391e7285c4cf9c421c3c33a79e86e6caaa6ed047ffd6980392cff895e2c397654f4b00c
7
+ data.tar.gz: e6b6a73d80c93bb76b3f5e9794ecb22d181b30808d90525c5d58f15c2fe42742cb39d73138460eb733c2326dfc3972076b4b83786cb07a5d9a1b610e4d9ff070
data/README.md CHANGED
@@ -49,3 +49,27 @@ if ENV['RAILS_DATABASE_USER']
49
49
  Shackles.apply_config!(:username => ENV['RAILS_DATABASE_USER'])
50
50
  end
51
51
  ```
52
+
53
+ Additionally **in Ruby 2.0+** you can include Shackles::HelperMethods and use several helpers
54
+ to execute methods on specific environments:
55
+
56
+ ```ruby
57
+ class SomeModel
58
+ include Shackles::HelperMethods
59
+
60
+ def expensive_read_only
61
+ ...
62
+ end
63
+ shackle_method :expensive_read_only, environment: :slave
64
+
65
+ def self.class_level_expensive_read_only
66
+ ...
67
+ end
68
+ shackle_class_method :class_level_expensive_read_only, environment: :slave
69
+
70
+ # helpers for multiple methods are also available
71
+
72
+ shackle_methods :instance_method_foo, :instance_method_bar, environment: :slave
73
+ shackle_class_methods :class_method_foo, :class_method_bar, environment: :slave
74
+ end
75
+ ```
@@ -18,6 +18,7 @@ module Shackles
18
18
  def initialize!
19
19
  require 'shackles/connection_handler'
20
20
  require 'shackles/connection_specification'
21
+ require 'shackles/helper_methods'
21
22
 
22
23
  activated_environments << Shackles.environment
23
24
 
@@ -0,0 +1,36 @@
1
+ module Shackles
2
+ module HelperMethods
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ # see readme for example usage
8
+ module ClassMethods
9
+ def shackle_class_methods(*methods, opts)
10
+ methods.each { |m| shackle_class_method(m, opts) }
11
+ end
12
+
13
+ def shackle_class_method(method, opts)
14
+ self.singleton_class.shackle_method(method, opts)
15
+ end
16
+
17
+ def shackle_methods(*methods, opts)
18
+ methods.each { |m| shackle_method(m, opts) }
19
+ end
20
+
21
+ def shackle_method(method, opts)
22
+ @shackles_module ||= begin
23
+ m = Module.new
24
+ self.prepend m
25
+ m
26
+ end
27
+
28
+ @shackles_module.class_eval <<-RUBY, __FILE__, __LINE__ + 1
29
+ def #{method}(*args)
30
+ Shackles.activate(#{opts[:environment].inspect}) { super }
31
+ end
32
+ RUBY
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Shackles
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,61 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shackles
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-03 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '4.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.2'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: mocha
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ! '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ! '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ! '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ! '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  description: Allows multiple environments in database.yml, and dynamically switching
@@ -70,6 +70,7 @@ files:
70
70
  - lib/shackles.rb
71
71
  - lib/shackles/connection_handler.rb
72
72
  - lib/shackles/connection_specification.rb
73
+ - lib/shackles/helper_methods.rb
73
74
  - lib/shackles/railtie.rb
74
75
  - lib/shackles/version.rb
75
76
  - spec/shackles_spec.rb
@@ -83,17 +84,17 @@ require_paths:
83
84
  - lib
84
85
  required_ruby_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - ! '>='
87
+ - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  requirements:
91
- - - ! '>='
92
+ - - ">="
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
96
  rubyforge_project:
96
- rubygems_version: 2.3.0
97
+ rubygems_version: 2.4.5
97
98
  signing_key:
98
99
  specification_version: 4
99
100
  summary: ActiveRecord database environment switching for slaves and least-privilege