ae_page_objects 0.1.3.rl2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ae_page_objects.rb +7 -1
- data/lib/ae_page_objects/core/application.rb +39 -5
- data/lib/ae_page_objects/core/configuration.rb +15 -0
- data/lib/ae_page_objects/core/constant_resolver.rb +38 -0
- data/lib/ae_page_objects/core/dependencies_hook.rb +7 -0
- data/lib/ae_page_objects/version.rb +1 -1
- metadata +7 -6
data/lib/ae_page_objects.rb
CHANGED
@@ -5,12 +5,16 @@ require 'active_support/core_ext/module/delegation'
|
|
5
5
|
require 'active_support/core_ext/hash/keys'
|
6
6
|
require 'active_support/core_ext/object/try'
|
7
7
|
require 'active_support/core_ext/class'
|
8
|
-
require 'active_support/
|
8
|
+
require 'active_support/dependencies'
|
9
9
|
|
10
10
|
require 'ae_page_objects/version'
|
11
11
|
|
12
12
|
module AePageObjects
|
13
13
|
autoload :Universe, 'ae_page_objects/core/universe'
|
14
|
+
autoload :ConstantResolver, 'ae_page_objects/core/constant_resolver'
|
15
|
+
autoload :DependenciesHook, 'ae_page_objects/core/dependencies_hook'
|
16
|
+
autoload :Installable, 'ae_page_objects/core/installable'
|
17
|
+
autoload :Configuration, 'ae_page_objects/core/configuration'
|
14
18
|
autoload :Singleton, 'ae_page_objects/core/singleton'
|
15
19
|
autoload :Application, 'ae_page_objects/core/application'
|
16
20
|
autoload :ApplicationRouter, 'ae_page_objects/core/application_router'
|
@@ -40,6 +44,8 @@ module AePageObjects
|
|
40
44
|
autoload :Checkbox, 'ae_page_objects/elements/checkbox'
|
41
45
|
end
|
42
46
|
|
47
|
+
ActiveSupport::Dependencies.extend AePageObjects::DependenciesHook
|
48
|
+
|
43
49
|
|
44
50
|
|
45
51
|
|
@@ -5,11 +5,19 @@ module AePageObjects
|
|
5
5
|
class << self
|
6
6
|
private :new
|
7
7
|
|
8
|
-
|
8
|
+
attr_accessor :called_from
|
9
|
+
|
10
|
+
delegate :initialize!, :to => :instance
|
11
|
+
delegate :config, :to => :instance
|
9
12
|
|
10
13
|
def inherited(application_class)
|
11
14
|
super
|
12
15
|
|
16
|
+
application_class.called_from = begin
|
17
|
+
call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
|
18
|
+
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
|
19
|
+
end
|
20
|
+
|
13
21
|
application_class.universe.send(:include, Universe)
|
14
22
|
application_class.universe.page_objects_application_class = application_class
|
15
23
|
end
|
@@ -31,18 +39,44 @@ module AePageObjects
|
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
|
-
attr_writer :router
|
35
|
-
|
36
42
|
delegate :universe, :to => 'self.class'
|
37
43
|
|
44
|
+
delegate :paths, :to => :config
|
45
|
+
delegate :router, :to => :config
|
46
|
+
|
38
47
|
delegate :path_recognizes_url?, :to => :router
|
39
48
|
delegate :generate_path, :to => :router
|
40
49
|
|
41
|
-
def
|
42
|
-
@
|
50
|
+
def config
|
51
|
+
@config ||= Configuration.new(self)
|
43
52
|
end
|
44
53
|
|
45
54
|
def initialize!
|
55
|
+
ActiveSupport::Dependencies.autoload_paths.unshift(*paths)
|
56
|
+
eager_load!
|
57
|
+
end
|
58
|
+
|
59
|
+
def resolve_constant(from_mod, const_name)
|
60
|
+
resolver = ConstantResolver.new(self, from_mod, const_name)
|
61
|
+
|
62
|
+
resolved = nil
|
63
|
+
paths.each do |path|
|
64
|
+
break if resolved = resolver.load_constant_from_path(path)
|
65
|
+
end
|
66
|
+
resolved
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def eager_load!
|
72
|
+
paths.each do |path|
|
73
|
+
matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
|
74
|
+
|
75
|
+
Dir.glob("#{path}/**/*.rb").sort.each do |file|
|
76
|
+
dependency_name = file.sub(matcher, '\1')
|
77
|
+
require_dependency dependency_name
|
78
|
+
end
|
79
|
+
end
|
46
80
|
end
|
47
81
|
end
|
48
82
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :router, :paths
|
4
|
+
|
5
|
+
def initialize(application)
|
6
|
+
@application = application
|
7
|
+
@paths = [application.class.called_from]
|
8
|
+
end
|
9
|
+
|
10
|
+
def router
|
11
|
+
@router ||= ApplicationRouter.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
class ConstantResolver
|
3
|
+
def initialize(application, from_mod, const_name)
|
4
|
+
@application = application
|
5
|
+
@from_mod = from_mod
|
6
|
+
@const_name = const_name
|
7
|
+
|
8
|
+
@path_for_constant = path_for_constant
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_constant_from_path(path)
|
12
|
+
file_path = File.join(path, "#{@path_for_constant}.rb").sub(/(\.rb)?$/, ".rb")
|
13
|
+
|
14
|
+
if File.file?(file_path) && ! ActiveSupport::Dependencies.loaded.include?(File.expand_path(file_path))
|
15
|
+
ActiveSupport::Dependencies.require_or_load file_path
|
16
|
+
|
17
|
+
unless ActiveSupport::Dependencies.local_const_defined?(@from_mod, @const_name)
|
18
|
+
qualified_name = ActiveSupport::Dependencies.qualified_name_for(@from_mod, @const_name)
|
19
|
+
raise LoadError, "Expected #{@file_path} to define #{qualified_name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
@from_mod.const_get(@const_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def path_for_constant
|
29
|
+
name_within_universe = ""
|
30
|
+
if @application.universe != @from_mod
|
31
|
+
name_within_universe = @from_mod.name.split("#{@application.universe.name}::")[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
name_within_universe += "::#{@const_name}"
|
35
|
+
name_within_universe.underscore
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_page_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- 3
|
10
|
-
|
11
|
-
- 2
|
12
|
-
version: 0.1.3.rl2
|
10
|
+
version: 0.1.3
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Donnie Tognazzini
|
@@ -17,7 +15,7 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date: 2013-
|
18
|
+
date: 2013-06-12 00:00:00 Z
|
21
19
|
dependencies:
|
22
20
|
- !ruby/object:Gem::Dependency
|
23
21
|
type: :runtime
|
@@ -128,6 +126,9 @@ files:
|
|
128
126
|
- lib/ae_page_objects/concerns/visitable.rb
|
129
127
|
- lib/ae_page_objects/core/application.rb
|
130
128
|
- lib/ae_page_objects/core/application_router.rb
|
129
|
+
- lib/ae_page_objects/core/configuration.rb
|
130
|
+
- lib/ae_page_objects/core/constant_resolver.rb
|
131
|
+
- lib/ae_page_objects/core/dependencies_hook.rb
|
131
132
|
- lib/ae_page_objects/core/dsl/collection.rb
|
132
133
|
- lib/ae_page_objects/core/dsl/element.rb
|
133
134
|
- lib/ae_page_objects/core/dsl/form_for.rb
|