mokei 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/README.md +56 -3
- data/Rakefile +1 -0
- data/gemfiles/rails_5.0.gemfile +7 -0
- data/gemfiles/rails_5.1.gemfile +7 -0
- data/gemfiles/rails_edge.gemfile +11 -0
- data/lib/generators/rails/mokei_generator.rb +14 -0
- data/lib/generators/rspec/mokei_generator.rb +9 -0
- data/lib/generators/templates/builder.rb +2 -0
- data/lib/generators/test_unit/mokei_generator.rb +9 -0
- data/lib/mokei.rb +3 -1
- data/lib/mokei/builder/base.rb +39 -0
- data/lib/mokei/load_builders.rb +19 -0
- data/lib/mokei/railtie.rb +16 -0
- data/lib/mokei/version.rb +1 -1
- data/mokei.gemspec +8 -2
- metadata +99 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 585ba69af491c2dbd5b115dbf26a9042090d937f
|
4
|
+
data.tar.gz: 84e3c314e7614cca8f3ea7df53ec67f82ede4439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef7b395e5c8315705d9a38dc59908c48fa4732244b7c517ff3bd356b125e48957777dbd41056e432ff9ee6ab4b5d0a814e619076105147f2fe87146d71d4fb88
|
7
|
+
data.tar.gz: b5fd177a289bae3978ee0ff533d9b617e64e66b4d5dfd849e3194f40b1a1ad8e29e820348cd277f94ad2bf6772b7809676759a6a7209d41d6056b0ed91d8862a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Mokei
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/y-yagi/mokei.svg?branch=master)](https://travis-ci.org/y-yagi/mokei) [![Code Climate](https://codeclimate.com/github/y-yagi/mokei/badges/gpa.svg)](https://codeclimate.com/github/y-yagi/mokei)
|
4
4
|
|
5
|
-
|
5
|
+
`Mokei` is a builder library for Rails applications. It is mainly intended for use in test.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,60 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
# migration file
|
27
|
+
ActiveRecord::Schema.define do
|
28
|
+
create_table :users, force: true do |t|
|
29
|
+
t.string :name
|
30
|
+
t.string :email
|
31
|
+
t.boolean :active, default: false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# model
|
36
|
+
class User < ActiveRecord::Base
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# builder
|
42
|
+
# test/builders/user_builder.rb
|
43
|
+
class UserBuilder < Mokei::Builder::Base
|
44
|
+
def dummy
|
45
|
+
target.email = "dummy@example.com"
|
46
|
+
target.name = "dummy account"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
```
|
52
|
+
user = UserBuilder.new.dummy.build
|
53
|
+
=> #<User id: nil, name: "dummy account", email: "dummy@example.com", active: false, created_at: nil, updated_at: nil>
|
54
|
+
```
|
55
|
+
|
56
|
+
By calling the `build` method you can get the object to build. Within the builder class, you can use the object to be built with `target`.
|
57
|
+
|
58
|
+
Also, the method defined for the builder is chainable.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# builder
|
62
|
+
# test/builders/user_builder.rb
|
63
|
+
class UserBuilder < Mokei::Builder::Base
|
64
|
+
def dummy
|
65
|
+
target.email = "dummy@example.com"
|
66
|
+
target.name = "dummy account"
|
67
|
+
end
|
68
|
+
|
69
|
+
def registered
|
70
|
+
target.active = true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
```
|
76
|
+
user = UserBuilder.new.dummy.registered.build
|
77
|
+
=> #<User id: nil, name: "dummy account", email: "dummy@example.com", active: true, created_at: nil, updated_at: nil>
|
78
|
+
```
|
26
79
|
|
27
80
|
## Development
|
28
81
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git "https://github.com/rails/rails.git", :branch => "master" do
|
4
|
+
gem "activesupport"
|
5
|
+
gem "activerecord"
|
6
|
+
gem "railties"
|
7
|
+
end
|
8
|
+
|
9
|
+
gem "arel", git: "https://github.com/rails/arel.git", branch: "master"
|
10
|
+
|
11
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class MokeiGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc <<DESC
|
7
|
+
Description:
|
8
|
+
Create builder files for model.
|
9
|
+
DESC
|
10
|
+
|
11
|
+
hook_for :test_framework
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Rspec
|
2
|
+
class MokeiGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../../templates', __FILE__)
|
4
|
+
|
5
|
+
def create_builder_file
|
6
|
+
template "builder.rb", File.join("test/builders", class_path, "#{file_name}_builder.rb")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module TestUnit
|
2
|
+
class MokeiGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../../templates', __FILE__)
|
4
|
+
|
5
|
+
def create_builder_file
|
6
|
+
template "builder.rb", File.join("test/builders", class_path, "#{file_name}_builder.rb")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/mokei.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "tapper"
|
2
|
+
require "active_support"
|
3
|
+
require "active_support/inflector"
|
4
|
+
|
5
|
+
module Mokei
|
6
|
+
module Builder
|
7
|
+
class Base
|
8
|
+
attr_reader :target
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def inherited(child)
|
12
|
+
child.include(Tapper)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
target_class = determine_target(self.class.to_s)
|
18
|
+
@target = target_class.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
target
|
23
|
+
end
|
24
|
+
|
25
|
+
def create!
|
26
|
+
raise NotImplementedError unless target.respond_to?(:save!)
|
27
|
+
|
28
|
+
target.save!
|
29
|
+
target
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def determine_target(class_name)
|
35
|
+
class_name.sub!(/Builder$/, "").constantize
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mokei
|
2
|
+
class << self
|
3
|
+
attr_accessor :builder_paths
|
4
|
+
end
|
5
|
+
|
6
|
+
self.builder_paths = %w(builders test/builders)
|
7
|
+
|
8
|
+
def self.load_builders!
|
9
|
+
absolute_builder_paths = builder_paths.map { |path| File.expand_path(path) }
|
10
|
+
|
11
|
+
absolute_builder_paths.uniq.each do |path|
|
12
|
+
load("#{path}.rb") if File.exist?("#{path}.rb")
|
13
|
+
|
14
|
+
if File.directory? path
|
15
|
+
Dir[File.join(path, '**', '*.rb')].sort.each { |file| load file }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
module Mokei
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "mokei.set_builder_paths" do
|
6
|
+
Mokei.builder_paths = [
|
7
|
+
Rails.root.join("builders"),
|
8
|
+
Rails.root.join("test", "builders")
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
config.after_initialize do
|
13
|
+
Mokei.load_builders!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/mokei/version.rb
CHANGED
data/mokei.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'mokei/version'
|
@@ -9,7 +8,8 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ["Yuji Yaginuma"]
|
10
9
|
spec.email = ["yuuji.yaginuma@gmail.com"]
|
11
10
|
|
12
|
-
spec.summary = %q{
|
11
|
+
spec.summary = %q{`Mokei` is a builder library for Rails applications.}
|
12
|
+
spec.homepage = "https://github.com/y-yagi/mokei"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -19,6 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "activesupport"
|
23
|
+
spec.add_dependency "activerecord"
|
24
|
+
spec.add_dependency "railties"
|
25
|
+
spec.add_dependency "tapper"
|
26
|
+
spec.add_development_dependency "byebug"
|
27
|
+
spec.add_development_dependency "sqlite3"
|
22
28
|
spec.add_development_dependency "bundler", "~> 1.14"
|
23
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
30
|
spec.add_development_dependency "minitest", "~> 5.0"
|
metadata
CHANGED
@@ -1,15 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mokei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Yaginuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tapper
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
13
97
|
- !ruby/object:Gem::Dependency
|
14
98
|
name: bundler
|
15
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,10 +152,20 @@ files:
|
|
68
152
|
- Rakefile
|
69
153
|
- bin/console
|
70
154
|
- bin/setup
|
155
|
+
- gemfiles/rails_5.0.gemfile
|
156
|
+
- gemfiles/rails_5.1.gemfile
|
157
|
+
- gemfiles/rails_edge.gemfile
|
158
|
+
- lib/generators/rails/mokei_generator.rb
|
159
|
+
- lib/generators/rspec/mokei_generator.rb
|
160
|
+
- lib/generators/templates/builder.rb
|
161
|
+
- lib/generators/test_unit/mokei_generator.rb
|
71
162
|
- lib/mokei.rb
|
163
|
+
- lib/mokei/builder/base.rb
|
164
|
+
- lib/mokei/load_builders.rb
|
165
|
+
- lib/mokei/railtie.rb
|
72
166
|
- lib/mokei/version.rb
|
73
167
|
- mokei.gemspec
|
74
|
-
homepage:
|
168
|
+
homepage: https://github.com/y-yagi/mokei
|
75
169
|
licenses:
|
76
170
|
- MIT
|
77
171
|
metadata: {}
|
@@ -91,8 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
185
|
version: '0'
|
92
186
|
requirements: []
|
93
187
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.6.
|
188
|
+
rubygems_version: 2.6.12
|
95
189
|
signing_key:
|
96
190
|
specification_version: 4
|
97
|
-
summary:
|
191
|
+
summary: "`Mokei` is a builder library for Rails applications."
|
98
192
|
test_files: []
|