Class: RoCommands::Rails

Inherits:
Base show all
Defined in:
lib/ro_commands/rails.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

describe, inherited, start, usage

Methods included from Bash

#_bash, #add_time, #bash, #bash_capture, #bash_capture_array, #bash_lines, #bash_per, #bash_system, #bundle_exec, #err, err, #handle_path, #kernel_system, out, #out, #status, status

Class Method Details

.generators_mapObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/ro_commands/rails.rb', line 19

def generators_map
  @generators_map ||= {
      scaffold: 's',
      migration: 'm',
      model: 'mo',
      controller: 'c',
      assets: 'a',
      task: 't'
  }
end

.itemsObject



50
51
52
# File 'lib/ro_commands/rails.rb', line 50

def items
  @items ||= %w(migration scaffold model)
end

.items2Object



54
55
56
# File 'lib/ro_commands/rails.rb', line 54

def items2
  @items2 ||= %w(controller task assets)
end

.method_added(method) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/ro_commands/rails.rb', line 7

def method_added(method)
  super
  unless method.match(%r{})
    meths << method
  end
  meths.uniq!
end

.methsObject



15
16
17
# File 'lib/ro_commands/rails.rb', line 15

def meths
  @meths ||= []
end

.set_shortcut_method(item) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ro_commands/rails.rb', line 30

def set_shortcut_method(item)
  class_eval do
    #shortcut_item = generators_map[item.to_sym]
    #desc usage(shortcut_item), describe('generate', item, shortcut_item)
    #
    #define_method shortcut_item.to_sym do |*args|
    #  send item.to_sym, *args
    #end

    #shortcut_item_d = "#{shortcut_item}_d"
    #item_d = "#{item}_d"
    #
    #desc usage(shortcut_item_d), describe('destroy', item, shortcut_item_d)
    #define_method shortcut_item_d.to_sym do |*args|
    #  send item_d.to_sym, *args
    #end
  end
end

Instance Method Details

#get_assetsObject



129
130
131
132
133
134
# File 'lib/ro_commands/rails.rb', line 129

def get_assets
  assets = get_files('assets') do |f|
    f.match(%r{(js|coffee|scss|css)$})
  end
  Out.out(assets)
end

#get_controllersObject



138
139
140
141
# File 'lib/ro_commands/rails.rb', line 138

def get_controllers
  ctrls = get_rails_files('controllers')
  Out.out(ctrls)
end

#get_migrationsObject



110
111
112
113
114
115
116
117
118
# File 'lib/ro_commands/rails.rb', line 110

def get_migrations
  migrations = Find.find('db/migrate').select do |f|
    f.match(%r{rb$})
  end.map do |f|
    File.basename(f).gsub(%r(^\d+_), "").gsub(%r{\.rb$}, "")

  end
  Out.out(migrations)
end

#get_modelsObject



122
123
124
125
# File 'lib/ro_commands/rails.rb', line 122

def get_models
  models = get_rails_files('models')
  Out.out(models)
end

#get_scaffoldsObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ro_commands/rails.rb', line 96

def get_scaffolds
  ctrls = get_rails_files('controllers')
  if ctrls
    scaffolds = ctrls.flatten.map do |f|
      f.gsub(%r{_controller}) do |m|
        ""
      end
    end
    Out.out(scaffolds)
  end
end