ae_page_objects 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module AePageObjects
14
14
  autoload :DependenciesHook, 'ae_page_objects/core/dependencies_hook'
15
15
  autoload :Installable, 'ae_page_objects/core/installable'
16
16
  autoload :Configuration, 'ae_page_objects/core/configuration'
17
- autoload :Configurable, 'ae_page_objects/core/configurable'
17
+ autoload :Singleton, 'ae_page_objects/core/singleton'
18
18
  autoload :Application, 'ae_page_objects/core/application'
19
19
  autoload :ApplicationRouter, 'ae_page_objects/core/application_router'
20
20
  autoload :RakeRouter, 'ae_page_objects/core/rake_router'
@@ -1,51 +1,51 @@
1
1
  module AePageObjects
2
2
  class Application
3
- include Configurable
3
+ include AePageObjects::Singleton
4
4
 
5
5
  class << self
6
6
  private :new
7
7
 
8
+ attr_accessor :called_from
9
+
8
10
  delegate :initialize!, :to => :instance
11
+ delegate :config, :to => :instance
9
12
 
10
13
  def inherited(application_class)
11
14
  super
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
+
12
21
  application_class.parent.send(:include, ConstantResolver)
22
+ application_class.parent.page_objects_application = application_class
13
23
  end
14
24
  end
15
25
 
26
+ delegate :root_path, :to => :config
27
+
16
28
  delegate :router, :to => :config
17
29
  delegate :path_recognizes_url?, :to => :router
18
30
  delegate :generate_path, :to => :router
19
31
 
20
- def initialize
21
- ActiveSupport::Dependencies.autoload_paths.unshift(*all_autoload_paths)
22
-
23
- # Freeze so future modifications will fail rather than do nothing mysteriously
24
- config.eager_load_paths.freeze
25
- end
26
-
27
32
  def config
28
33
  @config ||= Configuration.new(self)
29
34
  end
30
35
 
31
36
  def initialize!
37
+ ActiveSupport::Dependencies.autoload_paths.unshift(root_path)
32
38
  eager_load!
33
39
  end
34
40
 
35
- def all_autoload_paths
36
- @all_autoload_paths ||= config.eager_load_paths.uniq
37
- end
38
-
39
41
  private
40
42
 
41
43
  def eager_load!
42
- config.eager_load_paths.each do |load_path|
43
- matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
44
+ matcher = /\A#{Regexp.escape(root_path)}\/(.*)\.rb\Z/
44
45
 
45
- Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
46
- dependency_name = file.sub(matcher, '\1')
47
- require_dependency dependency_name
48
- end
46
+ Dir.glob("#{root_path}/**/*.rb").sort.each do |file|
47
+ dependency_name = file.sub(matcher, '\1')
48
+ require_dependency dependency_name
49
49
  end
50
50
  end
51
51
  end
@@ -1,15 +1,12 @@
1
1
  module AePageObjects
2
2
  class Configuration
3
- attr_writer :router
3
+ attr_accessor :router, :root_path
4
4
 
5
5
  def initialize(application)
6
6
  @application = application
7
+ @root_path = application.class.called_from
7
8
  end
8
9
 
9
- def eager_load_paths
10
- @eager_load_paths ||= ["test/page_objects"]
11
- end
12
-
13
10
  def router
14
11
  @router ||= ApplicationRouter.new
15
12
  end
@@ -1,8 +1,15 @@
1
1
  module AePageObjects
2
2
  module ConstantResolver
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
+ included do
6
+ class << self
7
+ attr_accessor :page_objects_application
8
+ end
9
+ end
10
+
5
11
  module ClassMethods
12
+
6
13
  def const_name_for(from_mod, const_name)
7
14
  name_within_universe = ""
8
15
  if self != from_mod
@@ -12,21 +19,23 @@ module AePageObjects
12
19
  name_within_universe += "::#{const_name}"
13
20
  end
14
21
 
15
- def load_missing_constant(from_mod, const_name)
22
+ def load_missing_page_objects_constant(from_mod, const_name)
16
23
  path_for_constant = self.const_name_for(from_mod, const_name).underscore
17
24
 
18
- application = "#{self.name}::Application".constantize
19
- application.all_autoload_paths.each do |autoload_path|
20
- file_path = File.join(autoload_path, "#{path_for_constant}.rb").sub(/(\.rb)?$/, ".rb")
21
-
22
- if File.file?(file_path) && ! ActiveSupport::Dependencies.loaded.include?(File.expand_path(file_path))
23
- ActiveSupport::Dependencies.require_or_load file_path
24
- raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless ActiveSupport::Dependencies.local_const_defined?(from_mod, const_name)
25
- return from_mod.const_get(const_name)
25
+ file_path = File.join(page_objects_application.instance.root_path, "#{path_for_constant}.rb").sub(/(\.rb)?$/, ".rb")
26
+
27
+ if File.file?(file_path) && ! ActiveSupport::Dependencies.loaded.include?(File.expand_path(file_path))
28
+ ActiveSupport::Dependencies.require_or_load file_path
29
+
30
+ unless ActiveSupport::Dependencies.local_const_defined?(from_mod, const_name)
31
+ qualified_name = ActiveSupport::Dependencies.qualified_name_for(from_mod, const_name)
32
+ raise LoadError, "Expected #{file_path} to define #{qualified_name}"
26
33
  end
34
+
35
+ from_mod.const_get(const_name)
36
+ else
37
+ nil
27
38
  end
28
-
29
- nil
30
39
  end
31
40
  end
32
41
  end
@@ -15,7 +15,7 @@ module AePageObjects
15
15
 
16
16
  def load_missing_constant(from_mod, const_name)
17
17
  page_objects = DependenciesHook.containing_page_object_universe(from_mod)
18
- page_objects && page_objects.load_missing_constant(from_mod, const_name) || super
18
+ page_objects && page_objects.load_missing_page_objects_constant(from_mod, const_name) || super
19
19
  end
20
20
  end
21
21
  end
@@ -1,10 +1,8 @@
1
1
  module AePageObjects
2
- module Configurable
2
+ module Singleton
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- delegate :config, :to => :instance
7
-
8
6
  def instance
9
7
  @instance ||= new
10
8
  end
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Donnie Tognazzini
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-24 00:00:00 Z
18
+ date: 2013-06-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -110,7 +110,6 @@ files:
110
110
  - lib/ae_page_objects/concerns/visitable.rb
111
111
  - lib/ae_page_objects/core/application.rb
112
112
  - lib/ae_page_objects/core/application_router.rb
113
- - lib/ae_page_objects/core/configurable.rb
114
113
  - lib/ae_page_objects/core/configuration.rb
115
114
  - lib/ae_page_objects/core/constant_resolver.rb
116
115
  - lib/ae_page_objects/core/dependencies_hook.rb
@@ -119,6 +118,7 @@ files:
119
118
  - lib/ae_page_objects/core/dsl/form_for.rb
120
119
  - lib/ae_page_objects/core/internal_helpers.rb
121
120
  - lib/ae_page_objects/core/rake_router.rb
121
+ - lib/ae_page_objects/core/singleton.rb
122
122
  - lib/ae_page_objects/document.rb
123
123
  - lib/ae_page_objects/element.rb
124
124
  - lib/ae_page_objects/element_proxy.rb