forked from RiverGlide/CukeSalad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compartmentalisation of cukesalad objects into a cukesalad module
- Loading branch information
Showing
9 changed files
with
264 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,49 @@ | ||
require 'cukesalad/director' | ||
|
||
class Actor | ||
|
||
def initialize this_type_of_role, directed_by=Director.new | ||
@director = directed_by | ||
get_into_character_for this_type_of_role | ||
@note_pad = {} | ||
end | ||
|
||
def perform described_task, details = {} | ||
get_ready_to_perform described_task | ||
@info = details | ||
perform_task | ||
end | ||
alias :answer :perform | ||
module CukeSalad | ||
class Actor | ||
|
||
def initialize this_type_of_role, directed_by=Director.new | ||
@director = directed_by | ||
get_into_character_for this_type_of_role | ||
@note_pad = {} | ||
end | ||
|
||
def perform described_task, details = {} | ||
get_ready_to_perform described_task | ||
@info = details | ||
perform_task | ||
end | ||
alias :answer :perform | ||
|
||
def get_into_character_for described_role | ||
the_role = @director.explain_the_role described_role | ||
see_how_to_do the_role | ||
end | ||
|
||
def get_ready_to_perform something | ||
the_thing = @director.how_do_i_perform something | ||
see_how_to_do the_thing | ||
end | ||
def get_into_character_for described_role | ||
the_role = @director.explain_the_role described_role | ||
see_how_to_do the_role | ||
end | ||
def get_ready_to_perform something | ||
the_thing = @director.how_do_i_perform something | ||
see_how_to_do the_thing | ||
end | ||
|
||
def see_how_to_do something | ||
extend something | ||
end | ||
def see_how_to_do something | ||
extend something | ||
end | ||
|
||
def value_of(symbol) | ||
@info[symbol] | ||
end | ||
def value_of(symbol) | ||
@info[symbol] | ||
end | ||
|
||
def take_note_of key, value | ||
@note_pad.store key, value | ||
end | ||
def take_note_of key, value | ||
@note_pad.store key, value | ||
end | ||
|
||
def recall key | ||
begin | ||
@note_pad.fetch key | ||
rescue KeyError | ||
raise KeyError, "You tried to recall ':#{key}' but no previous step appears to have taken note of that information." | ||
def recall key | ||
begin | ||
@note_pad.fetch key | ||
rescue KeyError | ||
raise KeyError, "You tried to recall ':#{key}' but no previous step appears to have taken note of that information." | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
module Codify | ||
module ConstName | ||
def ConstName.from sentence | ||
joined_together capitalised( words_from sentence ) | ||
end | ||
|
||
private | ||
def ConstName.joined_together words | ||
words.join | ||
end | ||
|
||
def ConstName.words_from this_sentence | ||
on_word_boundary = /\s|([A-Z][a-z]+)/ | ||
this_sentence.split( on_word_boundary ) | ||
end | ||
module CukeSalad | ||
module Codify | ||
module ConstName | ||
def ConstName.from sentence | ||
joined_together capitalised( words_from sentence ) | ||
end | ||
|
||
private | ||
def ConstName.joined_together words | ||
words.join | ||
end | ||
|
||
def ConstName.words_from this_sentence | ||
on_word_boundary = /\s|([A-Z][a-z]+)/ | ||
this_sentence.split( on_word_boundary ) | ||
end | ||
|
||
def ConstName.capitalised words | ||
words.collect{ | word | word.capitalize } | ||
def ConstName.capitalised words | ||
words.collect{ | word | word.capitalize } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
require 'cukesalad/codify/const_name' | ||
class Director | ||
module CukeSalad | ||
class Director | ||
|
||
include Codify | ||
|
||
#TODO: Needs refactoring | ||
def explain_the_role description | ||
name = ConstName.from description | ||
begin | ||
find_directives_for name | ||
rescue NameError | ||
raise "I can't find a role called '#{ name }'. Have you created it?\ne.g.\n module #{ name }\n end" | ||
include Codify | ||
|
||
#TODO: Needs refactoring | ||
def explain_the_role description | ||
name = ConstName.from description | ||
begin | ||
find_directives_for name | ||
rescue NameError | ||
raise "I can't find a role called '#{ name }'. Have you created it?\ne.g.\n module #{ name }\n end" | ||
end | ||
end | ||
end | ||
|
||
def how_do_i_perform something | ||
name = ConstName.from something | ||
begin | ||
find_directives_for name | ||
rescue NameError | ||
raise "I can't find a task called '#{ something }'. Have you created it?\ne.g.\n in_order_to '#{ something }' do\n # the actions\n end" | ||
def how_do_i_perform something | ||
name = ConstName.from something | ||
begin | ||
find_directives_for name | ||
rescue NameError | ||
raise "I can't find a task called '#{ something }'. Have you created it?\ne.g.\n in_order_to '#{ something }' do\n # the actions\n end" | ||
end | ||
end | ||
end | ||
|
||
def find_directives_for something | ||
Kernel.const_get( something ) | ||
def find_directives_for something | ||
Kernel.const_get( something ) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
module Specifics | ||
def understand_the details | ||
@info = with_specifics_from( details ) | ||
end | ||
|
||
def value_of(symbol) | ||
@info[symbol] | ||
end | ||
module CukeSalad | ||
module Specifics | ||
def understand_the details | ||
@info = with_specifics_from( details ) | ||
end | ||
|
||
def value_of(symbol) | ||
@info[symbol] | ||
end | ||
|
||
def with_specifics_from details | ||
result = {} | ||
names_and_values_in(details).each_slice(2) do |name_value| | ||
result[symbolized name_value[0]] = the_value_from_the name_value[1] | ||
def with_specifics_from details | ||
result = {} | ||
names_and_values_in(details).each_slice(2) do |name_value| | ||
result[symbolized name_value[0]] = the_value_from_the name_value[1] | ||
end | ||
result | ||
end | ||
result | ||
end | ||
|
||
def set_last value | ||
@info[@info.keys.last] = value | ||
end | ||
def set_last value | ||
@info[@info.keys.last] = value | ||
end | ||
|
||
def names_and_values_in details | ||
specifics_pattern = /('[^']+')/ | ||
details.split(specifics_pattern) | ||
end | ||
def names_and_values_in details | ||
specifics_pattern = /('[^']+')/ | ||
details.split(specifics_pattern) | ||
end | ||
|
||
def symbolized name | ||
name.strip.gsub(' ', '_').to_sym | ||
end | ||
def symbolized name | ||
name.strip.gsub(' ', '_').to_sym | ||
end | ||
|
||
def the_value_from_the item | ||
item.gsub(/(^'|'$)/, '') unless item.nil? | ||
def the_value_from_the item | ||
item.gsub(/(^'|'$)/, '') unless item.nil? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Cukesalad | ||
module CukeSalad | ||
VERSION = "0.6.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.