Module: Takenoko

Extended by:
Takenoko
Included in:
Takenoko
Defined in:
lib/takenoko.rb,
lib/takenoko/version.rb,
lib/takenoko/exporter.rb,
lib/takenoko/attach_helper.rb,
lib/takenoko/google_client.rb,
lib/takenoko/mapping_generator.rb,
lib/generators/takenoko/config_generator.rb

Defined Under Namespace

Modules: AttachHelper, Exporter, Generators, MappingGenerator Classes: GoogleClient, Railtie

Constant Summary collapse

SUPPORTED_FILE_EXT =
[:csv,:yaml,:json, :yml]
VERSION =
"0.3.0"
@@google_cridential_file =
nil
@@personal_cridential_file =
"config/my_cridential.json"
@@mapping_file =
false
@@always_reload =
true
@@google_client =
nil
@@mapping_config =
nil
@@file_extension =
:csv
@@export_file_location =
"db/spreadsheet"
@@truncate_all_data =
false
@@allow_overwrite =
true
@@sheet_id =
nil
@@enable_postprocess =
false
@@postprocess_class =
nil
@@download_location =
"tmp/attach_files"
@@log_folder =
"tmp/takenoko"
@@folder_id =
nil

Instance Method Summary collapse

Instance Method Details

#config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Takenoko)

    the object that the method was called on



60
61
62
# File 'lib/takenoko.rb', line 60

def config
  yield self
end

#download_all_filesObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/takenoko.rb', line 94

def download_all_files
  errors = []
  mapping_config[:tables].each do |table,conf|
    next if conf[:attach_files].blank?
    begin
      download_table_files table
    rescue Exception => e
      errors << e.to_s
    end
  end
  raise errors.join("\n") unless errors.empty?
  
  return true
end

#download_attached_files(table_name) ⇒ Object



82
83
84
85
86
# File 'lib/takenoko.rb', line 82

def download_attached_files(table_name)
  table_data = google_client.get_table(table_name)
  return false unless table_data[:attach_files].present?
  return AttachHelper.download table_data
end

#download_table_files(table_name) ⇒ Object



88
89
90
91
92
# File 'lib/takenoko.rb', line 88

def download_table_files(table_name)
  table_data = google_client.get_table(table_name)
  raise "attach_files not set" unless table_data[:attach_files].present?
  AttachHelper.download table_data
end

#google_clientObject



68
69
70
71
# File 'lib/takenoko.rb', line 68

def google_client
  @@google_client ||= GoogleClient.new(google_cridential_file)
  return @@google_client
end

#log_folderObject



64
65
66
67
# File 'lib/takenoko.rb', line 64

def log_folder
  FileUtils.mkdir_p(@@log_folder) unless File.directory?(@@log_folder)
  @@log_folder
end

#mapping_configObject



73
74
75
# File 'lib/takenoko.rb', line 73

def mapping_config
  MappingGenerator.generate
end

#table_config(table_name) ⇒ Object



77
78
79
80
# File 'lib/takenoko.rb', line 77

def table_config(table_name)
  raise "#{table_name} config not exists" unless conf = mapping_config[:tables][table_name]
  return conf
end