customize 0.0.1
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.
- data/.rspec +1 -0
- data/.watchr +42 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +157 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +3 -0
- data/README.rdoc +26 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/customize.gemspec +126 -0
- data/lib/customize/character.rb +5 -0
- data/lib/customize/characterize.rb +25 -0
- data/lib/customize/engine.rb +7 -0
- data/lib/customize/inherit_node.rb +11 -0
- data/lib/customize/inherited.rb +48 -0
- data/lib/customize.rb +9 -0
- data/lib/generators/customize/USAGE +8 -0
- data/lib/generators/customize/customize_generator.rb +17 -0
- data/lib/generators/customize/templates/migration.rb +24 -0
- data/spec/customize/characterize_spec.rb +66 -0
- data/spec/customize/inherited_spec.rb +70 -0
- data/spec/customize_spec.rb +7 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20120420023014_create_customize.rb +24 -0
- data/spec/dummy/db/schema.rb +37 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +202 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/spec_helper.rb +40 -0
- metadata +283 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/.watchr
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
def run(cmd)
|
2
|
+
puts(cmd)
|
3
|
+
`#{cmd}`
|
4
|
+
end
|
5
|
+
|
6
|
+
def growl(first, result)
|
7
|
+
passed = result.include?('0 failures')
|
8
|
+
title = "RSpec Test #{ passed ? "Successful!" : "Failed..."}"
|
9
|
+
image = passed ? "info" : "error"
|
10
|
+
severity = passed ? "low" : "critical"
|
11
|
+
body = passed ? "All Passed!" : result[result.rindex("Failures"), result.size].gsub(/(\\|<\/|\r\n:w|[\n\r"'])/,'')
|
12
|
+
options = "-i #{image} -u #{severity} '#{title}' '#{body}'"
|
13
|
+
system "notify-send #{options} &"
|
14
|
+
end
|
15
|
+
|
16
|
+
def run_spec(file)
|
17
|
+
unless File.exist?(file)
|
18
|
+
puts "#{file} does not exist"
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
puts "Running #{file}"
|
23
|
+
result = run("bundle exec rspec #{file}")
|
24
|
+
growl(result.split("\n").first, result) rescue nil
|
25
|
+
puts result
|
26
|
+
end
|
27
|
+
|
28
|
+
watch("spec/.*/*_spec\.rb") do |match|
|
29
|
+
run_spec match[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
watch("lib/(.*/.*)\.rb") do |match|
|
33
|
+
run_spec %{spec/#{match[1]}_spec.rb}
|
34
|
+
end
|
35
|
+
|
36
|
+
watch("spec/.*/.*/*_spec\.rb") do |match|
|
37
|
+
run_spec match[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
watch("lib/(.*/.*/.*)\.rb") do |match|
|
41
|
+
run_spec %{spec/#{match[1]}_spec.rb}
|
42
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://ruby.taobao.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "rails", ">= 3.0.12"
|
7
|
+
gem "capybara", ">= 0.4.0"
|
8
|
+
|
9
|
+
group :development,:test do
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "rspec-rails", ">= 2.8.0"
|
12
|
+
gem "sqlite3-ruby"
|
13
|
+
gem "with_model", '>= 0.1.5'
|
14
|
+
gem "rdoc", "~> 3.12"
|
15
|
+
gem "cucumber"
|
16
|
+
gem "bundler", ">= 1.0.0"
|
17
|
+
gem "jeweler", ">= 1.8.3"
|
18
|
+
gem "simplecov", ">= 0"
|
19
|
+
end
|
20
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
21
|
+
# gem 'ruby-debug'
|
22
|
+
# gem 'ruby-debug19'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://ruby.taobao.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.3)
|
5
|
+
actionpack (= 3.2.3)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.3)
|
8
|
+
activemodel (= 3.2.3)
|
9
|
+
activesupport (= 3.2.3)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.1)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.2)
|
17
|
+
activemodel (3.2.3)
|
18
|
+
activesupport (= 3.2.3)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.3)
|
21
|
+
activemodel (= 3.2.3)
|
22
|
+
activesupport (= 3.2.3)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.3)
|
26
|
+
activemodel (= 3.2.3)
|
27
|
+
activesupport (= 3.2.3)
|
28
|
+
activesupport (3.2.3)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
addressable (2.2.7)
|
32
|
+
arel (3.0.2)
|
33
|
+
builder (3.0.0)
|
34
|
+
capybara (1.1.2)
|
35
|
+
mime-types (>= 1.16)
|
36
|
+
nokogiri (>= 1.3.3)
|
37
|
+
rack (>= 1.0.0)
|
38
|
+
rack-test (>= 0.5.4)
|
39
|
+
selenium-webdriver (~> 2.0)
|
40
|
+
xpath (~> 0.1.4)
|
41
|
+
childprocess (0.3.1)
|
42
|
+
ffi (~> 1.0.6)
|
43
|
+
cucumber (1.1.9)
|
44
|
+
builder (>= 2.1.2)
|
45
|
+
diff-lcs (>= 1.1.2)
|
46
|
+
gherkin (~> 2.9.0)
|
47
|
+
json (>= 1.4.6)
|
48
|
+
term-ansicolor (>= 1.0.6)
|
49
|
+
diff-lcs (1.1.3)
|
50
|
+
erubis (2.7.0)
|
51
|
+
ffi (1.0.11)
|
52
|
+
gherkin (2.9.3)
|
53
|
+
json (>= 1.4.6)
|
54
|
+
git (1.2.5)
|
55
|
+
hike (1.2.1)
|
56
|
+
i18n (0.6.0)
|
57
|
+
jeweler (1.8.3)
|
58
|
+
bundler (~> 1.0)
|
59
|
+
git (>= 1.2.5)
|
60
|
+
rake
|
61
|
+
rdoc
|
62
|
+
journey (1.0.3)
|
63
|
+
json (1.6.6)
|
64
|
+
libwebsocket (0.1.3)
|
65
|
+
addressable
|
66
|
+
mail (2.4.4)
|
67
|
+
i18n (>= 0.4.0)
|
68
|
+
mime-types (~> 1.16)
|
69
|
+
treetop (~> 1.4.8)
|
70
|
+
mime-types (1.18)
|
71
|
+
multi_json (1.3.2)
|
72
|
+
nokogiri (1.5.2)
|
73
|
+
polyglot (0.3.3)
|
74
|
+
rack (1.4.1)
|
75
|
+
rack-cache (1.2)
|
76
|
+
rack (>= 0.4)
|
77
|
+
rack-ssl (1.3.2)
|
78
|
+
rack
|
79
|
+
rack-test (0.6.1)
|
80
|
+
rack (>= 1.0)
|
81
|
+
rails (3.2.3)
|
82
|
+
actionmailer (= 3.2.3)
|
83
|
+
actionpack (= 3.2.3)
|
84
|
+
activerecord (= 3.2.3)
|
85
|
+
activeresource (= 3.2.3)
|
86
|
+
activesupport (= 3.2.3)
|
87
|
+
bundler (~> 1.0)
|
88
|
+
railties (= 3.2.3)
|
89
|
+
railties (3.2.3)
|
90
|
+
actionpack (= 3.2.3)
|
91
|
+
activesupport (= 3.2.3)
|
92
|
+
rack-ssl (~> 1.3.2)
|
93
|
+
rake (>= 0.8.7)
|
94
|
+
rdoc (~> 3.4)
|
95
|
+
thor (~> 0.14.6)
|
96
|
+
rake (0.9.2.2)
|
97
|
+
rdoc (3.12)
|
98
|
+
json (~> 1.4)
|
99
|
+
rspec (2.9.0)
|
100
|
+
rspec-core (~> 2.9.0)
|
101
|
+
rspec-expectations (~> 2.9.0)
|
102
|
+
rspec-mocks (~> 2.9.0)
|
103
|
+
rspec-core (2.9.0)
|
104
|
+
rspec-expectations (2.9.1)
|
105
|
+
diff-lcs (~> 1.1.3)
|
106
|
+
rspec-mocks (2.9.0)
|
107
|
+
rspec-rails (2.9.0)
|
108
|
+
actionpack (>= 3.0)
|
109
|
+
activesupport (>= 3.0)
|
110
|
+
railties (>= 3.0)
|
111
|
+
rspec (~> 2.9.0)
|
112
|
+
rubyzip (0.9.7)
|
113
|
+
selenium-webdriver (2.21.2)
|
114
|
+
childprocess (>= 0.2.5)
|
115
|
+
ffi (~> 1.0)
|
116
|
+
libwebsocket (~> 0.1.3)
|
117
|
+
multi_json (~> 1.0)
|
118
|
+
rubyzip
|
119
|
+
simplecov (0.6.1)
|
120
|
+
multi_json (~> 1.0)
|
121
|
+
simplecov-html (~> 0.5.3)
|
122
|
+
simplecov-html (0.5.3)
|
123
|
+
sprockets (2.1.2)
|
124
|
+
hike (~> 1.2)
|
125
|
+
rack (~> 1.0)
|
126
|
+
tilt (~> 1.1, != 1.3.0)
|
127
|
+
sqlite3 (1.3.6)
|
128
|
+
sqlite3-ruby (1.3.3)
|
129
|
+
sqlite3 (>= 1.3.3)
|
130
|
+
term-ansicolor (1.0.7)
|
131
|
+
thor (0.14.6)
|
132
|
+
tilt (1.3.3)
|
133
|
+
treetop (1.4.10)
|
134
|
+
polyglot
|
135
|
+
polyglot (>= 0.3.1)
|
136
|
+
tzinfo (0.3.33)
|
137
|
+
with_model (0.2.6)
|
138
|
+
activerecord (>= 2.3.5, < 4.0.0)
|
139
|
+
rspec (< 3)
|
140
|
+
xpath (0.1.4)
|
141
|
+
nokogiri (~> 1.3)
|
142
|
+
|
143
|
+
PLATFORMS
|
144
|
+
ruby
|
145
|
+
|
146
|
+
DEPENDENCIES
|
147
|
+
bundler (>= 1.0.0)
|
148
|
+
capybara (>= 0.4.0)
|
149
|
+
cucumber
|
150
|
+
jeweler (>= 1.8.3)
|
151
|
+
rails (>= 3.0.12)
|
152
|
+
rdoc (~> 3.12)
|
153
|
+
rspec-rails (>= 2.8.0)
|
154
|
+
simplecov
|
155
|
+
sqlite3
|
156
|
+
sqlite3-ruby
|
157
|
+
with_model (>= 0.1.5)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Customize
|
2
|
+
|
3
|
+
== Introduction
|
4
|
+
|
5
|
+
customize is an rails engine intend to easy customize rails models with activerecord.
|
6
|
+
|
7
|
+
== Install
|
8
|
+
|
9
|
+
customize is designed for rails 3.0+
|
10
|
+
|
11
|
+
to use it, add to Gemfile:
|
12
|
+
|
13
|
+
gem 'customize'
|
14
|
+
|
15
|
+
install bundle:
|
16
|
+
|
17
|
+
bundle install
|
18
|
+
|
19
|
+
generate migrations and other resources:
|
20
|
+
|
21
|
+
rails g customize
|
22
|
+
|
23
|
+
|
24
|
+
= Copyright
|
25
|
+
|
26
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rdoc/task'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'Customize'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'jeweler'
|
28
|
+
Jeweler::Tasks.new do |gem|
|
29
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
30
|
+
gem.name = "customize"
|
31
|
+
gem.homepage = "http://github.com/lazing/customize"
|
32
|
+
gem.license = "MIT"
|
33
|
+
gem.summary = %Q{easy customize your domain model behavior}
|
34
|
+
gem.description = %Q{
|
35
|
+
easy customize your domain model, including:
|
36
|
+
characterize;
|
37
|
+
inherit;
|
38
|
+
formula
|
39
|
+
}
|
40
|
+
gem.email = "ryan@idolgo.com"
|
41
|
+
gem.authors = ["Ryan Wong"]
|
42
|
+
# dependencies defined in Gemfile
|
43
|
+
end
|
44
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/customize.gemspec
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "customize"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Wong"]
|
12
|
+
s.date = "2012-04-20"
|
13
|
+
s.description = "\n\t\teasy customize your domain model, including:\n\t\tcharacterize;\n\t\tinherit;\n\t\tformula\n\t"
|
14
|
+
s.email = "ryan@idolgo.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.markdown",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rspec",
|
21
|
+
".watchr",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"MIT-LICENSE",
|
25
|
+
"README.markdown",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"customize.gemspec",
|
30
|
+
"lib/customize.rb",
|
31
|
+
"lib/customize/character.rb",
|
32
|
+
"lib/customize/characterize.rb",
|
33
|
+
"lib/customize/engine.rb",
|
34
|
+
"lib/customize/inherit_node.rb",
|
35
|
+
"lib/customize/inherited.rb",
|
36
|
+
"lib/generators/customize/USAGE",
|
37
|
+
"lib/generators/customize/customize_generator.rb",
|
38
|
+
"lib/generators/customize/templates/migration.rb",
|
39
|
+
"spec/customize/characterize_spec.rb",
|
40
|
+
"spec/customize/inherited_spec.rb",
|
41
|
+
"spec/customize_spec.rb",
|
42
|
+
"spec/dummy/Rakefile",
|
43
|
+
"spec/dummy/app/controllers/application_controller.rb",
|
44
|
+
"spec/dummy/app/helpers/application_helper.rb",
|
45
|
+
"spec/dummy/app/views/layouts/application.html.erb",
|
46
|
+
"spec/dummy/config.ru",
|
47
|
+
"spec/dummy/config/application.rb",
|
48
|
+
"spec/dummy/config/boot.rb",
|
49
|
+
"spec/dummy/config/database.yml",
|
50
|
+
"spec/dummy/config/environment.rb",
|
51
|
+
"spec/dummy/config/environments/development.rb",
|
52
|
+
"spec/dummy/config/environments/production.rb",
|
53
|
+
"spec/dummy/config/environments/test.rb",
|
54
|
+
"spec/dummy/config/initializers/backtrace_silencers.rb",
|
55
|
+
"spec/dummy/config/initializers/inflections.rb",
|
56
|
+
"spec/dummy/config/initializers/mime_types.rb",
|
57
|
+
"spec/dummy/config/initializers/secret_token.rb",
|
58
|
+
"spec/dummy/config/initializers/session_store.rb",
|
59
|
+
"spec/dummy/config/locales/en.yml",
|
60
|
+
"spec/dummy/config/routes.rb",
|
61
|
+
"spec/dummy/db/migrate/20120420023014_create_customize.rb",
|
62
|
+
"spec/dummy/db/schema.rb",
|
63
|
+
"spec/dummy/public/404.html",
|
64
|
+
"spec/dummy/public/422.html",
|
65
|
+
"spec/dummy/public/500.html",
|
66
|
+
"spec/dummy/public/favicon.ico",
|
67
|
+
"spec/dummy/public/javascripts/application.js",
|
68
|
+
"spec/dummy/public/javascripts/controls.js",
|
69
|
+
"spec/dummy/public/javascripts/dragdrop.js",
|
70
|
+
"spec/dummy/public/javascripts/effects.js",
|
71
|
+
"spec/dummy/public/javascripts/prototype.js",
|
72
|
+
"spec/dummy/public/javascripts/rails.js",
|
73
|
+
"spec/dummy/public/stylesheets/.gitkeep",
|
74
|
+
"spec/dummy/script/rails",
|
75
|
+
"spec/integration/navigation_spec.rb",
|
76
|
+
"spec/spec_helper.rb"
|
77
|
+
]
|
78
|
+
s.homepage = "http://github.com/lazing/customize"
|
79
|
+
s.licenses = ["MIT"]
|
80
|
+
s.require_paths = ["lib"]
|
81
|
+
s.rubygems_version = "1.8.21"
|
82
|
+
s.summary = "easy customize your domain model behavior"
|
83
|
+
|
84
|
+
if s.respond_to? :specification_version then
|
85
|
+
s.specification_version = 3
|
86
|
+
|
87
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
88
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.0.12"])
|
89
|
+
s.add_runtime_dependency(%q<capybara>, [">= 0.4.0"])
|
90
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
91
|
+
s.add_development_dependency(%q<rspec-rails>, [">= 2.8.0"])
|
92
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
93
|
+
s.add_development_dependency(%q<with_model>, [">= 0.1.5"])
|
94
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
95
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
96
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
97
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
|
98
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
99
|
+
else
|
100
|
+
s.add_dependency(%q<rails>, [">= 3.0.12"])
|
101
|
+
s.add_dependency(%q<capybara>, [">= 0.4.0"])
|
102
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
103
|
+
s.add_dependency(%q<rspec-rails>, [">= 2.8.0"])
|
104
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
105
|
+
s.add_dependency(%q<with_model>, [">= 0.1.5"])
|
106
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
107
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
108
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
109
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
110
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
111
|
+
end
|
112
|
+
else
|
113
|
+
s.add_dependency(%q<rails>, [">= 3.0.12"])
|
114
|
+
s.add_dependency(%q<capybara>, [">= 0.4.0"])
|
115
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
116
|
+
s.add_dependency(%q<rspec-rails>, [">= 2.8.0"])
|
117
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
118
|
+
s.add_dependency(%q<with_model>, [">= 0.1.5"])
|
119
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
120
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
121
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
122
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
123
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Customize
|
2
|
+
module Characterize
|
3
|
+
|
4
|
+
def self.included base
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.has_many :characters, :class_name=>Customize::Character.name, :as=>:related
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
def character
|
13
|
+
@character ||= proc {
|
14
|
+
all_character = Character.where(:related_id=>(ascent_ids | [self.id]), :related_type=>self.class.name)
|
15
|
+
all_character.inject(HashWithIndifferentAccess.new) { |map, item|
|
16
|
+
map[item.key] = item.value
|
17
|
+
map
|
18
|
+
}
|
19
|
+
}.call
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Customize::InheritNode < ActiveRecord::Base
|
2
|
+
self.table_name = "customize_inherit_nodes"
|
3
|
+
belongs_to :parent_node, :class_name=>self.name, :foreign_key=> 'parent_id'
|
4
|
+
has_many :children, :class_name=>self.name, :foreign_key=>'parent_id'
|
5
|
+
|
6
|
+
after_destroy { |object|
|
7
|
+
object.class.where("right > :right and node_type = :type",
|
8
|
+
:right=>object.right, :type=>object.node_type).update_all("right = right -2")
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Customize
|
2
|
+
module Inherited
|
3
|
+
def self.included base
|
4
|
+
base.extend ClassMethods
|
5
|
+
base.has_one :inherit_node, :class_name=>Customize::InheritNode.name, :as=>:node, :dependent=>:destroy
|
6
|
+
|
7
|
+
base.after_create { |object|
|
8
|
+
object.create_inherit_node :left=>0, :right=>1
|
9
|
+
}
|
10
|
+
|
11
|
+
base.before_destroy { |object|
|
12
|
+
raise 'object should not have children when destroy' if object.inherit_node.children.size > 0
|
13
|
+
}
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
def inherit parent
|
21
|
+
raise 'should be save first' if self.new_record?
|
22
|
+
raise 'should be same class' if self.class != parent.class
|
23
|
+
inherit_node.parent_id = parent.inherit_node.id
|
24
|
+
right = parent.inherit_node.right
|
25
|
+
InheritNode.where("right >= ?", inherit_node.left).update_all("right = right+2")
|
26
|
+
inherit_node.left = right
|
27
|
+
inherit_node.right = right + 1
|
28
|
+
inherit_node.save
|
29
|
+
end
|
30
|
+
|
31
|
+
def ascent_ids
|
32
|
+
@ascent_ids ||=
|
33
|
+
InheritNode.where("left < :left and right > :right and node_type = :type",
|
34
|
+
:left=>inherit_node.left, :right=>inherit_node.right, :type=>self.class.name).pluck(:node_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def descent_ids
|
38
|
+
r = InheritNode.where("left > :left and right < :right and node_type = :type",
|
39
|
+
:left=>inherit_node.left, :right=>inherit_node.right, :type=>self.class.name)
|
40
|
+
r.pluck(:node_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def ascents
|
44
|
+
self.class.find ascent_ids
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/customize.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'customize/engine'
|
3
|
+
|
4
|
+
module Customize
|
5
|
+
autoload :Characterize, 'customize/characterize'
|
6
|
+
autoload :Inherited, 'customize/inherited'
|
7
|
+
autoload :InheritNode, 'customize/inherit_node'
|
8
|
+
autoload :Character, 'customize/character'
|
9
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CustomizeGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def self.next_migration_number(path)
|
6
|
+
unless @prev_migration_nr
|
7
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
8
|
+
else
|
9
|
+
@prev_migration_nr += 1
|
10
|
+
end
|
11
|
+
@prev_migration_nr.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_migrations
|
15
|
+
migration_template "migration.rb", "db/migrate/create_customize.rb"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateCustomize < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.change
|
4
|
+
create_table :customize_characters do |t|
|
5
|
+
t.string :key
|
6
|
+
t.string :type
|
7
|
+
t.text :value
|
8
|
+
t.string :related_type
|
9
|
+
t.integer :related_id
|
10
|
+
end
|
11
|
+
add_index :customize_characters, [:related_type, :related_id]
|
12
|
+
|
13
|
+
create_table :customize_inherit_nodes do |t|
|
14
|
+
t.integer :node_id
|
15
|
+
t.string :node_type
|
16
|
+
t.integer :left
|
17
|
+
t.integer :right
|
18
|
+
t.integer :parent_id
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :customize_inherit_nodes, [:node_type, :node_id]
|
22
|
+
add_index :customize_inherit_nodes, :parent_id
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Customize::Characterize do
|
4
|
+
|
5
|
+
with_model :product do
|
6
|
+
table do |t|
|
7
|
+
t.string :name
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
model do
|
12
|
+
include Customize::Characterize
|
13
|
+
include Customize::Inherited
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { Product.create! }
|
18
|
+
|
19
|
+
it "has characters" do
|
20
|
+
subject.characters.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
context "support type" do
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
@value = example.metadata[:description_args].first
|
27
|
+
@type = example.metadata[:type]
|
28
|
+
subject.characters.create :key=>@type, :type=>@type, :value=>@value
|
29
|
+
subject.reload
|
30
|
+
end
|
31
|
+
|
32
|
+
after :each do
|
33
|
+
subject.character[@type].should == @value
|
34
|
+
end
|
35
|
+
|
36
|
+
it 10, :type=>:integer do
|
37
|
+
end
|
38
|
+
|
39
|
+
it 12.34, :type=>:decimal do
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'string', :type=>:string do
|
43
|
+
end
|
44
|
+
|
45
|
+
it [1, 2, 3] do
|
46
|
+
end
|
47
|
+
|
48
|
+
it Hash.new(:foo=>:bar) do
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has readonly hash character" do
|
54
|
+
subject.characters.create! :key=>:foo, :value=>'bar'
|
55
|
+
subject.character[:foo].should == 'bar'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "has inherited character" do
|
59
|
+
parent = Product.create!
|
60
|
+
parent.characters.create! :key=>:p, :value=>1
|
61
|
+
subject.inherit parent
|
62
|
+
subject.character[:p].should == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|