customize 0.0.4 → 0.0.5

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
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.4"
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/20120420023014_create_customize.rb",
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
@@ -0,0 +1,16 @@
1
+ module Customize
2
+ module Calculator
3
+ class Base
4
+ cattr_accessor :inputs
5
+ @@inputs = []
6
+ def self.input name
7
+ sym = name.to_sym
8
+ @@inputs << sym
9
+ attr_accessor sym
10
+ end
11
+
12
+ def calculate instance
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Customize
2
+ module Calculator
3
+ class ExpressionCalculator < Base
4
+ input :expression
5
+
6
+ def calculate instance
7
+ instance.instance_eval expression
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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
@@ -0,0 +1,8 @@
1
+ module Customize
2
+ module Formulaic
3
+ def self.included base
4
+ base.has_many :formulars, :class_name=>Formular.name, :as=>:related
5
+ end
6
+ end
7
+
8
+ 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
@@ -4,4 +4,10 @@ describe Customize do
4
4
  it "should be valid" do
5
5
  Customize.should be_a(Module)
6
6
  end
7
- end
7
+
8
+ context :initializer do
9
+ it :has_calculators do
10
+ Customize.calculators.should have(1).items
11
+ end
12
+ end
13
+ end
@@ -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
@@ -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 :type
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
@@ -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 => 20120420023014) do
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 "type"
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"
@@ -6,4 +6,11 @@ describe "Navigation" do
6
6
  it "should be a valid app" do
7
7
  ::Rails.application.should be_a(Dummy::Application)
8
8
  end
9
+
10
+ it "should have config.customize" do
11
+
12
+ ::Rails.application.config.customize.should == Customize
13
+
14
+ end
15
+
9
16
  end
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
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/20120420023014_create_customize.rb
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: -24310993
307
+ hash: 1041955549
303
308
  required_rubygems_version: !ruby/object:Gem::Requirement
304
309
  none: false
305
310
  requirements: