github.com/bhameyie/otto@v0.2.1-0.20160406174117-16052efa52ec/builtin/app/ruby/customization.go (about)

     1  package rubyapp
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/hashicorp/otto/helper/compile"
     8  	"github.com/hashicorp/otto/helper/schema"
     9  )
    10  
    11  const defaultLatestVersion = "2.2"
    12  
    13  type customizations struct {
    14  	Opts *compile.AppOptions
    15  }
    16  
    17  func (c *customizations) process(d *schema.FieldData) error {
    18  	vsn := d.Get("ruby_version")
    19  
    20  	// If we were asked to detect the version, we attempt to do so.
    21  	// If we can't detect it for non-erroneous reasons, we use our default.
    22  	if vsn == "detect" {
    23  		var err error
    24  		c.Opts.Ctx.Ui.Header("Detecting Ruby version to use...")
    25  		vsn, err = detectRubyVersionGemfile(filepath.Dir(c.Opts.Ctx.Appfile.Path))
    26  		if err != nil {
    27  			return err
    28  		}
    29  		if vsn != "" {
    30  			c.Opts.Ctx.Ui.Message(fmt.Sprintf(
    31  				"Detected desired Ruby version: %s", vsn))
    32  		}
    33  		if vsn == "" {
    34  			vsn = defaultLatestVersion
    35  			c.Opts.Ctx.Ui.Message(fmt.Sprintf(
    36  				"No desired Ruby version found! Will use the default: %s", vsn))
    37  		}
    38  	}
    39  
    40  	c.Opts.Bindata.Context["ruby_version"] = vsn
    41  	return nil
    42  }