class MiniSheet

Public Class Methods

new(sheet, config) click to toggle source
# File lib/sawa/MiniSheet.rb, line 7
def initialize(sheet, config)
  @sheet = sheet
  @config = config
  @idx_path = 2
  @idx_title = 3
  @idx_method = 1
  @idx_process = 2
  @idx_role = 3
  @idx_type = 1
  @idx_name = 2
  @idx_unique = 3
  @idx_nullable = 4
  @idx_jsonignore = 5
  @idx_mtitle = 6
  @idx_mappedBy = 7
  @idx_refColumn = 8
  @idx_isList = 5
  @idx_param = 6
end

Public Instance Methods

api_imports() click to toggle source
# File lib/sawa/MiniSheet.rb, line 150
def api_imports
  arr = []
  @sheet.each do |row|
    if row[0] != "p"
      next
    end
    if row[@idx_isList] == "1" and !arr.include?("import java.util.List;")
      arr.push "import java.util.List;"
    end
    if row[@idx_param].include?("@role") and !arr.include?("import io.dropwizard.auth.Auth;")
      arr.push "import io.dropwizard.auth.Auth;"
    end
  end
  arr
end
api_name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 83
def api_name
  getName("if", @sheet.name)
end
dao_name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 71
def dao_name
  getName("dao", @sheet.name)
end
model_imports() click to toggle source
# File lib/sawa/MiniSheet.rb, line 97
def model_imports
  arr = []
  @sheet.each do |row|
    if row[0] != "m"
      next
    end

    if row[@idx_jsonignore] == "1" and !arr.include?("import com.fasterxml.jackson.annotation.JsonIgnore;")
      arr.push "import com.fasterxml.jackson.annotation.JsonIgnore;"
    end
    if row[@idx_mappedBy] == "1:n" and !arr.include?("import javax.persistence.OneToMany;")
      arr.push "import javax.persistence.OneToMany;"
    end
    if row[@idx_mappedBy] == "1:n" and !arr.include?("import com.fasterxml.jackson.annotation.JsonManagedReference;")
      arr.push "import com.fasterxml.jackson.annotation.JsonManagedReference;"
    end
    if row[@idx_mappedBy] == "1:n" and !arr.include?("import org.hibernate.annotations.Where;")
      arr.push "import org.hibernate.annotations.Where;"
    end

    if row[@idx_mappedBy] == "n:1" and !arr.include?("import javax.persistence.ManyToOne;")
      arr.push "import javax.persistence.ManyToOne;"
    end
    if row[@idx_mappedBy] == "n:1" and !arr.include?("import com.fasterxml.jackson.annotation.JsonBackReference;")
      arr.push "import com.fasterxml.jackson.annotation.JsonBackReference;"
    end
    if row[@idx_mappedBy] == "n:1" and !arr.include?("import javax.persistence.JoinColumn;")
      arr.push "import javax.persistence.JoinColumn;"
    end

    if row[@idx_mappedBy] == "1:1" and !arr.include?("import javax.persistence.OneToOne;")
      arr.push "import javax.persistence.OneToOne;"
    end
    if row[@idx_mappedBy] == "1:1" and !arr.include?("import javax.persistence.JoinColumn;")
      arr.push "import javax.persistence.JoinColumn;"
    end
  end
  arr
end
model_name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 59
def model_name
  getName("model", @sheet.name)
end
model_property_metas() click to toggle source
# File lib/sawa/MiniSheet.rb, line 87
def model_property_metas
  arr = []
  @sheet.each do |row|
    if row[0] == "m" and row[@idx_jsonignore] == "1"
      arr.push "#{@sheet.row(0)[@idx_path]}.#{row[@idx_name]}=#{row[@idx_type]},#{row[@idx_nullable]},#{row[@idx_mtitle]}"
    end
  end
  arr
end
model_title() click to toggle source
# File lib/sawa/MiniSheet.rb, line 67
def model_title
  @sheet.row(0)[@idx_title]
end
name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 27
def name
  @sheet.name
end
package_api() click to toggle source
# File lib/sawa/MiniSheet.rb, line 39
def package_api
  @config['packageApi']
end
package_dao() click to toggle source
# File lib/sawa/MiniSheet.rb, line 43
def package_dao
  @config['packageDao']
end
package_model() click to toggle source
# File lib/sawa/MiniSheet.rb, line 47
def package_model
  @config['packageModel']
end
package_resource() click to toggle source
# File lib/sawa/MiniSheet.rb, line 51
def package_resource
  @config['packageResource']
end
page_name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 79
def page_name
  getName("page", @sheet.name)
end
resource_imports() click to toggle source
# File lib/sawa/MiniSheet.rb, line 137
def resource_imports
  arr = []
  @sheet.each do |row|
    if row[0] != "p"
      next
    end
    if row[@idx_jsonignore] == "1" and !arr.include?("import java.util.List;")
      arr.push "import java.util.List;"
    end
  end
  arr
end
resource_name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 75
def resource_name
  getName("resource", @sheet.name)
end
resource_path() click to toggle source
# File lib/sawa/MiniSheet.rb, line 63
def resource_path
  @sheet.row(0)[@idx_path]
end
rows_model() click to toggle source
# File lib/sawa/MiniSheet.rb, line 31
def rows_model
  get_model_rows(@sheet)
end
rows_path() click to toggle source
# File lib/sawa/MiniSheet.rb, line 35
def rows_path
  get_path_rows(@sheet)
end
table_name() click to toggle source
# File lib/sawa/MiniSheet.rb, line 55
def table_name
  @sheet.name
end

Private Instance Methods

getName(type, sheetName) click to toggle source
# File lib/sawa/MiniSheet.rb, line 168
def getName(type, sheetName)
  perfix = sheetName.split("_")
  perfix[0].capitalize + perfix[1].capitalize + type.capitalize
end
get_model_rows(sheet) click to toggle source
# File lib/sawa/MiniSheet.rb, line 175
def get_model_rows(sheet)
  rows_model = []
  sheet.each do |row|
    if row[0] == "m"
      rows_model.push(MiniProperty.new(row, self))
    end
  end
  rows_model
end
get_path_rows(sheet) click to toggle source
# File lib/sawa/MiniSheet.rb, line 187
def get_path_rows(sheet)
  rows_path = []
  sheet.each do |row|
    if row[0] == "p"
      rows_path.push(MiniResource.new(row, self))
    end
  end
  rows_path
end