Module: Mobilify

Includes:
PageObject
Defined in:
lib/mobilify.rb,
lib/mobilify/version.rb

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



13
14
15
# File 'lib/mobilify.rb', line 13

def self.included(klass)
  klass.send :include, PageObject
end

Instance Method Details

#context?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mobilify.rb', line 17

def context?
  @context
end

#initialize(browser, opts = {}) ⇒ Object



7
8
9
10
11
# File 'lib/mobilify.rb', line 7

def initialize(browser, opts = {})
  super(browser, opts[:visit] || false)
  @context = opts[:context]
  mobilify! if @context
end

#mobilify!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mobilify.rb', line 21

def mobilify!
  match = false
  (contexts = []) << @context

  contexts.flatten.each do |c|
    next if match
    context = c.to_s
    methods.
      select { |m| m.to_s.start_with? "#{context}_" }.
      select { |m| respond_to? m.to_s.gsub("#{context}_", '') }.
      map { |m| self.method(m) }.each do |method|
        (class << self; self; end).class_eval do
          define_method(method.name.to_s.gsub("#{context}_", ''), method)
          match = true
        end
      end
  end
end