Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add techdocs #40

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Huxley TechDocs

on:
workflow_dispatch:
push:
branches: master
paths:
- "docs/**"
- "mkdocs.yml"
- ".github/workflows/publish-docs.yaml"
pull_request:
branches: master
paths:
- "docs/**"
- "mkdocs.yaml"
- ".github/workflows/publish-docs.yaml"
schedule:
- cron: "15 3 1 * *"

concurrency: huxley-techdocs-${{ github.ref }}

jobs:
publish-techdocs:
uses: simplybusiness/github-action-reusable-workflows/.github/workflows/techdocs.yaml@v1
with:
repo: "github-action-reusable-workflows"
secrets:
region: ${{ secrets.AWS_LIVE_CICD_REGION }}
aws-access-key-id: ${{ secrets.AWS_LIVE_CICD_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_LIVE_CICD_SECRET_ACCESS_KEY }}
116 changes: 1 addition & 115 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,115 +1 @@
[![Build Status](https://semaphoreci.com/api/v1/projects/e488365d-9c57-4431-916a-72aea091d1b5/229083/shields_badge.svg)](https://semaphoreci.com/simplybusiness/rulezilla)
[![Code Climate](https://codeclimate.com/repos/53ecc0416956800c1d01f6bf/badges/76b47eaeffc33e312508/gpa.svg)](https://codeclimate.com/repos/53ecc0416956800c1d01f6bf/feed)
[![Gem Version](https://badge.fury.io/rb/rulezilla.svg)](http://badge.fury.io/rb/rulezilla)

rulezilla
=========

This provides a DSL to implement rules for various tasks. In the current version we are still relying on user to have a certain level of Ruby knowledge
in order to be able to use this DSL. The ultimate goal is for people without prior Ruby knowledge to be able to change and even write the Rule.


# Installation

## Using `Gemfile`

Add the following line to your `Gemfile`:

gem 'rulezilla'

Then run:

bundle install

## Without `Gemfile`

On your command line run the following:

gem install 'rulezilla'

## Usage

### Rules

Rules are defined in Ruby. Rules are classes that include the `Rulezilla::DSL`.

#### Ruby

You can use plain Ruby to define the rule classes. But you will need to include the `Rulezilla::DSL` module. That will give you access to the DSL used to define rules.

Here is an example:

class RoboticsRule
include Rulezilla::DSL

group :may_not_injure_human do
condition { not_injure_human? }

group :obey_human do
condition { do_as_human_told? }

define :protect_its_own_existence do
condition { protect_itself? }
result(true)
end
end
end

default(false)

end

Please refer to the [feature](spec/features/rulezilla_dsl_framework.feature) for further details of the DSL.

### Support Module

The support module will be automatically included if its name is `"#{rule_class_name}Support"`

e.g. if the rule class name is `RoboticsRule`, then the support would be `RoboticsRuleSupport`

module RoboticsRuleSupport
def protect_itself?
in_danger? && not_letting_itself_be_detroyed?
end
end

### How to execute the rule

If the entity is:

entity = {
not_injure_human?: true,
do_as_human_told?: true,
in_danger?: true,
not_letting_itself_be_detroyed?: true
}

#### To get the first matching result output

RoboticsRule.apply(entity) #=> true

#### To get all matching result outputs

RoboticsRule.all(entity) #=> [true, false]

Note that `false` is the result outcome coming out from `default(false)` on top level, which is also called `root node`. The `root` node does not have any condition and hence
it is considered to be matching. This means, by consequence, that its result (`default(false)`) is included in the list of matching result outputs which `#all(entity)` above
returns.

#### To get the trace of all nodes

RoboticsRule.trace(entity)
#=> all the nodes instance: [root, may_not_injure_human, obey_human, protect_its_own_existence] in sequence order.

#### To get all results from the Rule

RoboticsRule.results #=> [true, false]


### Syntax

Please refer to the features for DSL syntax:

[DSL Feature](spec/features/rulezilla_dsl_framework.feature),

[Default Support Methods Feature](spec/features/default_support_methods.feature)
All documentation is now in the `docs/` subdirectory, or can be viewed in rendered form on Backstage. Start with the [index](docs/index.md)
9 changes: 9 additions & 0 deletions _pipeline/stage_publishdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 0.2

phases:
install:
commands:
- docker_setup
build:
commands:
- run_huxley publish_backstage_docs
4 changes: 3 additions & 1 deletion catalog-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: rulezilla
description: Rule DSL
description: Rule DSL
annotations:
backstage.io/techdocs-ref: dir:.
spec:
type: library
lifecycle: production
115 changes: 115 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[![Build Status](https://semaphoreci.com/api/v1/projects/e488365d-9c57-4431-916a-72aea091d1b5/229083/shields_badge.svg)](https://semaphoreci.com/simplybusiness/rulezilla)
[![Code Climate](https://codeclimate.com/repos/53ecc0416956800c1d01f6bf/badges/76b47eaeffc33e312508/gpa.svg)](https://codeclimate.com/repos/53ecc0416956800c1d01f6bf/feed)
[![Gem Version](https://badge.fury.io/rb/rulezilla.svg)](http://badge.fury.io/rb/rulezilla)

rulezilla
=========

This provides a DSL to implement rules for various tasks. In the current version we are still relying on user to have a certain level of Ruby knowledge
in order to be able to use this DSL. The ultimate goal is for people without prior Ruby knowledge to be able to change and even write the Rule.


# Installation

## Using `Gemfile`

Add the following line to your `Gemfile`:

gem 'rulezilla'

Then run:

bundle install

## Without `Gemfile`

On your command line run the following:

gem install 'rulezilla'

## Usage

### Rules

Rules are defined in Ruby. Rules are classes that include the `Rulezilla::DSL`.

#### Ruby

You can use plain Ruby to define the rule classes. But you will need to include the `Rulezilla::DSL` module. That will give you access to the DSL used to define rules.

Here is an example:

class RoboticsRule
include Rulezilla::DSL

group :may_not_injure_human do
condition { not_injure_human? }

group :obey_human do
condition { do_as_human_told? }

define :protect_its_own_existence do
condition { protect_itself? }
result(true)
end
end
end

default(false)

end

Please refer to the [feature](spec/features/rulezilla_dsl_framework.feature) for further details of the DSL.

### Support Module

The support module will be automatically included if its name is `"#{rule_class_name}Support"`

e.g. if the rule class name is `RoboticsRule`, then the support would be `RoboticsRuleSupport`

module RoboticsRuleSupport
def protect_itself?
in_danger? && not_letting_itself_be_detroyed?
end
end

### How to execute the rule

If the entity is:

entity = {
not_injure_human?: true,
do_as_human_told?: true,
in_danger?: true,
not_letting_itself_be_detroyed?: true
}

#### To get the first matching result output

RoboticsRule.apply(entity) #=> true

#### To get all matching result outputs

RoboticsRule.all(entity) #=> [true, false]

Note that `false` is the result outcome coming out from `default(false)` on top level, which is also called `root node`. The `root` node does not have any condition and hence
it is considered to be matching. This means, by consequence, that its result (`default(false)`) is included in the list of matching result outputs which `#all(entity)` above
returns.

#### To get the trace of all nodes

RoboticsRule.trace(entity)
#=> all the nodes instance: [root, may_not_injure_human, obey_human, protect_its_own_existence] in sequence order.

#### To get all results from the Rule

RoboticsRule.results #=> [true, false]


### Syntax

Please refer to the features for DSL syntax:

[DSL Feature](spec/features/rulezilla_dsl_framework.feature),

[Default Support Methods Feature](spec/features/default_support_methods.feature)
8 changes: 8 additions & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
site_name: Rulezilla Docs
repo_url: https://github.com/simplybusiness/rulezilla
edit_uri: blob/master/docs/
docs_dir: "docs"
nav:
- Home: index.md
plugins:
- techdocs-core