lib/kindergarten/perimeter.rb in kindergarten-0.0.5 vs lib/kindergarten/perimeter.rb in kindergarten-0.1.0

- old
+ new

@@ -3,11 +3,11 @@ # # @example # class ExamplePerimeter < Kindergarten::Perimeter # purpose :books # - # govern do |child| + # govern do # can :read, Book do |book| # book.level <= 2 # end # end # @@ -19,17 +19,33 @@ # sandbox :read # end # class Perimeter class << self - attr_reader :sandboxed_methods, :govern_proc + attr_reader :exposed_methods, :govern_proc - # Define a list of sandbox methods - def sandbox(*list) - @sandboxed_methods ||= [] - @sandboxed_methods |= list + # Defines a list of sandboxed methods + # + # Can be called multiple times to grow the list. + # + # @example + # class BondModule < Kindergarten::Perimeter + # # ... + # expose :m, :q + # + # # ... + # expose :enemies + # end + # + # BondModule.exposed_methods + # => [ :m, :q, :enemies ] + # + def expose(*list) + @exposed_methods ||= [] + @exposed_methods |= list end + alias_method :sandbox, :expose # Instruct the Governess how to govern this perimeter def govern(&proc) @govern_proc = proc end @@ -86,34 +102,18 @@ unless @governess.nil? || self.class.govern_proc.nil? @governess.instance_eval(&self.class.govern_proc) end end + delegate :scrub, :rinse, :guard, :unguarded, + :to => :governess + # @return [Array] List of sandbox methods def sandbox_methods - self.class.sandboxed_methods + self.class.exposed_methods end - # @see Governess#scrub - def scrub(*args) - self.governess.scrub(*args) - end - - # @see Governess#rinse - def rinse(*args) - self.governess.rinse(*args) - end - - # @see Governess#guard - def guard(action, target) - self.governess.guard(action, target) - end - - # @see Governess#unguarded - def unguarded(&block) - self.governess.unguarded(&block) - end - + # Perform a block under the watchful eye off the governess def governed(method, unguarded=false, &block) if unguarded == true self.governess.unguarded do self.governess.governed(method, &block) end