Class: Masque
- Inherits:
-
Object
- Object
- Masque
- Defined in:
- lib/masque.rb,
lib/masque/dsl.rb,
lib/masque/version.rb
Defined Under Namespace
Modules: DSL
Constant Summary collapse
- VERSION =
"0.4.3"
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#compat_mode ⇒ Object
readonly
Returns the value of attribute compat_mode.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #compat_capybara_1x! ⇒ Object
- #compat_capybara_20! ⇒ Object
- #compat_capybara_21! ⇒ Object
-
#initialize(options = {}) ⇒ Masque
constructor
A new instance of Masque.
- #reset_session! ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Masque
Returns a new instance of Masque.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/masque.rb', line 20 def initialize( = {}) @options = @driver = [:driver] || :poltergeist case [:capybara_compat] when "2.1" when "2.0" when "1.x" else # default compat mode is 1.x (currently. IMO this is most useful for crawler, but any use case can be changed this decision) end @agent = Class.new do include Masque::DSL attr_accessor :session def initialize(session) @session = session end def method_missing(*args, &block) if block_given? session.__send__(*args, &block) else session.__send__(*args) end end end.new(Capybara::Session.new(@driver)) if @driver == :webkit h = Headless.new(.merge(:destroy_at_exit => false, :reuse => true)) h.start ObjectSpace.define_finalizer(@agent.driver.browser.instance_variable_get(:@connection)) do h.destroy end end end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
14 15 16 |
# File 'lib/masque.rb', line 14 def agent @agent end |
#compat_mode ⇒ Object (readonly)
Returns the value of attribute compat_mode.
14 15 16 |
# File 'lib/masque.rb', line 14 def compat_mode @compat_mode end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/masque.rb', line 14 def @options end |
Class Method Details
.run(options = {}, &block) ⇒ Object
16 17 18 |
# File 'lib/masque.rb', line 16 def self.run( = {}, &block) new().run(&block) end |
Instance Method Details
#compat_capybara_1x! ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/masque.rb', line 94 def # http://www.elabs.se/blog/60-introducing-capybara-2-1 @compat_mode = "1.x" Capybara.configure do |config| config.match = :prefer_exact config.ignore_hidden_elements = false end end |
#compat_capybara_20! ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/masque.rb', line 83 def # http://www.elabs.se/blog/60-introducing-capybara-2-1 @compat_mode = "2.0" Capybara.configure do |config| config.match = :one config. = true config.ignore_hidden_elements = true config.visible_text_only = true end end |
#compat_capybara_21! ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/masque.rb', line 72 def # https://github.com/jnicklas/capybara/blob/2.1.0/lib/capybara.rb#L323 @compat_mode = "2.1" Capybara.configure do |config| config.ignore_hidden_elements = true config.match = :smart config.exact = false config.visible_text_only = false end end |
#reset_session! ⇒ Object
62 63 64 65 66 |
# File 'lib/masque.rb', line 62 def reset_session! run do driver.reset! end end |
#run(&block) ⇒ Object
68 69 70 |
# File 'lib/masque.rb', line 68 def run(&block) @agent.instance_eval(&block) end |