acts_as_arter_flow_object 0.2.0 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_arter_flow_object}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["tim.teng"]
12
- s.date = %q{2010-04-19}
12
+ s.date = %q{2010-04-20}
13
13
  s.description = %q{simple progress indicator for game arters }
14
14
  s.email = %q{tim.rubist@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,9 +27,9 @@ Gem::Specification.new do |s|
27
27
  "generators/acts_as_arter_flow_object/USAGE",
28
28
  "generators/acts_as_arter_flow_object/acts_as_arter_flow_object_generator.rb",
29
29
  "generators/acts_as_arter_flow_object/templates/migration.rb",
30
+ "generators/acts_as_arter_flow_object/templates/models/arter_flow_object.rb",
30
31
  "lib/acts_as_arter_flow_object.rb",
31
32
  "lib/afo/acts_as_afo.rb",
32
- "lib/afo/arter_flow_object.rb",
33
33
  "test/helper.rb",
34
34
  "test/test_acts_as_arter_flow_object.rb"
35
35
  ]
@@ -6,6 +6,8 @@ class ActsAsArterFlowObjectGenerator < Rails::Generator::Base
6
6
  def manifest
7
7
  recorded_session = record do |m|
8
8
  unless options[:skip_migration]
9
+ m.template "models/arter_flow_object.rb", "app/models/arter_flow_object.rb"
10
+ m.directory "db/migrate"
9
11
  m.migration_template 'migration.rb', 'db/migrate',
10
12
  :assigns => { :migration_name => "CreateArterFlowObjectsTable" },
11
13
  :migration_file_name => "create_arter_flow_objects_table"
@@ -0,0 +1,39 @@
1
+ class ArterFlowObject < ActiveRecord::Base
2
+
3
+ default_scope :order => "created_at desc"
4
+
5
+ belongs_to :afoable, :polymorphic => true
6
+
7
+ STEPS = [:design, :model, :map, :rig]
8
+
9
+ STEPS.each do |s|
10
+ self.class_eval <<-EOF
11
+ belongs_to :#{s}_updater, :class_name => "User", :foreign_key => :#{s}_updater_id
12
+ EOF
13
+
14
+ self.module_eval <<-MDE
15
+ def toggle_#{s}! usr
16
+ self.toggle "#{s}".to_sym
17
+ self.#{s}_updater = usr
18
+ save!
19
+ end
20
+
21
+ def #{s}_updater_name
22
+ self.#{s}_updater.login rescue ''
23
+ end
24
+ MDE
25
+ end
26
+
27
+ def origin_human_type
28
+ Kernel.const_get(self.afoable_type).human_name
29
+ end
30
+
31
+ def origin_name
32
+ afoable.send(:title) rescue (afoable.send(:name) rescue 'Unknown')
33
+ end
34
+
35
+ def self.afo_types_for_select
36
+ find(:all, :select => "DISTINCT afoable_type").inject([]){|ary,rcd| ary << [rcd.origin_human_type, rcd.afoable_type]}
37
+ end
38
+
39
+ end
@@ -1,4 +1,4 @@
1
- require 'afo/arter_flow_object'
1
+ #require 'afo/arter_flow_object'
2
2
 
3
3
  require 'afo/acts_as_afo'
4
4
 
@@ -20,20 +20,27 @@ module ActsAsAFO
20
20
  create_arter_flow_objecjt
21
21
  end
22
22
 
23
- ArterFlowObject::STEPS.each do |s|
24
- module_eval <<-EOF
25
- def #{s}ed?
26
- arter_flow_object.send(:#{s}) rescue false
27
- end
28
-
29
- def toggle_#{s}!(usr)
30
- raise ActiveRecord::RecordNotFound.new("no corresponding arter flow object record found") unless arter_flow_object
31
- arter_flow_object.toggle(:#{s})
32
- arter_flow_object.#{s}_updater = usr
33
- arter_flow_object.save
34
- end
35
- EOF
36
- end
23
+ # lazy generating
24
+ # 'cause before user run " script/generate acts_as_arter_flow_object",
25
+ # acts_as_arter_flow_object.rb has not been copied to app/models,
26
+ # and this will caused a "uninitialized constant ActsAsAFO::InstanceMethods::ArterFlowObject" error.
27
+ klazz = Kernel.const_get("ArterFlowObject") rescue nil
28
+ unless klazz.nil?
29
+ ArterFlowObject::STEPS.each do |s|
30
+ module_eval <<-EOF
31
+ def #{s}ed?
32
+ !!arter_flow_object.send(:#{s}) rescue false
33
+ end
34
+
35
+ def toggle_#{s}!(usr)
36
+ raise ActiveRecord::RecordNotFound.new("no corresponding arter flow object record found") unless arter_flow_object
37
+ arter_flow_object.toggle(:#{s})
38
+ arter_flow_object.#{s}_updater = usr
39
+ arter_flow_object.save
40
+ end
41
+ EOF
42
+ end
43
+ end
37
44
 
38
45
  private
39
46
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - tim.teng
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-19 00:00:00 +08:00
17
+ date: 2010-04-20 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -38,9 +38,9 @@ files:
38
38
  - generators/acts_as_arter_flow_object/USAGE
39
39
  - generators/acts_as_arter_flow_object/acts_as_arter_flow_object_generator.rb
40
40
  - generators/acts_as_arter_flow_object/templates/migration.rb
41
+ - generators/acts_as_arter_flow_object/templates/models/arter_flow_object.rb
41
42
  - lib/acts_as_arter_flow_object.rb
42
43
  - lib/afo/acts_as_afo.rb
43
- - lib/afo/arter_flow_object.rb
44
44
  - test/helper.rb
45
45
  - test/test_acts_as_arter_flow_object.rb
46
46
  has_rdoc: true
@@ -1,19 +0,0 @@
1
- class ArterFlowObject < ActiveRecord::Base
2
-
3
- default_scope :order => "created_at desc"
4
-
5
- belongs_to :afoable, :polymorphic => true
6
-
7
- STEPS = [:design, :model, :map, :rig]
8
-
9
- STEPS.each do |s|
10
- self.class_eval <<-EOF
11
- belongs_to :#{s}_updater, :class_name => "User", :foreign_key => :#{s}_updater_id
12
- EOF
13
- end
14
-
15
- def self.afo_types_for_select
16
- find(:all, :select => "DISTINCT afoable_type").inject([]){|ary,rcd| tipe = rcd.call(:afoable_type); ary << [Kernel.const_get(tipe).human_name,tipe]}
17
- end
18
-
19
- end