Class: GoonModelGen::Builder::StoreBuilder

Inherits:
AbstractBuilder show all
Defined in:
lib/goon_model_gen/builder/store_builder.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractBuilder

#base_package_path, #config, #package_suffix

Instance Method Summary collapse

Methods inherited from AbstractBuilder

#build, #build_sentences, #build_sentences_with, #method_to_template_for, #method_to_template_map, #templates_for

Constructor Details

#initialize(config, model_packages) ⇒ StoreBuilder

Returns a new instance of StoreBuilder.

Parameters:



19
20
21
22
23
# File 'lib/goon_model_gen/builder/store_builder.rb', line 19

def initialize(config, model_packages)
  super(config, config.store_package_path)
  @package_suffix = "_store"
  @model_packages = model_packages
end

Instance Attribute Details

#model_packagesObject (readonly)

Returns the value of attribute model_packages.



15
16
17
# File 'lib/goon_model_gen/builder/store_builder.rb', line 15

def model_packages
  @model_packages
end

Instance Method Details

#build_package(package_path, types) ⇒ Golang::Package, Array<Proc>

Parameters:

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/goon_model_gen/builder/store_builder.rb', line 28

def build_package(package_path, types)
  procs = []
  pkg = Golang::Package.new(package_path).tap do |pkg|
    types.select{|t| t.is_a?(Source::Struct) && t.id_name && t.id_type }.each do |t|
      store_type = pkg.new_struct(t.name + "Store")
      procs << Proc.new{ build_sentences('store', 'goon', t, store_type) }
      store_type.memo[:model] =
        begin
          pkg_name = Golang::Package.regularize_name(t.file.basename)
          pkg = model_packages.detect_by(pkg_name)
          raise "Package not found for #{t.file.basename}" unless pkg
          pkg.lookup(t.name)
        end
    end
  end
  return pkg, procs
end

#resolve_type_names(pkgs) ⇒ Object

Parameters:



47
48
49
# File 'lib/goon_model_gen/builder/store_builder.rb', line 47

def resolve_type_names(pkgs)
  pkgs.resolve_type_names(Golang::DatastorePackageFactory.new(config.package_alias_map).packages.dup.add(model_packages))
end