Module: Vignette
- Defined in:
- lib/vignette.rb,
lib/vignette/version.rb
Defined Under Namespace
Modules: Errors
Constant Summary collapse
- VERSION =
"0.0.18"
Class Method Summary collapse
-
.active? ⇒ Boolean
Is Vignette active for this thread (i.e. do we have a repo?).
-
.clear_repo ⇒ Object
Clears the current repo on this thread.
-
.force_choice ⇒ Object
Get the force_choice for this thread.
-
.init(opts = {}) ⇒ Object
Set any initializers.
-
.repo ⇒ Object
Get the repo for this thread.
-
.set_repo(repo, force_choice = nil) ⇒ Object
Sets the current repo to be used to get and store tests for this thread.
-
.set_vig(vig) ⇒ Object
For this repo, store an update Vig.
-
.tests(vig = nil) ⇒ Object
Pull all the tests for this current repo.
-
.vig(repo = nil) ⇒ Object
From the repo (default whatever is set for the thread), grab Vignettes’ repo and unpack.
-
.with_repo(repo, force_choice = nil) ⇒ Object
Performs block with repo set to ‘repo` for this thread Force choice will be automatically selected if given.
Class Method Details
.active? ⇒ Boolean
Is Vignette active for this thread (i.e. do we have a repo?)
65 66 67 |
# File 'lib/vignette.rb', line 65 def self.active? !Thread.current[:vignette_repo].nil? end |
.clear_repo ⇒ Object
Clears the current repo on this thread
48 49 50 |
# File 'lib/vignette.rb', line 48 def self.clear_repo set_repo(nil, nil) end |
.force_choice ⇒ Object
Get the force_choice for this thread
77 78 79 80 81 |
# File 'lib/vignette.rb', line 77 def self.force_choice raise Errors::ConfigError.new("Repo not active, please call Vignette.set_repo before using Vignette (or use around_filter in Rails)") if !active? Thread.current[:vignette_force_choice] end |
.init(opts = {}) ⇒ Object
Set any initializers
35 36 37 38 39 |
# File 'lib/vignette.rb', line 35 def self.init(opts={}) opts.each do |k,v| Vignette.send("#{k}=", v) end end |
.repo ⇒ Object
Get the repo for this thread
70 71 72 73 74 |
# File 'lib/vignette.rb', line 70 def self.repo raise Errors::ConfigError.new("Repo not active, please call Vignette.set_repo before using Vignette (or use around_filter in Rails)") if !active? Thread.current[:vignette_repo] end |
.set_repo(repo, force_choice = nil) ⇒ Object
Sets the current repo to be used to get and store tests for this thread
42 43 44 45 |
# File 'lib/vignette.rb', line 42 def self.set_repo(repo, force_choice=nil) Thread.current[:vignette_repo] = repo Thread.current[:vignette_force_choice] = force_choice end |
.set_vig(vig) ⇒ Object
For this repo, store an update Vig
91 92 93 |
# File 'lib/vignette.rb', line 91 def self.set_vig(vig) repo[:v] = vig.to_json end |
.tests(vig = nil) ⇒ Object
Pull all the tests for this current repo
96 97 98 99 100 101 102 103 104 |
# File 'lib/vignette.rb', line 96 def self.tests(vig=nil) vig ||= Vignette.vig name_values = vig.values.map { |v| [ v['n'], [ v['t'], v['v'] ] ] }.group_by { |el| el[0] } arr = name_values.map { |k,v| [ k.to_s.to_sym, v.sort { |a,b| b[1][0] <=> a[1][0] }.first[1][1] ] } Hash[arr] end |
.vig(repo = nil) ⇒ Object
From the repo (default whatever is set for the thread), grab Vignettes’ repo and unpack
84 85 86 87 88 |
# File 'lib/vignette.rb', line 84 def self.vig(repo=nil) repo ||= Vignette.repo # allow using existing repo && repo[:v].present? ? JSON(repo[:v]) : {} end |
.with_repo(repo, force_choice = nil) ⇒ Object
Performs block with repo set to ‘repo` for this thread Force choice will be automatically selected if given
54 55 56 57 58 59 60 61 62 |
# File 'lib/vignette.rb', line 54 def self.with_repo(repo, force_choice=nil) begin Vignette.set_repo(repo, force_choice) yield ensure Vignette.clear_repo end end |