customize 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/models/customize/formular.rb +16 -0
- data/customize.gemspec +7 -2
- data/lib/customize.rb +8 -0
- data/lib/customize/calculator/base.rb +16 -0
- data/lib/customize/calculator/expression_calculator.rb +11 -0
- data/lib/customize/engine.rb +7 -0
- data/lib/customize/formulaic.rb +8 -0
- data/lib/generators/customize/templates/migration.rb +11 -0
- data/spec/customize/formulaic_spec.rb +47 -0
- data/spec/customize_spec.rb +7 -1
- data/spec/dummy/config/environments/development.rb +0 -1
- data/spec/dummy/db/migrate/{20120420023014_create_customize.rb → 20120502085558_create_customize.rb} +12 -1
- data/spec/dummy/db/schema.rb +13 -2
- data/spec/integration/navigation_spec.rb +7 -0
- metadata +8 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Customize
|
2
|
+
class Formular < ActiveRecord::Base
|
3
|
+
belongs_to :related, :polymorphic=>true
|
4
|
+
serialize :calculator_attributes
|
5
|
+
|
6
|
+
def calculator
|
7
|
+
cal = calculator_name.constantize
|
8
|
+
cal_ins = cal.new
|
9
|
+
#calculator_attributes.try :symbolize_keys!
|
10
|
+
(calculator_attributes.keys & cal.inputs).each do |name|
|
11
|
+
cal_ins.instance_variable_set "@#{name}", calculator_attributes[name]
|
12
|
+
end if calculator_attributes
|
13
|
+
cal_ins
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/customize.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "customize"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ryan Wong"]
|
@@ -26,17 +26,22 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"app/controllers/customize/inherit_nodes_controller.rb",
|
28
28
|
"app/models/customize/character.rb",
|
29
|
+
"app/models/customize/formular.rb",
|
29
30
|
"app/models/customize/inherit_node.rb",
|
30
31
|
"config/routes.rb",
|
31
32
|
"customize.gemspec",
|
32
33
|
"lib/customize.rb",
|
34
|
+
"lib/customize/calculator/base.rb",
|
35
|
+
"lib/customize/calculator/expression_calculator.rb",
|
33
36
|
"lib/customize/characterize.rb",
|
34
37
|
"lib/customize/engine.rb",
|
38
|
+
"lib/customize/formulaic.rb",
|
35
39
|
"lib/customize/inherited.rb",
|
36
40
|
"lib/generators/customize/USAGE",
|
37
41
|
"lib/generators/customize/customize_generator.rb",
|
38
42
|
"lib/generators/customize/templates/migration.rb",
|
39
43
|
"spec/customize/characterize_spec.rb",
|
44
|
+
"spec/customize/formulaic_spec.rb",
|
40
45
|
"spec/customize/inherited_spec.rb",
|
41
46
|
"spec/customize_spec.rb",
|
42
47
|
"spec/dummy/Rakefile",
|
@@ -58,7 +63,7 @@ Gem::Specification.new do |s|
|
|
58
63
|
"spec/dummy/config/initializers/session_store.rb",
|
59
64
|
"spec/dummy/config/locales/en.yml",
|
60
65
|
"spec/dummy/config/routes.rb",
|
61
|
-
"spec/dummy/db/migrate/
|
66
|
+
"spec/dummy/db/migrate/20120502085558_create_customize.rb",
|
62
67
|
"spec/dummy/db/schema.rb",
|
63
68
|
"spec/dummy/public/404.html",
|
64
69
|
"spec/dummy/public/422.html",
|
data/lib/customize.rb
CHANGED
@@ -3,6 +3,14 @@ require 'has_scope'
|
|
3
3
|
require 'customize/engine'
|
4
4
|
|
5
5
|
module Customize
|
6
|
+
module Calculator
|
7
|
+
autoload :Base, 'customize/calculator/base'
|
8
|
+
autoload :ExpressionCalculator, 'customize/calculator/expression_calculator'
|
9
|
+
end
|
6
10
|
autoload :Characterize, 'customize/characterize'
|
7
11
|
autoload :Inherited, 'customize/inherited'
|
12
|
+
autoload :Formulaic, 'customize/formulaic'
|
13
|
+
|
14
|
+
mattr_accessor :calculators
|
15
|
+
@@calculators = []
|
8
16
|
end
|
data/lib/customize/engine.rb
CHANGED
@@ -4,5 +4,12 @@ module Customize
|
|
4
4
|
config.generators do |g|
|
5
5
|
# g.test_framework :rspec, :view_specs => false
|
6
6
|
end
|
7
|
+
config.customize = Customize
|
8
|
+
|
9
|
+
initializer "customize.load_calculators" do |app|
|
10
|
+
app.config.customize.calculators = [
|
11
|
+
Customize::Calculator::ExpressionCalculator
|
12
|
+
]
|
13
|
+
end
|
7
14
|
end
|
8
15
|
end
|
@@ -20,5 +20,16 @@ class CreateCustomize < ActiveRecord::Migration
|
|
20
20
|
|
21
21
|
add_index :customize_inherit_nodes, [:node_type, :node_id]
|
22
22
|
add_index :customize_inherit_nodes, :parent_id
|
23
|
+
|
24
|
+
create_table :customize_formulars do |t|
|
25
|
+
t.string :name
|
26
|
+
t.string :calculator_name
|
27
|
+
t.text :comment
|
28
|
+
t.text :calculator_attributes
|
29
|
+
t.string :related_type
|
30
|
+
t.integer :related_id
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index :customize_formulars, [:related_type, :related_id]
|
23
34
|
end
|
24
35
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Customize::Formulaic do
|
4
|
+
|
5
|
+
with_model :product do
|
6
|
+
table do |t|
|
7
|
+
end
|
8
|
+
model do
|
9
|
+
include Customize::Formulaic
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
with_model :instance do
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { Product.create }
|
17
|
+
|
18
|
+
context :formulaic_model do
|
19
|
+
it :has_formulars do
|
20
|
+
subject.formulars.should be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context :forumular do
|
25
|
+
subject { Customize::Formular.create :calculator_name=>Customize::Calculator::ExpressionCalculator.name }
|
26
|
+
|
27
|
+
it "has calculator" do
|
28
|
+
subject.calculator.should be_a(Customize::Calculator::ExpressionCalculator)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "store input value" do
|
32
|
+
subject.calculator_attributes = {:expression=>1}
|
33
|
+
subject.save
|
34
|
+
subject.reload
|
35
|
+
subject.calculator.expression.should == 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context :expression_calculator do
|
40
|
+
it "1+1=2" do
|
41
|
+
calculator = Customize::Calculator::ExpressionCalculator.new
|
42
|
+
calculator.expression = "1 + 1"
|
43
|
+
calculator.calculate(Instance.new).should == 2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/customize_spec.rb
CHANGED
@@ -11,7 +11,6 @@ Dummy::Application.configure do
|
|
11
11
|
|
12
12
|
# Show full error reports and disable caching
|
13
13
|
config.consider_all_requests_local = true
|
14
|
-
config.action_view.debug_rjs = true
|
15
14
|
config.action_controller.perform_caching = false
|
16
15
|
|
17
16
|
# Don't care if the mailer can't send
|
data/spec/dummy/db/migrate/{20120420023014_create_customize.rb → 20120502085558_create_customize.rb}
RENAMED
@@ -3,7 +3,7 @@ class CreateCustomize < ActiveRecord::Migration
|
|
3
3
|
def change
|
4
4
|
create_table :customize_characters do |t|
|
5
5
|
t.string :key
|
6
|
-
t.string :
|
6
|
+
t.string :value_type
|
7
7
|
t.text :value
|
8
8
|
t.string :related_type
|
9
9
|
t.integer :related_id
|
@@ -20,5 +20,16 @@ class CreateCustomize < ActiveRecord::Migration
|
|
20
20
|
|
21
21
|
add_index :customize_inherit_nodes, [:node_type, :node_id]
|
22
22
|
add_index :customize_inherit_nodes, :parent_id
|
23
|
+
|
24
|
+
create_table :customize_formulars do |t|
|
25
|
+
t.string :name
|
26
|
+
t.string :calculator_name
|
27
|
+
t.text :comment
|
28
|
+
t.text :calculator_attributes
|
29
|
+
t.string :related_type
|
30
|
+
t.integer :related_id
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index :customize_formulars, [:related_type, :related_id]
|
23
34
|
end
|
24
35
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,11 +11,11 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20120502085558) do
|
15
15
|
|
16
16
|
create_table "customize_characters", :force => true do |t|
|
17
17
|
t.string "key"
|
18
|
-
t.string "
|
18
|
+
t.string "value_type"
|
19
19
|
t.text "value"
|
20
20
|
t.string "related_type"
|
21
21
|
t.integer "related_id"
|
@@ -23,6 +23,17 @@ ActiveRecord::Schema.define(:version => 20120420023014) do
|
|
23
23
|
|
24
24
|
add_index "customize_characters", ["related_type", "related_id"], :name => "index_customize_characters_on_related_type_and_related_id"
|
25
25
|
|
26
|
+
create_table "customize_formulars", :force => true do |t|
|
27
|
+
t.string "name"
|
28
|
+
t.string "calculator_name"
|
29
|
+
t.text "comment"
|
30
|
+
t.text "calculator_attributes"
|
31
|
+
t.string "related_type"
|
32
|
+
t.integer "related_id"
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index "customize_formulars", ["related_type", "related_id"], :name => "index_customize_formulars_on_related_type_and_related_id"
|
36
|
+
|
26
37
|
create_table "customize_inherit_nodes", :force => true do |t|
|
27
38
|
t.integer "node_id"
|
28
39
|
t.string "node_type"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: customize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -236,17 +236,22 @@ files:
|
|
236
236
|
- VERSION
|
237
237
|
- app/controllers/customize/inherit_nodes_controller.rb
|
238
238
|
- app/models/customize/character.rb
|
239
|
+
- app/models/customize/formular.rb
|
239
240
|
- app/models/customize/inherit_node.rb
|
240
241
|
- config/routes.rb
|
241
242
|
- customize.gemspec
|
242
243
|
- lib/customize.rb
|
244
|
+
- lib/customize/calculator/base.rb
|
245
|
+
- lib/customize/calculator/expression_calculator.rb
|
243
246
|
- lib/customize/characterize.rb
|
244
247
|
- lib/customize/engine.rb
|
248
|
+
- lib/customize/formulaic.rb
|
245
249
|
- lib/customize/inherited.rb
|
246
250
|
- lib/generators/customize/USAGE
|
247
251
|
- lib/generators/customize/customize_generator.rb
|
248
252
|
- lib/generators/customize/templates/migration.rb
|
249
253
|
- spec/customize/characterize_spec.rb
|
254
|
+
- spec/customize/formulaic_spec.rb
|
250
255
|
- spec/customize/inherited_spec.rb
|
251
256
|
- spec/customize_spec.rb
|
252
257
|
- spec/dummy/Rakefile
|
@@ -268,7 +273,7 @@ files:
|
|
268
273
|
- spec/dummy/config/initializers/session_store.rb
|
269
274
|
- spec/dummy/config/locales/en.yml
|
270
275
|
- spec/dummy/config/routes.rb
|
271
|
-
- spec/dummy/db/migrate/
|
276
|
+
- spec/dummy/db/migrate/20120502085558_create_customize.rb
|
272
277
|
- spec/dummy/db/schema.rb
|
273
278
|
- spec/dummy/public/404.html
|
274
279
|
- spec/dummy/public/422.html
|
@@ -299,7 +304,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
299
304
|
version: '0'
|
300
305
|
segments:
|
301
306
|
- 0
|
302
|
-
hash:
|
307
|
+
hash: 1041955549
|
303
308
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
304
309
|
none: false
|
305
310
|
requirements:
|