Class: RComponent::Applier

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_component.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_root, rails_root, autofire = true) ⇒ Applier

Returns a new instance of Applier.



54
55
56
57
58
59
# File 'lib/rails_component.rb', line 54

def initialize(component_root, rails_root, autofire = true)
  @rails_root = Pathname.new(rails_root)
  @component_root = Pathname.new(component_root)

  fire_recept!(File.read(@component_root + 'recept.rb')) if autofire
end

Class Method Details

.remote(url, rails_root) ⇒ Object



44
45
46
47
48
# File 'lib/rails_component.rb', line 44

def self.remote(url, rails_root)
  dir = Dir.mktmpdir
  Git.clone(url, dir)
  new(dir, rails_root)
end

.remote_recept(url, rails_root) ⇒ Object



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

def self.remote_recept(url, rails_root)
  new(rails_root, rails_root, false).fire_recept!(open(url).read)
end

Instance Method Details

#clone_files(*list) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rails_component.rb', line 66

def clone_files(*list)
  Dir.chdir(@component_root) do 
    list.each do |file|
      if File.exist?(@component_root + file)
        copy_file(file)
      else
        Dir.glob(file).each {|f| copy_file(f) }
      end
    end
  end
end

#commit_changes(message) ⇒ Object



105
106
107
108
109
110
# File 'lib/rails_component.rb', line 105

def commit_changes(message)
  Dir.chdir(@rails_root) do 
    exec("git init .", method(:magenta)) unless File.directory?(@rails_root + '.git')
    exec("git add . && git commit -m \"#{message.gsub(/"/, "\\\"")}\"", method(:magenta))
  end
end

#fire_recept!(source) ⇒ Object



61
62
63
64
# File 'lib/rails_component.rb', line 61

def fire_recept!(source)
  eval source
  print "Done!"
end

#mkdirs(*list) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/rails_component.rb', line 78

def mkdirs(*list)
  list.each do |dir|
    unless File.directory?(@rails_root + dir)
      pretty_make_dir(dir)
    end
  end
end


86
87
88
89
90
# File 'lib/rails_component.rb', line 86

def print(text)
  puts
  puts text
  puts
end

#run(cmd) ⇒ Object



98
99
100
101
102
103
# File 'lib/rails_component.rb', line 98

def run(cmd)
  Dir.chdir(@rails_root) do
    puts blue(cmd)
    `#{cmd}`
  end
end

#with_file(file, &block) ⇒ Object



92
93
94
95
96
# File 'lib/rails_component.rb', line 92

def with_file(file, &block)
  FileUtils.mkdir_p(File.dirname(@rails_root + file))
  FileUtils.touch(@rails_root + file) unless File.exist?(@rails_root + file)
  File.open(@rails_root + file, 'a+:utf-8') {|f| block.call(f) }
end