Class: Crabfarm::Modes::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/modes/generator.rb

Instance Method Summary collapse

Instance Method Details

#ensureObject



74
75
76
77
# File 'lib/crabfarm/modes/generator.rb', line 74

def ensure
  generate_dir([@base_path] + @path, false)
  self
end

#generate_app(_name, _target) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crabfarm/modes/generator.rb', line 11

def generate_app(_name, _target)
  with_external_path _target do
    binding = {
      name: _name,
      version: Crabfarm::VERSION
    }

    path(_name).ensure
    path(_name, '.gitignore').render('dot_gitignore')
    path(_name, 'Gemfile').render('Gemfile', binding)
    path(_name, 'Crabfile').render('Crabfile', binding)
    path(_name, '.rspec').render('dot_rspec', binding)
    path(_name, '.crabfarm').render('dot_crabfarm', binding)
    path(_name, 'boot.rb').render('boot.rb', binding)
    path(_name, 'bin', 'crabfarm').render('crabfarm_bin', binding, 0755)
    path(_name, 'app', 'parsers', '.gitkeep').render('dot_gitkeep')
    path(_name, 'app', 'states', '.gitkeep').render('dot_gitkeep')
    path(_name, 'app', 'helpers', '.gitkeep').render('dot_gitkeep')
    path(_name, 'spec', 'spec_helper.rb').render('spec_helper.rb', binding)
    path(_name, 'spec', 'snapshots', '.gitkeep').render('dot_gitkeep')
    path(_name, 'spec', 'mementos', '.gitkeep').render('dot_gitkeep')
    path(_name, 'spec', 'integration', '.gitkeep').render('dot_gitkeep')
    path(_name, 'logs', '.gitkeep').render('dot_gitkeep')
  end
end

#generate_parser(_name) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/crabfarm/modes/generator.rb', line 46

def generate_parser(_name)
  class_name = _name.camelize + 'Parser'
  with_crawler_path do
    binding = { parser_class: class_name }
    path('app', 'parsers', class_name.underscore + '.rb').render('parser.rb', binding)
    path('spec', 'parsers', class_name.underscore + '_spec.rb').render('parser_spec.rb', binding)
  end
end

#generate_state(_name) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/crabfarm/modes/generator.rb', line 37

def generate_state(_name)
  class_name = _name.camelize
  with_crawler_path do
    binding = { state_class: class_name.camelize }
    path('app', 'states', class_name.underscore + '.rb').render('state.rb', binding)
    path('spec', 'states', class_name.underscore + '_spec.rb').render('state_spec.rb', binding)
  end
end

#path(*_args) ⇒ Object



69
70
71
72
# File 'lib/crabfarm/modes/generator.rb', line 69

def path(*_args)
  @path = _args
  self
end

#render(_template, _binding = {}, _mod = nil) ⇒ Object



79
80
81
82
83
84
# File 'lib/crabfarm/modes/generator.rb', line 79

def render(_template, _binding={}, _mod=nil)
  path = [@base_path] + @path
  generate_dir(path[0..-2], true)
  render_template(_template, _binding, path, _mod)
  self
end

#with_crawler_pathObject



60
61
62
63
64
65
66
67
# File 'lib/crabfarm/modes/generator.rb', line 60

def with_crawler_path
  if defined? CF_PATH
    @base_path = CF_PATH
    yield
  else
    puts "This command can only be run inside a crabfarm application"
  end
end

#with_external_path(_target) ⇒ Object



55
56
57
58
# File 'lib/crabfarm/modes/generator.rb', line 55

def with_external_path(_target)
  @base_path = _target
  yield
end