Class: Harvixture::Model

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Model

Returns a new instance of Model.



5
6
7
# File 'lib/harvixture/model.rb', line 5

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/harvixture/model.rb', line 4

def object
  @object
end

Instance Method Details

#filenameObject



17
18
19
# File 'lib/harvixture/model.rb', line 17

def filename
  File.join(RAILS_ROOT, Config.output_dir, "#{object.class.table_name}.yml")
end

#write_fixtureObject



9
10
11
12
13
14
15
# File 'lib/harvixture/model.rb', line 9

def write_fixture
  FileUtils.mkdir_p(File.dirname(filename))
  File.open(filename, 'w+') { |file| file.print '---' } unless File.exist?(filename)
  File.open(filename, 'a+') do |file|
    file.puts object.to_harvixture
  end
end