Module: TestDummy
- Defined in:
- lib/test_dummy.rb
Defined Under Namespace
Modules: ClassMethods, Helper, InstanceMethods, Support, TestHelper Classes: Definition, Exception, Loader, Operation
Class Method Summary collapse
-
.add_module(new_module) ⇒ Object
Adds a mixin to the core Helper module.
-
.config(&block) ⇒ Object
Used in an initializer to define configuration parameters.
-
.declare(on_class, &block) ⇒ Object
Used to dynamically declare extensions on a particular class.
-
.define(&block) ⇒ Object
Used to configure defaults or aliases that can be used by all operations.
-
.dummy(*fields, &block) ⇒ Object
Used in an initializer to define things that can be dummied by all models if these properties are available.
-
.dummy_extensions_path ⇒ Object
Returns the current path used to load dummy extensions into models, or nil if no path is currently defined.
-
.dummy_extensions_path=(value) ⇒ Object
Defines the dummy extension path.
-
.included(base) ⇒ Object
This is called when this module is included.
Class Method Details
.add_module(new_module) ⇒ Object
Adds a mixin to the core Helper module
58 59 60 |
# File 'lib/test_dummy.rb', line 58 def self.add_module(new_module) Helper.send(:extend, new_module) end |
.config(&block) ⇒ Object
Used in an initializer to define configuration parameters.
97 98 99 |
# File 'lib/test_dummy.rb', line 97 def self.config(&block) TestDummy.instance_eval(&block) end |
.declare(on_class, &block) ⇒ Object
Used to dynamically declare extensions on a particular class. Has the effect of executing the block in the context of the class given.
53 54 55 |
# File 'lib/test_dummy.rb', line 53 def self.declare(on_class, &block) on_class.instance_eval(&block) end |
.define(&block) ⇒ Object
Used to configure defaults or aliases that can be used by all operations. Takes a block that should call definition methods like ‘dummy`.
64 65 66 |
# File 'lib/test_dummy.rb', line 64 def self.define(&block) instance_eval(&block) end |
.dummy(*fields, &block) ⇒ Object
Used in an initializer to define things that can be dummied by all models if these properties are available.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/test_dummy.rb', line 70 def self.dummy(*fields, &block) case (fields.last) when Hash = fields.pop end # REFACTOR: Adapt to new Operation style if ( and [:with]) with = [:with] fields.each do |name| if (Helper.respond_to?(with)) Helper.send(:alias_method, name, with) else Helper.send(:define_method, name) do send(with) end end end else fields.each do |name| Helper.send(:define_method, name, &block) end end end |
.dummy_extensions_path ⇒ Object
Returns the current path used to load dummy extensions into models, or nil if no path is currently defined. Defaults to “test/dummy” off of the Rails root if Rails is available.
29 30 31 32 33 34 35 36 37 |
# File 'lib/test_dummy.rb', line 29 def self.dummy_extensions_path @dummy_extensions_path ||= begin if (defined?(Rails)) File.('test/dummy', Rails.root) else nil end end end |
.dummy_extensions_path=(value) ⇒ Object
Defines the dummy extension path. The full path to the destination should be specified.
41 42 43 |
# File 'lib/test_dummy.rb', line 41 def self.dummy_extensions_path=(value) @dummy_extensions_path = value end |
.included(base) ⇒ Object
This is called when this module is included.
46 47 48 49 |
# File 'lib/test_dummy.rb', line 46 def self.included(base) base.send(:extend, ClassMethods) base.send(:include, InstanceMethods) end |