floor_manager 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.3 / 2012-05-21
2
+
3
+ + Allows the argument :namespace in FloorManager.define. All classes are
4
+ constructed from constants in that namespace, instead of Object.
1
5
 
2
6
  == 0.1.2 / 2011-09-28
3
7
 
data/README CHANGED
@@ -29,6 +29,9 @@ And in your tests:
29
29
  This gives you two posts to test against. Both posts will have the same
30
30
  author, right down to the database id.
31
31
 
32
+ Look here for more documentation:
33
+ http://blog.absurd.li/2011/09/28/introducing_floor_manager.html
34
+
32
35
  INSTALLATION
33
36
 
34
37
  Either by installing from http://github.com/kschiess/floor_manager as a rails
@@ -43,7 +46,7 @@ Then just require it atop of your floor definitions as follows:
43
46
 
44
47
  COMPATIBILITY
45
48
 
46
- Has been tested with Ruby 1.9.2 and ActiveRecord/DataMapper.
49
+ Has been tested with Ruby 1.9.2/1.8.7 MRI and ActiveRecord/DataMapper.
47
50
 
48
51
  STATUS
49
52
 
data/lib/floor_manager.rb CHANGED
@@ -5,10 +5,10 @@ class FloorManager
5
5
 
6
6
  # Defines a new environment under the supervision of the floor manager.
7
7
  #
8
- def define(environment_name, &block)
8
+ def define(environment_name, options={}, &block)
9
9
  @floors ||= {}
10
10
 
11
- @floors[environment_name] = FloorManager::Floor.from_dsl(&block)
11
+ @floors[environment_name] = FloorManager::Floor.from_dsl(options, &block)
12
12
  end
13
13
 
14
14
  # Returns an instance of the environment.
@@ -3,12 +3,13 @@ module FloorManager::Employee
3
3
 
4
4
  # Base class for employees. No instances of this should be created.
5
5
  class Template
6
- def self.from_dsl(klass_name, &block)
7
- new(klass_name).tap { |emp| DSL.new(emp, &block) }
6
+ def self.from_dsl(klass_name, namespace=nil, &block)
7
+ new(klass_name, namespace).tap { |emp| DSL.new(emp, &block) }
8
8
  end
9
9
 
10
- def initialize(klass_name)
10
+ def initialize(klass_name, namespace=nil)
11
11
  @klass_name = klass_name
12
+ @namespace = namespace
12
13
  @attributes = Hash.new { |h,k| h[k] = Array.new }
13
14
  end
14
15
 
@@ -56,7 +57,7 @@ module FloorManager::Employee
56
57
 
57
58
  def produce_instance
58
59
  name = camelcase(@klass_name.to_s)
59
- Object.const_get(name).new
60
+ (@namespace || Object).const_get(name).new
60
61
  end
61
62
  def camelcase(str)
62
63
  str.gsub(%r((^|_)\w)) { |match| match[-1].upcase }
@@ -5,27 +5,30 @@
5
5
  #
6
6
  class FloorManager::Floor
7
7
  class DSL
8
- def initialize(&block)
8
+ def initialize(options, &block)
9
+ @namespace = options[:namespace] || nil
9
10
  @floor = FloorManager::Floor.new
10
11
  instance_eval(&block)
11
12
  end
12
13
 
13
14
  def one(name, opts={}, &block)
14
15
  klass_name = opts[:class] || name
15
- @floor.employees[name.to_sym] = FloorManager::Employee::Unique.from_dsl(klass_name, &block)
16
+ @floor.employees[name.to_sym] =
17
+ FloorManager::Employee::Unique.from_dsl(klass_name, @namespace, &block)
16
18
  end
17
19
 
18
20
  def any(name, opts={}, &block)
19
21
  klass_name = opts[:class] || name
20
- @floor.employees[name.to_sym] = FloorManager::Employee::Template.from_dsl(klass_name, &block)
22
+ @floor.employees[name.to_sym] =
23
+ FloorManager::Employee::Template.from_dsl(klass_name, @namespace, &block)
21
24
  end
22
25
 
23
26
  def object
24
27
  @floor
25
28
  end
26
29
  end
27
- def self.from_dsl(&block)
28
- DSL.new(&block).object
30
+ def self.from_dsl(options, &block)
31
+ DSL.new(options, &block).object
29
32
  end
30
33
 
31
34
  attr_reader :employees
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: floor_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-28 00:00:00.000000000Z
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blankslate
16
- requirement: &70363139380420 !ruby/object:Gem::Requirement
16
+ requirement: &70180139114780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.1.2.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70363139380420
24
+ version_requirements: *70180139114780
25
25
  description:
26
26
  email: kaspar.schiess@absurd.li
27
27
  executables: []
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 268557802399120653
56
+ hash: 1777111506648327494
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 1.8.10
65
+ rubygems_version: 1.8.17
66
66
  signing_key:
67
67
  specification_version: 3
68
68
  summary: Allows creation of a whole graph of objects on the fly during testing