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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 554e4dbed3deb4a10624287592080b74bbda3043
4
- data.tar.gz: ecb13e162859735de0365e132ef6fc6034a95165
3
+ metadata.gz: 585ba69af491c2dbd5b115dbf26a9042090d937f
4
+ data.tar.gz: 84e3c314e7614cca8f3ea7df53ec67f82ede4439
5
5
  SHA512:
6
- metadata.gz: ebb3a887fa3b8dff1716fd255da245f00d4aa036352e3b68b41abb87fb024614b28d4ce5365f5e8f4d6bcabbf4ed6832ac1f908da54ab5c0e77c54fafe9919f0
7
- data.tar.gz: f1766bb0300fbfc02b9d4439ce1c2348f243c843fc47cf7cce23022a560fbfbc53b31e69ef23d87e573a6ae6fbf653d80c92a473b9bbd1cffd261fe2f23ddbd5
6
+ metadata.gz: ef7b395e5c8315705d9a38dc59908c48fa4732244b7c517ff3bd356b125e48957777dbd41056e432ff9ee6ab4b5d0a814e619076105147f2fe87146d71d4fb88
7
+ data.tar.gz: b5fd177a289bae3978ee0ff533d9b617e64e66b4d5dfd849e3194f40b1a1ad8e29e820348cd277f94ad2bf6772b7809676759a6a7209d41d6056b0ed91d8862a
@@ -1,5 +1,10 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.0
4
+ - 2.3.4
5
+ - 2.4.1
6
+ gemfile:
7
+ - gemfiles/rails_5.0.gemfile
8
+ - gemfiles/rails_5.1.gemfile
9
+ - gemfiles/rails_edge.gemfile
5
10
  before_install: gem install bundler -v 1.14.3
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Mokei
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mokei`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
@@ -5,6 +5,7 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
+ t.warning = true
8
9
  end
9
10
 
10
11
  task :default => :test
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activesupport", "~> 5.0.0"
4
+ gem "activerecord", "~> 5.0.0"
5
+ gem "railties", "~> 5.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activesupport", "~> 5.1.0"
4
+ gem "activerecord", "~> 5.1.0"
5
+ gem "railties", "~> 5.1.0"
6
+
7
+ gemspec path: "../"
@@ -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,2 @@
1
+ class <%= class_name %>Builder < Mokei::Builder::Base
2
+ 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
@@ -1,5 +1,7 @@
1
1
  require "mokei/version"
2
+ require "mokei/load_builders"
3
+ require "mokei/railtie"
4
+ require "mokei/builder/base"
2
5
 
3
6
  module Mokei
4
- # Your code goes here...
5
7
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mokei
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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{WIP}
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.1
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-02-09 00:00:00.000000000 Z
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.8
188
+ rubygems_version: 2.6.12
95
189
  signing_key:
96
190
  specification_version: 4
97
- summary: WIP
191
+ summary: "`Mokei` is a builder library for Rails applications."
98
192
  test_files: []