journeyman 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc88ba880fcd67214a896dac32304a317037a538
4
- data.tar.gz: 5e943948aea70eb2bcc2f4e58ce65671ef04a691
3
+ metadata.gz: 80e6b19998e4c462744824ae4e1e7a4200ed7d91
4
+ data.tar.gz: 1ec090c64d2903e2d893ed40e2120f3ba5e61286
5
5
  SHA512:
6
- metadata.gz: 4d2deabc6944da9b531b69861d78a7867d74a0f05eb1b7f8dffe5620916fd7d64190a8d265715f5c0fd5b046a79b24130701de0c234680a45a9363b57dc0f786
7
- data.tar.gz: 0ed0da538b523579bf98500ff50e70de99ea7b80384b60190d9810279b8acbb981c9c6122f499f662b12b54cadee4e65404a577013c23be86579f8fb2f7021f7
6
+ metadata.gz: 38102932e520f7b84d41c580ace722799a23cb40d64a982be5d8c3b70e8d65903e5fc59d205ed33ce80363cca3b1e78387a7f71ce9a4170b79e17da9384e9711
7
+ data.tar.gz: 8dc8d9b34e8f1b9724c5326131e47a127df66b61a148a5f47e06f4b99363b548930d8d0fac0d795f1ec1be5b9817f21d823479675f257421eb82378ef8e5e935
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- Journeyman [![Gem Version](https://badge.fury.io/rb/journeyman.svg)](http://badge.fury.io/rb/journeyman) [![Build Status](https://travis-ci.org/ElMassimo/journeyman.svg)](https://travis-ci.org/ElMassimo/journeyman) [![Test Coverage](https://codeclimate.com/repos/5372dce769568034ff0304c2/badges/e014d258ab0dbe3f668e/coverage.svg)](https://codeclimate.com/repos/5372dce769568034ff0304c2/feed) [![Code Climate](https://codeclimate.com/repos/5372dce769568034ff0304c2/badges/e014d258ab0dbe3f668e/gpa.png)](https://codeclimate.com/repos/5372dce769568034ff0304c2/feed) [![Inline docs](http://inch-ci.org/github/ElMassimo/journeyman.svg)](http://inch-ci.org/github/ElMassimo/journeyman) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/journeyman/blob/master/LICENSE.txt)
1
+ Journeyman
2
2
  =====================
3
+ [![Gem Version](https://badge.fury.io/rb/journeyman.svg)](http://badge.fury.io/rb/journeyman) [![Code Climate](https://codeclimate.com/github/ElMassimo/journeyman/badges/gpa.svg)](https://codeclimate.com/github/ElMassimo/journeyman) [![Test Coverage](https://codeclimate.com/github/ElMassimo/journeyman/badges/coverage.svg)](https://codeclimate.com/github/ElMassimo/journeyman) [![Inline docs](http://inch-ci.org/github/ElMassimo/journeyman.svg)](http://inch-ci.org/github/ElMassimo/journeyman) [![Build Status](https://travis-ci.org/ElMassimo/journeyman.svg)](https://travis-ci.org/ElMassimo/journeyman) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/journeyman/blob/master/LICENSE.txt)
3
4
 
4
5
  Journeyman is a fixtures replacement with an extremely light definition syntax,
5
6
  providing two default build strategies, but allowing full customization on how
@@ -22,7 +23,7 @@ Journeyman allows you to provide the default attributes for creation as the
22
23
  return value of the definition block.
23
24
 
24
25
  ```ruby
25
- Journeyman.define :album do |c|
26
+ Journeyman.define :album do |t|
26
27
  {
27
28
  title: 'Wish You Were Here',
28
29
  recorded_ago: -> { (Date.today - Date.new(1975, 9, 12)).round / 365 },
@@ -77,16 +78,16 @@ ignore.
77
78
  attributes. Specially useful when combined with ignore.
78
79
 
79
80
  ```ruby
80
- Journeyman.define :employee do
81
- find { |id| Person.find(id) }
81
+ Journeyman.define :employee do |c|
82
+ c.find { |id| Person.find(id) }
82
83
 
83
- build { |attrs|
84
+ c.build { |attrs|
84
85
  attrs.delete(:company).new_employee(attrs)
85
86
  }
86
87
 
87
- ignore :work_history
88
+ c.ignore :work_history
88
89
 
89
- after_create { |employee, attrs|
90
+ c.after_create { |employee, attrs|
90
91
  attrs[:work_history].each do |history|
91
92
  check_references(history)
92
93
  end
@@ -1,6 +1,7 @@
1
1
  require 'journeyman/load'
2
2
  require 'journeyman/integration'
3
3
  require 'journeyman/definition'
4
+ require 'journeyman/missing_factory_error'
4
5
 
5
6
  # Public: Allows to define and use factory methods. It is capable of providing
6
7
  # `build`, `create`, `find`, and `default` methods, the last two are optional.
@@ -39,12 +40,20 @@ module Journeyman
39
40
 
40
41
  # Public: Convenience accessor for build methods.
41
42
  def self.build(name, *args, &block)
42
- @context.send("build_#{name}", *args, &block)
43
+ if @context.respond_to?("build_#{name}")
44
+ @context.send("build_#{name}", *args, &block)
45
+ else
46
+ raise MissingFactoryError, "'#{name}' factory is not defined"
47
+ end
43
48
  end
44
49
 
45
50
  # Public: Convenience accessor for create methods.
46
51
  def self.create(name, *args, &block)
47
- @context.send("create_#{name}", *args, &block)
52
+ if @context.respond_to?("create_#{name}")
53
+ @context.send("create_#{name}", *args, &block)
54
+ else
55
+ raise MissingFactoryError, "'#{name}' factory is not defined"
56
+ end
48
57
  end
49
58
 
50
59
  # Public: Convenience accessor for default methods.
@@ -1,4 +1,5 @@
1
1
  require 'journeyman/configuration'
2
+
2
3
  module Journeyman
3
4
 
4
5
  # Internal: Builds and creates objects, using the configuration provided.
@@ -0,0 +1,4 @@
1
+ module Journeyman
2
+ class MissingFactoryError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Journeyman
2
+
3
+ VERSION = '0.2.0'
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journeyman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-16 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Journeyman allows you to define factories with custom build methods,
14
14
  allowing you to easily bend object creation to the nuances of your application and
@@ -27,6 +27,8 @@ files:
27
27
  - lib/journeyman/definition.rb
28
28
  - lib/journeyman/integration.rb
29
29
  - lib/journeyman/load.rb
30
+ - lib/journeyman/missing_factory_error.rb
31
+ - lib/journeyman/version.rb
30
32
  homepage: https://github.com/ElMassimo/journeyman
31
33
  licenses:
32
34
  - MIT
@@ -40,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
43
- version: 1.9.3
45
+ version: 2.1.0
44
46
  required_rubygems_version: !ruby/object:Gem::Requirement
45
47
  requirements:
46
48
  - - ">="
@@ -48,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  version: '0'
49
51
  requirements: []
50
52
  rubyforge_project:
51
- rubygems_version: 2.2.2
53
+ rubygems_version: 2.4.8
52
54
  signing_key:
53
55
  specification_version: 4
54
56
  summary: Let your factories use your business logic, keeping them flexible and making