Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Decorator TS parameters. New js rug instance per invocation #229 #242

Merged
merged 1 commit into from
Jan 31, 2017

Conversation

kipz
Copy link
Contributor

@kipz kipz commented Jan 30, 2017

  • add support for decorated parameters
  • decorate actually just populates the 'parameters' property
    • totally backwards compatible and interchangeable
import {Project} from '@atomist/rug/model/Core'
import {ProjectEditor} from '@atomist/rug/operations/ProjectEditor'
import {File} from '@atomist/rug/model/Core'
import {parameter} from '@atomist/rug/operations/RugOperation'

class SimpleEditor implements ProjectEditor {
    name: string = "Simple"
    description: string = "A nice little editor"

    @parameter({pattern: "^.*$$", description: "foo bar"})
    content: string = "Test String";

    @parameter({pattern: "^\\d+$$", description: "A nice round number"})
    amount: number = 10;

    @parameter({pattern: "^\\d+$$", description: "A nice round number"})
    nope: boolean;

    edit(project: Project) {
       if(this.amount != 10) {
          throw new Error("Number should be 10!");
       }
       if(this.content != "woot") {
          throw new Error("Name should be woot");
       }
    }
  }
export let editor = new SimpleEditor()

@johnsonr
Copy link
Contributor

I love the model. Would like to see some timing tests before merging.

case x => x
}

clone.asInstanceOf[ScriptObjectMirror].callMember(member,processedArgs: _* )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nicer to match

val decoratedParamNames: Set[String] = clone.get("parameters") match {
case ps: ScriptObjectMirror if !ps.isEmpty => {
ps.asScala.collect {
case (_, details: ScriptObjectMirror) if details.get("decorated").asInstanceOf[Boolean] => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nicer without casting.

@@ -0,0 +1,82 @@
package com.atomist.rug.runtime.js
Copy link
Contributor

@johnsonr johnsonr Jan 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do it in this PR, but I added ability to load a TypeScript side file from the class path. Makes it easier to edit the TS. For example,

val jsed = TestUtils.editorInSideFile(this, "SimpleBanana.ts")

Where the TypeScript file is under test resources in the same package.

@kipz kipz force-pushed the params branch 2 times, most recently from 5c8e378 to fc9420b Compare January 31, 2017 01:19
@johnsonr
Copy link
Contributor

LGTM
Merge on green

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants