makers 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +64 -70
- data/Rakefile +1 -14
- data/lib/generators/makers/install_generator.rb +20 -0
- data/lib/generators/makers/templates/definitions.rb +2 -0
- data/lib/makers.rb +8 -35
- data/lib/makers/definitions.rb +18 -27
- data/lib/makers/dsl/maker.rb +74 -0
- data/lib/makers/extensions/active_support/test_case.rb +15 -0
- data/lib/makers/maker.rb +32 -81
- data/lib/makers/proxy.rb +3 -42
- data/lib/makers/railtie.rb +10 -21
- data/lib/makers/version.rb +1 -1
- data/test/dummy/Rakefile +0 -1
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +1 -0
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/config/application.rb +3 -0
- data/test/dummy/config/database.yml +4 -22
- data/test/dummy/config/database.yml.travis +3 -0
- data/test/dummy/config/environments/development.rb +6 -2
- data/test/dummy/config/environments/production.rb +16 -24
- data/test/dummy/config/environments/test.rb +7 -12
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/secrets.yml +1 -1
- data/test/dummy/db/migrate/20140613221835_create_users.rb +0 -2
- data/test/dummy/db/migrate/20140615180954_create_posts.rb +0 -3
- data/test/dummy/db/schema.rb +38 -14
- data/test/dummy/log/development.log +176 -0
- data/test/dummy/log/test.log +1529 -0
- data/test/dummy/test/makers.rb +20 -0
- data/test/generator_test.rb +18 -0
- data/test/makers_test.rb +66 -0
- data/test/test_helper.rb +5 -18
- metadata +31 -48
- data/lib/generators/makers/model/model_generator.rb +0 -15
- data/lib/generators/makers/model/templates/maker.rb +0 -2
- data/lib/makers/callbacks.rb +0 -23
- data/lib/makers/configuration.rb +0 -10
- data/lib/makers/fetcher.rb +0 -18
- data/lib/makers/methods.rb +0 -11
- data/lib/makers/sequence.rb +0 -19
- data/test/aliases_test.rb +0 -20
- data/test/associations_test.rb +0 -50
- data/test/attributes_test.rb +0 -26
- data/test/callbacks_test.rb +0 -38
- data/test/clean_test.rb +0 -18
- data/test/dependent_test.rb +0 -30
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/test/makers/people.rb +0 -2
- data/test/dummy/test/makers/users.rb +0 -3
- data/test/fabricators_test.rb +0 -33
- data/test/generators_test.rb +0 -13
- data/test/inheritance_test.rb +0 -49
- data/test/lists_test.rb +0 -33
- data/test/load_test.rb +0 -13
- data/test/merges_test.rb +0 -31
data/lib/makers/maker.rb
CHANGED
@@ -1,112 +1,63 @@
|
|
1
1
|
module Makers
|
2
2
|
class Maker
|
3
3
|
|
4
|
-
attr_reader :options, :
|
4
|
+
attr_reader :options, :assignments, :object
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@name = name
|
6
|
+
def initialize(options, assignments)
|
8
7
|
@options = options
|
9
|
-
@
|
10
|
-
@
|
11
|
-
Fetcher.new(name, options, &block)
|
12
|
-
end
|
13
|
-
|
14
|
-
def parent
|
15
|
-
@parent ||= begin
|
16
|
-
if @options[:parent]
|
17
|
-
Makers.definitions.find(@options[:parent])
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def attributes_for(options={})
|
23
|
-
{}.tap do |hash|
|
24
|
-
iterate_attributes(options, proxy) do |name, value|
|
25
|
-
hash[name] = value
|
26
|
-
end
|
27
|
-
end
|
8
|
+
@assignments = assignments
|
9
|
+
@object = build_object
|
28
10
|
end
|
29
11
|
|
30
12
|
%w(build create).each do |name|
|
31
13
|
define_method name do |*args|
|
32
14
|
options = args.extract_options!
|
33
|
-
|
15
|
+
action = :"#{name}_one"
|
34
16
|
if args.any?
|
35
|
-
[]
|
36
|
-
|
37
|
-
|
38
|
-
end
|
17
|
+
collection = []
|
18
|
+
args.first.times do
|
19
|
+
collection << send(action, options)
|
39
20
|
end
|
21
|
+
collection
|
40
22
|
else
|
41
|
-
send
|
23
|
+
send action, options
|
42
24
|
end
|
43
25
|
end
|
44
26
|
end
|
45
27
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
28
|
+
def attributes
|
29
|
+
hash = {}
|
30
|
+
if options.has_key?(:parent)
|
31
|
+
hash.merge! Makers.definitions.find(options[:parent]).attributes
|
50
32
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
protected
|
55
|
-
|
56
|
-
def load
|
57
|
-
unless @loaded
|
58
|
-
if parent
|
59
|
-
@options = parent.options.merge(@options)
|
60
|
-
end
|
61
|
-
unless @options[:class] ||= @name.to_s.classify.constantize
|
62
|
-
raise "Class not found for maker #{@name}"
|
63
|
-
end
|
64
|
-
@proxy = Proxy.new(self, &@block)
|
65
|
-
@loaded = true
|
33
|
+
assignments.keys.each do |name|
|
34
|
+
hash[name] = object.send(name)
|
66
35
|
end
|
36
|
+
hash
|
67
37
|
end
|
68
38
|
|
69
|
-
|
70
|
-
@options[:class].new.tap do |instance|
|
71
|
-
trigger :before_build, instance
|
72
|
-
iterate_attributes(options, instance) do |name, value|
|
73
|
-
instance.send :"#{name}=", value
|
74
|
-
end
|
75
|
-
trigger :after_build, instance
|
76
|
-
end
|
77
|
-
end
|
39
|
+
private
|
78
40
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
Makers.records << instance
|
84
|
-
end
|
85
|
-
trigger :after_create, instance
|
41
|
+
def build_one(overrides={})
|
42
|
+
instance = options[:class_name].constantize.new
|
43
|
+
attributes.merge(overrides).each do |name, value|
|
44
|
+
instance.send "#{name}=", value
|
86
45
|
end
|
46
|
+
instance
|
87
47
|
end
|
88
48
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
callback.call instance
|
94
|
-
end
|
49
|
+
def create_one(overrides={})
|
50
|
+
instance = build_one(overrides)
|
51
|
+
instance.save
|
52
|
+
instance
|
95
53
|
end
|
96
54
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
context.instance_eval &value
|
102
|
-
when Sequence
|
103
|
-
value.generate context
|
104
|
-
else
|
105
|
-
value
|
106
|
-
end.tap do |value|
|
107
|
-
yield name, value
|
108
|
-
end
|
55
|
+
def build_object
|
56
|
+
klass = Class.new
|
57
|
+
assignments.each do |name, logic|
|
58
|
+
klass.send :define_method, name, &logic
|
109
59
|
end
|
60
|
+
klass.new
|
110
61
|
end
|
111
62
|
|
112
63
|
end
|
data/lib/makers/proxy.rb
CHANGED
@@ -1,51 +1,12 @@
|
|
1
1
|
module Makers
|
2
2
|
class Proxy
|
3
|
-
include Callbacks
|
4
3
|
|
5
|
-
def initialize(
|
6
|
-
@maker = maker
|
7
|
-
@attributes = []
|
8
|
-
@sequences = {}
|
4
|
+
def initialize(&block)
|
9
5
|
instance_eval &block
|
10
6
|
end
|
11
7
|
|
12
|
-
def
|
13
|
-
|
14
|
-
if @maker.parent
|
15
|
-
hash.merge! @maker.parent.proxy.attributes
|
16
|
-
end
|
17
|
-
@attributes.each do |name|
|
18
|
-
hash[name] = send(name)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def sequence(name, &block)
|
24
|
-
@attributes << name
|
25
|
-
@sequences[name] = Sequence.new(&block)
|
26
|
-
class_eval do
|
27
|
-
define_method(name) { @sequences[name] }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def method_missing(name, *args, &block)
|
32
|
-
unless name == :maker
|
33
|
-
options = args.extract_options!
|
34
|
-
strategy = options.delete(:strategy) || :build
|
35
|
-
if block_given?
|
36
|
-
logic = block
|
37
|
-
elsif maker = Makers.definitions.find(name) rescue nil
|
38
|
-
logic = -> { maker.send(strategy, options) }
|
39
|
-
elsif maker = Makers.definitions.find(name.to_s.singularize.to_sym) rescue nil
|
40
|
-
logic = -> { maker.send(strategy, (args.first || 1), options) }
|
41
|
-
elsif args.any?
|
42
|
-
logic = -> { args.first }
|
43
|
-
end
|
44
|
-
if defined? logic
|
45
|
-
@attributes.send (block_given? ? :push : :unshift), name
|
46
|
-
class_eval { define_method(name, logic) }
|
47
|
-
end
|
48
|
-
end
|
8
|
+
def maker(*args, &block)
|
9
|
+
DSL::Maker.new *args, &block
|
49
10
|
end
|
50
11
|
|
51
12
|
end
|
data/lib/makers/railtie.rb
CHANGED
@@ -1,32 +1,21 @@
|
|
1
1
|
module Makers
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
|
4
|
-
initializer
|
4
|
+
initializer :makers do
|
5
5
|
config.app_generators.test_framework(
|
6
6
|
config.app_generators.options[:rails][:test_framework],
|
7
|
-
fixture: false
|
8
|
-
fixture_replacement: :makers
|
7
|
+
fixture: false
|
9
8
|
)
|
10
|
-
if
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.include Makers::Methods
|
14
|
-
config.after(:each) do
|
15
|
-
Makers.clean
|
16
|
-
end
|
17
|
-
end
|
9
|
+
if Dir.exist?(Rails.root.join('spec'))
|
10
|
+
directory = 'spec'
|
18
11
|
else
|
19
|
-
|
20
|
-
include Makers::Methods
|
21
|
-
teardown do
|
22
|
-
Makers.clean
|
23
|
-
end
|
24
|
-
end
|
12
|
+
directory = 'test'
|
25
13
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
14
|
+
path = Rails.root.join("#{directory}/makers.rb")
|
15
|
+
if File.exist?(path)
|
16
|
+
load path
|
17
|
+
end
|
18
|
+
ActiveSupport::TestCase.include Makers::Extensions::ActiveSupport::TestCase
|
30
19
|
end
|
31
20
|
|
32
21
|
end
|
data/lib/makers/version.rb
CHANGED
data/test/dummy/Rakefile
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
</body>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= yield %>
|
11
|
+
</body>
|
14
12
|
</html>
|
data/test/dummy/bin/bundle
CHANGED
data/test/dummy/bin/rails
CHANGED
data/test/dummy/bin/rake
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# path to your application root.
|
6
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
7
|
+
|
8
|
+
Dir.chdir APP_ROOT do
|
9
|
+
# This script is a starting point to setup your application.
|
10
|
+
# Add necessary setup steps to this file:
|
11
|
+
|
12
|
+
puts "== Installing dependencies =="
|
13
|
+
system 'gem install bundler --conservative'
|
14
|
+
system 'bundle check || bundle install'
|
15
|
+
|
16
|
+
# puts "\n== Copying sample files =="
|
17
|
+
# unless File.exist?('config/database.yml')
|
18
|
+
# system 'cp config/database.yml.sample config/database.yml'
|
19
|
+
# end
|
20
|
+
|
21
|
+
puts "\n== Preparing database =="
|
22
|
+
system 'bin/rake db:setup'
|
23
|
+
|
24
|
+
puts "\n== Removing old logs and tempfiles =="
|
25
|
+
system 'rm -f log/*'
|
26
|
+
system 'rm -rf tmp/cache'
|
27
|
+
|
28
|
+
puts "\n== Restarting application server =="
|
29
|
+
system 'touch tmp/restart.txt'
|
30
|
+
end
|
@@ -18,5 +18,8 @@ module Dummy
|
|
18
18
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
19
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
20
|
# config.i18n.default_locale = :de
|
21
|
+
|
22
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
+
config.active_record.raise_in_transactional_callbacks = true
|
21
24
|
end
|
22
25
|
end
|
@@ -1,25 +1,7 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3
|
3
|
-
#
|
4
|
-
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
-
# gem 'sqlite3'
|
6
|
-
#
|
7
|
-
default: &default
|
8
|
-
adapter: sqlite3
|
9
|
-
pool: 5
|
10
|
-
timeout: 5000
|
11
|
-
|
12
1
|
development:
|
13
|
-
|
14
|
-
database:
|
2
|
+
adapter: postgresql
|
3
|
+
database: makers_development
|
15
4
|
|
16
|
-
# Warning: The database defined as "test" will be erased and
|
17
|
-
# re-generated from your development database when you run "rake".
|
18
|
-
# Do not set this db to the same as development or production.
|
19
5
|
test:
|
20
|
-
|
21
|
-
database:
|
22
|
-
|
23
|
-
production:
|
24
|
-
<<: *default
|
25
|
-
database: db/production.sqlite3
|
6
|
+
adapter: postgresql
|
7
|
+
database: makers_test
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Rails.application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
3
|
|
4
4
|
# In the development environment your application's code is reloaded on
|
@@ -10,7 +10,7 @@ Dummy::Application.configure do
|
|
10
10
|
config.eager_load = false
|
11
11
|
|
12
12
|
# Show full error reports and disable caching.
|
13
|
-
config.consider_all_requests_local
|
13
|
+
config.consider_all_requests_local = true
|
14
14
|
config.action_controller.perform_caching = false
|
15
15
|
|
16
16
|
# Don't care if the mailer can't send.
|
@@ -27,6 +27,10 @@ Dummy::Application.configure do
|
|
27
27
|
# number of complex assets.
|
28
28
|
config.assets.debug = true
|
29
29
|
|
30
|
+
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
31
|
+
# yet still be able to expire them through the digest params.
|
32
|
+
config.assets.digest = true
|
33
|
+
|
30
34
|
# Adds additional error checking when serving assets at runtime.
|
31
35
|
# Checks for improperly declared sprockets dependencies.
|
32
36
|
# Raises helpful error messages.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Rails.application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
3
|
|
4
4
|
# Code is not reloaded between requests.
|
@@ -11,20 +11,18 @@ Dummy::Application.configure do
|
|
11
11
|
config.eager_load = true
|
12
12
|
|
13
13
|
# Full error reports are disabled and caching is turned on.
|
14
|
-
config.consider_all_requests_local
|
14
|
+
config.consider_all_requests_local = false
|
15
15
|
config.action_controller.perform_caching = true
|
16
16
|
|
17
17
|
# Enable Rack::Cache to put a simple HTTP cache in front of your application
|
18
18
|
# Add `rack-cache` to your Gemfile before enabling this.
|
19
|
-
# For large-scale production use, consider using a caching reverse proxy like
|
19
|
+
# For large-scale production use, consider using a caching reverse proxy like
|
20
|
+
# NGINX, varnish or squid.
|
20
21
|
# config.action_dispatch.rack_cache = true
|
21
22
|
|
22
|
-
# Disable
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
config.serve_static_assets = false
|
27
|
-
end
|
23
|
+
# Disable serving static files from the `/public` folder by default since
|
24
|
+
# Apache or NGINX already handles this.
|
25
|
+
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
28
26
|
|
29
27
|
# Compress JavaScripts and CSS.
|
30
28
|
config.assets.js_compressor = :uglifier
|
@@ -33,21 +31,22 @@ Dummy::Application.configure do
|
|
33
31
|
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
34
32
|
config.assets.compile = false
|
35
33
|
|
36
|
-
#
|
34
|
+
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
35
|
+
# yet still be able to expire them through the digest params.
|
37
36
|
config.assets.digest = true
|
38
37
|
|
39
|
-
#
|
40
|
-
config.assets.version = '1.0'
|
38
|
+
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
41
39
|
|
42
40
|
# Specifies the header that your server uses for sending files.
|
43
|
-
# config.action_dispatch.x_sendfile_header =
|
44
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for
|
41
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
42
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
45
43
|
|
46
44
|
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
47
45
|
# config.force_ssl = true
|
48
46
|
|
49
|
-
#
|
50
|
-
|
47
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
48
|
+
# when problems arise.
|
49
|
+
config.log_level = :debug
|
51
50
|
|
52
51
|
# Prepend all log lines with the following tags.
|
53
52
|
# config.log_tags = [ :subdomain, :uuid ]
|
@@ -59,11 +58,7 @@ Dummy::Application.configure do
|
|
59
58
|
# config.cache_store = :mem_cache_store
|
60
59
|
|
61
60
|
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
62
|
-
# config.action_controller.asset_host =
|
63
|
-
|
64
|
-
# Precompile additional assets.
|
65
|
-
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
66
|
-
# config.assets.precompile += %w( search.js )
|
61
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
67
62
|
|
68
63
|
# Ignore bad email addresses and do not raise email delivery errors.
|
69
64
|
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
@@ -76,9 +71,6 @@ Dummy::Application.configure do
|
|
76
71
|
# Send deprecation notices to registered listeners.
|
77
72
|
config.active_support.deprecation = :notify
|
78
73
|
|
79
|
-
# Disable automatic flushing of the log to improve performance.
|
80
|
-
# config.autoflush_log = false
|
81
|
-
|
82
74
|
# Use default logging formatter so that PID and timestamp are not suppressed.
|
83
75
|
config.log_formatter = ::Logger::Formatter.new
|
84
76
|
|