Class: Enginery::Delete
- Inherits:
-
Object
show all
- Includes:
- Helpers
- Defined in:
- lib/enginery/delete.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#activerecord_associations, #app_config, #app_controllers, #app_models, #boot_app, #controller_exists?, #datamapper_associations, #dst_path, extract_setup, fail, #fail_unless_in_app_folder!, fail_verbosely, #in_app_folder?, #load_boot_rb, #load_file, #migrations_by_model, #model_exists?, o, parse_input, #routes_by_controller, #sequel_associations, #src_path, #unrootify, #valid_controller?, valid_db_type?, valid_engine?, valid_orm?, #valid_route?, valid_server?, validate_constant_name, #validate_route_name, #view_setups_for
Constructor Details
#initialize(dst_root) ⇒ Delete
Returns a new instance of Delete.
6
7
8
|
# File 'lib/enginery/delete.rb', line 6
def initialize dst_root
@dst_root = dst_root
end
|
Instance Attribute Details
#dst_root ⇒ Object
Returns the value of attribute dst_root.
4
5
6
|
# File 'lib/enginery/delete.rb', line 4
def dst_root
@dst_root
end
|
Instance Method Details
#controller(name) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/enginery/delete.rb', line 10
def controller name
controller_path, controller_object = valid_controller?(name)
routes_by_controller(name).each {|r| route(name, r)}
helper(name)
if File.exists?(controller_path)
o
o '*** Removing "%s" folder ***' % unrootify(controller_path)
FileUtils.rm_r(controller_path)
end
file = controller_path + CONTROLLER_SUFFIX
if File.exists?(file)
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
end
|
#helper(controller) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/enginery/delete.rb', line 77
def helper controller
_, ctrl = valid_controller?(controller)
file = dst_path(:helpers, class_to_route(controller) + HELPER_SUFFIX)
return unless File.exists?(file)
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
|
#migration(name) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/enginery/delete.rb', line 102
def migration name
name.nil? || name.empty? && fail("Please provide migration name")
Dir[dst_path(:migrations, '**/%s.*%s' % [name, MIGRATION_SUFFIX])].each do |file|
load_file file
if defined?(DataMapper::Migration) && Migrator::MigratorInstance.instance_of?(DataMapper::Migration)
Migrator.new(dst_root).update_model_file(Migrator::MigratorContext, :down)
end
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
end
|
#model(name) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/enginery/delete.rb', line 86
def model name
name.nil? || name.empty? && fail("Please provide model name")
file = dst_path(:models, class_to_route(name) + MODEL_SUFFIX)
if File.exists?(file)
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
migrations_by_model(name).each do |m|
migration m.split('.').first
end
rear_controller(name)
true
end
|
#rear_controller(model) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/enginery/delete.rb', line 32
def rear_controller model
file = dst_path(:rear_controllers, class_to_route(model) + ADMIN_SUFFIX)
if File.exists?(file)
o
o '*** Deleting "%s" file ***' % unrootify(file)
FileUtils.rm(file)
end
end
|
#route(controller, name) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/enginery/delete.rb', line 43
def route controller, name
file, * = valid_route?(controller, name)
if File.exists?(file)
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
view controller, name
spec controller, name
end
|
#spec(controller, route) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/enginery/delete.rb', line 65
def spec controller, route
_, controller_object = valid_controller?(controller)
_, route = valid_route?(controller, route)
path = dst_path(:specs, class_to_route(controller), '/')
file = path + route + SPEC_SUFFIX
return unless File.exists?(file)
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
|
#view(controller, route) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/enginery/delete.rb', line 54
def view controller, route
_, ctrl = valid_controller?(controller)
path, ext = view_setups_for(ctrl, route)
file = File.join(path, route + ext)
return unless File.exists?(file)
o '*** Deleting "%s" file ***' % unrootify(file)
o
FileUtils.rm(file)
end
|