Class: Jeny::Command::Generate

Inherits:
Object
  • Object
show all
Includes:
Support
Defined in:
lib/jeny/command/generate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support

#edit_changed_files, simplify_path

Constructor Details

#initialize(config, data, from, to) ⇒ Generate

Returns a new instance of Generate.



6
7
8
9
10
11
# File 'lib/jeny/command/generate.rb', line 6

def initialize(config, data, from, to)
  @config = config
  @data = Caser.for_hash(data)
  @from = from
  @to = to
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/jeny/command/generate.rb', line 12

def config
  @config
end

#dataObject (readonly)

Returns the value of attribute data.



12
13
14
# File 'lib/jeny/command/generate.rb', line 12

def data
  @data
end

#fromObject (readonly)

Returns the value of attribute from.



12
13
14
# File 'lib/jeny/command/generate.rb', line 12

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



12
13
14
# File 'lib/jeny/command/generate.rb', line 12

def to
  @to
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jeny/command/generate.rb', line 14

def call
  puts
  changed = []
  from.glob("**/*") do |source|
    target = target_for(source)
    puts "creating #{simplify_path(target)}"
    if source.directory?
      target.mkdir_p
    else
      target.parent.mkdir_p
      file = File::Full.new(source, config)
      target_content = file.instantiate(data)
      target.write(target_content)
      changed << [target, target_content]
    end
  end
  edit_changed_files(changed)
end