less_interactions 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.rdoc +3 -1
 - data/less_interactions.gemspec +1 -1
 - data/lib/less_interactions/interaction.rb +42 -6
 - data/test/interaction_test.rb +18 -0
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 80d11c1484566f3f643bb2825130f84eceff5ecf
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 330847040474b05548a2e6c52a42365d5d30bc2d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2c61d1c2d65b49fa9a7cd3b0383f7adec2ba90bedb68f69126fb9b261ab426f613052e6cca9a18c76b92dbb5ec59d26d411f38b0762ff711f953ff2d223b4b58
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 01ddf8061f5eeed178d44e30e174f9cd1654a50179d32a70fb610d21e82d16ae838ba2010afbcb7c2003352dd524b72fd6ffb731299e3a4c8cea649e9157887b
         
     | 
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -19,7 +19,7 @@ Rails is great, but if you build a rails app of any size you start running into 
     | 
|
| 
       19 
19 
     | 
    
         
             
            * What are all the side effects of calling this method?
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            ==  
     | 
| 
      
 22 
     | 
    
         
            +
            == What do I do?!
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
            Less::Interactions are a place to put all of your business logic and still get all the rails goodness you love.
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
         @@ -79,6 +79,8 @@ After: 
     | 
|
| 
       79 
79 
     | 
    
         
             
                expects :some_other_thing_the_interaction_needs, allow_nil: true
         
     | 
| 
       80 
80 
     | 
    
         
             
                expects :business
         
     | 
| 
       81 
81 
     | 
    
         
             
                expects :user
         
     | 
| 
      
 82 
     | 
    
         
            +
                #only one of these is required
         
     | 
| 
      
 83 
     | 
    
         
            +
                expects_any :need_this, :or, :this
         
     | 
| 
       82 
84 
     | 
    
         | 
| 
       83 
85 
     | 
    
         
             
                # method chain in use case is easy to see.
         
     | 
| 
       84 
86 
     | 
    
         
             
                def run
         
     | 
    
        data/less_interactions.gemspec
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{less_interactions}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.0. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.0.14"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Eugen Minciu", "Steven Bristol"]
         
     | 
| 
         @@ -18,6 +18,8 @@ module Less 
     | 
|
| 
       18 
18 
     | 
    
         
             
                  n.each do |name, val|
         
     | 
| 
       19 
19 
     | 
    
         
             
                    nils[name] = nil
         
     | 
| 
       20 
20 
     | 
    
         
             
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  self.class.any_expectations.flatten.each {|e| nils[e] = nil}
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       21 
23 
     | 
    
         
             
                  nils.merge(options).each do |name, value|
         
     | 
| 
       22 
24 
     | 
    
         
             
                    instance_variable_set "@#{name}", value
         
     | 
| 
       23 
25 
     | 
    
         
             
                    if respond_to?( "#{name}=" ) && !value.nil?
         
     | 
| 
         @@ -32,7 +34,7 @@ module Less 
     | 
|
| 
       32 
34 
     | 
    
         
             
                #
         
     | 
| 
       33 
35 
     | 
    
         
             
                # The default implementation raises an {InvalidInteractionError}
         
     | 
| 
       34 
36 
     | 
    
         
             
                def run
         
     | 
| 
       35 
     | 
    
         
            -
                  raise InvalidInteractionError, "You  
     | 
| 
      
 37 
     | 
    
         
            +
                  raise InvalidInteractionError, "You must override the run instance method in #{self.class}"
         
     | 
| 
       36 
38 
     | 
    
         
             
                end
         
     | 
| 
       37 
39 
     | 
    
         | 
| 
       38 
40 
     | 
    
         
             
                def init
         
     | 
| 
         @@ -46,7 +48,7 @@ module Less 
     | 
|
| 
       46 
48 
     | 
    
         
             
                def self.run(context = {}, options = {})
         
     | 
| 
       47 
49 
     | 
    
         
             
                  me = new(context, options)
         
     | 
| 
       48 
50 
     | 
    
         
             
                  me.init
         
     | 
| 
       49 
     | 
    
         
            -
                   
     | 
| 
      
 51 
     | 
    
         
            +
                  me.send :expectations_met?
         
     | 
| 
       50 
52 
     | 
    
         
             
                  me.run
         
     | 
| 
       51 
53 
     | 
    
         
             
                end
         
     | 
| 
       52 
54 
     | 
    
         | 
| 
         @@ -64,27 +66,61 @@ module Less 
     | 
|
| 
       64 
66 
     | 
    
         
             
                  else
         
     | 
| 
       65 
67 
     | 
    
         
             
                    options = {}
         
     | 
| 
       66 
68 
     | 
    
         
             
                  end
         
     | 
| 
       67 
     | 
    
         
            -
                  parameters 
     | 
| 
       68 
     | 
    
         
            -
                     
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 69 
     | 
    
         
            +
                  __setup_expecations parameters do |parameter|
         
     | 
| 
      
 70 
     | 
    
         
            +
                    add_expectation(parameter, options)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                def self.expects_any *parameters
         
     | 
| 
      
 75 
     | 
    
         
            +
                  __setup_expecations parameters do |parameter|
         
     | 
| 
       71 
76 
     | 
    
         
             
                  end
         
     | 
| 
      
 77 
     | 
    
         
            +
                  add_any_expectation(parameters)
         
     | 
| 
       72 
78 
     | 
    
         
             
                end
         
     | 
| 
       73 
79 
     | 
    
         | 
| 
       74 
80 
     | 
    
         | 
| 
       75 
81 
     | 
    
         | 
| 
       76 
82 
     | 
    
         
             
                private
         
     | 
| 
       77 
83 
     | 
    
         | 
| 
      
 84 
     | 
    
         
            +
                def self.__setup_expecations parameters
         
     | 
| 
      
 85 
     | 
    
         
            +
                  parameters.each do |param|
         
     | 
| 
      
 86 
     | 
    
         
            +
                    methods = (self.instance_methods + self.private_instance_methods)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    self.send(:attr_reader, param.to_sym) unless methods.member?(param.to_sym)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    yield param if block_given?
         
     | 
| 
      
 89 
     | 
    
         
            +
                  end
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
       78 
92 
     | 
    
         
             
                def self.add_expectation(parameter, options)
         
     | 
| 
       79 
93 
     | 
    
         
             
                  expectations[parameter] = options
         
     | 
| 
       80 
94 
     | 
    
         
             
                end
         
     | 
| 
       81 
95 
     | 
    
         | 
| 
      
 96 
     | 
    
         
            +
                def self.add_any_expectation(parameters)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  any_expectations << parameters
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       82 
100 
     | 
    
         
             
                def expectations_met?
         
     | 
| 
      
 101 
     | 
    
         
            +
                  __expects_mets? && __expects_any_mets?
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                def __expects_any_mets?
         
     | 
| 
      
 105 
     | 
    
         
            +
                  self.class.any_expectations.each do |any_set|
         
     | 
| 
      
 106 
     | 
    
         
            +
                    if any_set.all? {|e| instance_variable_get("@#{e}").nil?}
         
     | 
| 
      
 107 
     | 
    
         
            +
                      raise MissingParameterError, "Parameters empty   :#{any_set.to_s} (At least one of these must not be nil)"
         
     | 
| 
      
 108 
     | 
    
         
            +
                    end
         
     | 
| 
      
 109 
     | 
    
         
            +
                  end
         
     | 
| 
      
 110 
     | 
    
         
            +
                  true
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                def __expects_mets?
         
     | 
| 
       83 
114 
     | 
    
         
             
                  self.class.expectations.each do |param, param_options|
         
     | 
| 
       84 
115 
     | 
    
         
             
                    unless param_options[:allow_nil]
         
     | 
| 
       85 
116 
     | 
    
         
             
                      raise MissingParameterError, "Parameter empty   :#{param.to_s}" if instance_variable_get("@#{param}").nil?
         
     | 
| 
       86 
117 
     | 
    
         
             
                    end
         
     | 
| 
       87 
118 
     | 
    
         
             
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
                  true
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                def self.any_expectations
         
     | 
| 
      
 123 
     | 
    
         
            +
                  @any_expectations ||= []
         
     | 
| 
       88 
124 
     | 
    
         
             
                end
         
     | 
| 
       89 
125 
     | 
    
         | 
| 
       90 
126 
     | 
    
         
             
                def self.expectations
         
     | 
    
        data/test/interaction_test.rb
    CHANGED
    
    | 
         @@ -182,4 +182,22 @@ class InteractionTest < Test::Unit::TestCase 
     | 
|
| 
       182 
182 
     | 
    
         
             
                 x = OverrideIt.new(int: 1).run
         
     | 
| 
       183 
183 
     | 
    
         
             
                 assert_equal "1", x.send(:int)
         
     | 
| 
       184 
184 
     | 
    
         
             
               end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
               should "fail if all expects_any parameters are nil" do
         
     | 
| 
      
 188 
     | 
    
         
            +
                 class AnyInteractionWithAllNilParameters < Less::Interaction
         
     | 
| 
      
 189 
     | 
    
         
            +
                   expects_any :title, :a, :b
         
     | 
| 
      
 190 
     | 
    
         
            +
                   def run; end
         
     | 
| 
      
 191 
     | 
    
         
            +
                 end
         
     | 
| 
      
 192 
     | 
    
         
            +
                 assert_raise(MissingParameterError) { AnyInteractionWithAllNilParameters.run() }
         
     | 
| 
      
 193 
     | 
    
         
            +
               end
         
     | 
| 
      
 194 
     | 
    
         
            +
             
     | 
| 
      
 195 
     | 
    
         
            +
               should "pass if any expects_any parameters is not nil" do
         
     | 
| 
      
 196 
     | 
    
         
            +
                 class AnyInteractionWithOneNonNilParameter < Less::Interaction
         
     | 
| 
      
 197 
     | 
    
         
            +
                   expects_any :title, :a, :b
         
     | 
| 
      
 198 
     | 
    
         
            +
                   def run; true; end
         
     | 
| 
      
 199 
     | 
    
         
            +
                 end
         
     | 
| 
      
 200 
     | 
    
         
            +
                 assert AnyInteractionWithOneNonNilParameter.run(:b => 1)
         
     | 
| 
      
 201 
     | 
    
         
            +
               end
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
       185 
203 
     | 
    
         
             
            end
         
     |