patriarch 0.0.4 → 0.1.0
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.
- data/.gitignore +1 -0
- data/README.md +43 -3
- data/lib/generators/patriarch/behaviour_generator.rb +117 -0
- data/lib/generators/patriarch/install_generator.rb +27 -10
- data/lib/generators/patriarch/templates/after_manager_service.rb +2 -1
- data/lib/generators/patriarch/templates/authorization_service.rb +1 -1
- data/lib/generators/patriarch/templates/before_manager_service.rb +2 -1
- data/lib/generators/patriarch/templates/before_service.rb +1 -1
- data/lib/generators/patriarch/templates/empty_behaviours_declaration.rb +2 -0
- data/lib/generators/patriarch/templates/empty_services_declaration.rb +2 -0
- data/lib/generators/patriarch/templates/manager_service-tripartite.rb +36 -0
- data/lib/generators/patriarch/templates/manager_service.rb +15 -8
- data/lib/generators/patriarch/templates/service-tripartite.rb +5 -0
- data/lib/generators/patriarch/templates/service.rb +1 -1
- data/lib/generators/patriarch/templates/tools_methods.rb +2 -1
- data/lib/generators/patriarch/templates/undo_service-tripartite.rb +5 -0
- data/lib/patriarch/behaviours.rb +170 -13
- data/lib/patriarch/dao_services/bipartite_relationship_builder_service.rb +0 -4
- data/lib/patriarch/dao_services/redis_mapper_service.rb +45 -8
- data/lib/patriarch/dao_services/retriever_service.rb +26 -4
- data/lib/patriarch/dao_services/tripartite_relationship_builder_service.rb +51 -0
- data/lib/patriarch/manager_service.rb +0 -9
- data/lib/patriarch/tool_services/redis_cleaner_service.rb +64 -0
- data/lib/patriarch/tool_services/redis_extractor_service.rb +33 -4
- data/lib/patriarch/transaction.rb +9 -4
- data/lib/patriarch/transaction_services/transaction_manager_service.rb +9 -0
- data/lib/patriarch/transaction_step.rb +10 -2
- data/lib/patriarch/version.rb +1 -1
- data/lib/patriarch.rb +11 -5
- data/patriarch.gemspec +2 -4
- data/spec/lib/patriarch/behaviours_spec.rb +233 -0
- data/spec/lib/patriarch/{bipartite_relationship_builder_spec.rb → dao_services/bipartite_relationship_builder_spec.rb} +19 -23
- data/spec/lib/patriarch/dao_services/tripartite_relationship_builder_spec.rb +49 -0
- data/spec/lib/patriarch/redis_mapper_service_spec.rb +46 -14
- data/spec/lib/patriarch/retriever_service_spec.rb +27 -8
- data/spec/lib/patriarch/tool_services/redis_cleaner_service_spec.rb +48 -0
- data/spec/lib/patriarch/transaction_spec.rb +13 -0
- data/spec/lib/patriarch/transaction_step_spec.rb +29 -0
- data/spec/spec_helper.rb +45 -11
- metadata +30 -53
- data/lib/generators/patriarch/patriarch_generator.rb +0 -114
- data/lib/patriarch/dao_services/.DAOinstancier.rb.swp +0 -0
- data/lib/patriarch/tool_services/redis_cleaner.rb +0 -47
- data/spec/lib/patriarch/add_behaviour_spec.rb +0 -59
- data/spec/lib/patriarch/like_service_spec.rb +0 -19
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: patriarch
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-11- | 
| 12 | 
            +
            date: 2012-11-30 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: verbs
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &16105280 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ! '>='
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: '0'
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *16105280
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: rails
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &16104860 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ! '>='
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: '0'
         | 
| 33 33 | 
             
              type: :runtime
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *16104860
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: railties
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &16104440 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ! '>='
         | 
| @@ -43,10 +43,10 @@ dependencies: | |
| 43 43 | 
             
                    version: '0'
         | 
| 44 44 | 
             
              type: :runtime
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *16104440
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: rspec
         | 
| 49 | 
            -
              requirement: & | 
| 49 | 
            +
              requirement: &16104020 !ruby/object:Gem::Requirement
         | 
| 50 50 | 
             
                none: false
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ! '>='
         | 
| @@ -54,40 +54,7 @@ dependencies: | |
| 54 54 | 
             
                    version: '0'
         | 
| 55 55 | 
             
              type: :development
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements: * | 
| 58 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 59 | 
            -
              name: fakeredis
         | 
| 60 | 
            -
              requirement: &14191640 !ruby/object:Gem::Requirement
         | 
| 61 | 
            -
                none: false
         | 
| 62 | 
            -
                requirements:
         | 
| 63 | 
            -
                - - ! '>='
         | 
| 64 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 65 | 
            -
                    version: '0'
         | 
| 66 | 
            -
              type: :development
         | 
| 67 | 
            -
              prerelease: false
         | 
| 68 | 
            -
              version_requirements: *14191640
         | 
| 69 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            -
              name: autotest-rails
         | 
| 71 | 
            -
              requirement: &14191220 !ruby/object:Gem::Requirement
         | 
| 72 | 
            -
                none: false
         | 
| 73 | 
            -
                requirements:
         | 
| 74 | 
            -
                - - ! '>='
         | 
| 75 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 76 | 
            -
                    version: '0'
         | 
| 77 | 
            -
              type: :development
         | 
| 78 | 
            -
              prerelease: false
         | 
| 79 | 
            -
              version_requirements: *14191220
         | 
| 80 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 81 | 
            -
              name: ZenTest
         | 
| 82 | 
            -
              requirement: &14190800 !ruby/object:Gem::Requirement
         | 
| 83 | 
            -
                none: false
         | 
| 84 | 
            -
                requirements:
         | 
| 85 | 
            -
                - - ! '>='
         | 
| 86 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 87 | 
            -
                    version: '0'
         | 
| 88 | 
            -
              type: :development
         | 
| 89 | 
            -
              prerelease: false
         | 
| 90 | 
            -
              version_requirements: *14190800
         | 
| 57 | 
            +
              version_requirements: *16104020
         | 
| 91 58 | 
             
            description: Patriach is about adding behaviours on the fly to good old active record
         | 
| 92 59 | 
             
              models.
         | 
| 93 60 | 
             
            email:
         | 
| @@ -102,8 +69,8 @@ files: | |
| 102 69 | 
             
            - README.md
         | 
| 103 70 | 
             
            - Rakefile
         | 
| 104 71 | 
             
            - lib/generators/patriarch/USAGE
         | 
| 72 | 
            +
            - lib/generators/patriarch/behaviour_generator.rb
         | 
| 105 73 | 
             
            - lib/generators/patriarch/install_generator.rb
         | 
| 106 | 
            -
            - lib/generators/patriarch/patriarch_generator.rb
         | 
| 107 74 | 
             
            - lib/generators/patriarch/templates/after_manager_service.rb
         | 
| 108 75 | 
             
            - lib/generators/patriarch/templates/after_service.rb
         | 
| 109 76 | 
             
            - lib/generators/patriarch/templates/authorization_service.rb
         | 
| @@ -113,36 +80,43 @@ files: | |
| 113 80 | 
             
            - lib/generators/patriarch/templates/empty_behaviours_declaration.rb
         | 
| 114 81 | 
             
            - lib/generators/patriarch/templates/empty_service_module.rb
         | 
| 115 82 | 
             
            - lib/generators/patriarch/templates/empty_services_declaration.rb
         | 
| 83 | 
            +
            - lib/generators/patriarch/templates/manager_service-tripartite.rb
         | 
| 116 84 | 
             
            - lib/generators/patriarch/templates/manager_service.rb
         | 
| 85 | 
            +
            - lib/generators/patriarch/templates/service-tripartite.rb
         | 
| 117 86 | 
             
            - lib/generators/patriarch/templates/service.rb
         | 
| 118 87 | 
             
            - lib/generators/patriarch/templates/tools_methods.rb
         | 
| 88 | 
            +
            - lib/generators/patriarch/templates/undo_service-tripartite.rb
         | 
| 119 89 | 
             
            - lib/generators/patriarch/templates/undo_service.rb
         | 
| 120 90 | 
             
            - lib/patriarch.rb
         | 
| 121 91 | 
             
            - lib/patriarch/authorization_service.rb
         | 
| 122 92 | 
             
            - lib/patriarch/behaviours.rb
         | 
| 123 | 
            -
            - lib/patriarch/dao_services/.DAOinstancier.rb.swp
         | 
| 124 93 | 
             
            - lib/patriarch/dao_services/bipartite_relationship_builder_service.rb
         | 
| 125 94 | 
             
            - lib/patriarch/dao_services/redis_mapper_service.rb
         | 
| 126 95 | 
             
            - lib/patriarch/dao_services/retriever_service.rb
         | 
| 96 | 
            +
            - lib/patriarch/dao_services/tripartite_relationship_builder_service.rb
         | 
| 127 97 | 
             
            - lib/patriarch/manager_service.rb
         | 
| 128 98 | 
             
            - lib/patriarch/service.rb
         | 
| 129 | 
            -
            - lib/patriarch/tool_services/ | 
| 99 | 
            +
            - lib/patriarch/tool_services/redis_cleaner_service.rb
         | 
| 130 100 | 
             
            - lib/patriarch/tool_services/redis_extractor_service.rb
         | 
| 131 101 | 
             
            - lib/patriarch/transaction.rb
         | 
| 132 102 | 
             
            - lib/patriarch/transaction_services/transaction_manager_service.rb
         | 
| 133 103 | 
             
            - lib/patriarch/transaction_step.rb
         | 
| 134 104 | 
             
            - lib/patriarch/version.rb
         | 
| 135 105 | 
             
            - patriarch.gemspec
         | 
| 136 | 
            -
            - spec/lib/patriarch/ | 
| 137 | 
            -
            - spec/lib/patriarch/bipartite_relationship_builder_spec.rb
         | 
| 138 | 
            -
            - spec/lib/patriarch/ | 
| 106 | 
            +
            - spec/lib/patriarch/behaviours_spec.rb
         | 
| 107 | 
            +
            - spec/lib/patriarch/dao_services/bipartite_relationship_builder_spec.rb
         | 
| 108 | 
            +
            - spec/lib/patriarch/dao_services/tripartite_relationship_builder_spec.rb
         | 
| 139 109 | 
             
            - spec/lib/patriarch/redis_mapper_service_spec.rb
         | 
| 140 110 | 
             
            - spec/lib/patriarch/retriever_service_spec.rb
         | 
| 111 | 
            +
            - spec/lib/patriarch/tool_services/redis_cleaner_service_spec.rb
         | 
| 112 | 
            +
            - spec/lib/patriarch/transaction_spec.rb
         | 
| 113 | 
            +
            - spec/lib/patriarch/transaction_step_spec.rb
         | 
| 141 114 | 
             
            - spec/spec_helper.rb
         | 
| 142 115 | 
             
            homepage: https://github.com/giglemad/patriarch
         | 
| 143 116 | 
             
            licenses:
         | 
| 144 117 | 
             
            - MIT
         | 
| 145 | 
            -
            post_install_message: Thanks for installing!
         | 
| 118 | 
            +
            post_install_message: ! 'Thanks for installing Patriarch ! Since it''s my first gem,
         | 
| 119 | 
            +
              please give some advice so i can improve it or even better : contribute'
         | 
| 146 120 | 
             
            rdoc_options: []
         | 
| 147 121 | 
             
            require_paths:
         | 
| 148 122 | 
             
            - lib
         | 
| @@ -165,9 +139,12 @@ signing_key: | |
| 165 139 | 
             
            specification_version: 3
         | 
| 166 140 | 
             
            summary: Manage relationships between instances of your models easily
         | 
| 167 141 | 
             
            test_files:
         | 
| 168 | 
            -
            - spec/lib/patriarch/ | 
| 169 | 
            -
            - spec/lib/patriarch/bipartite_relationship_builder_spec.rb
         | 
| 170 | 
            -
            - spec/lib/patriarch/ | 
| 142 | 
            +
            - spec/lib/patriarch/behaviours_spec.rb
         | 
| 143 | 
            +
            - spec/lib/patriarch/dao_services/bipartite_relationship_builder_spec.rb
         | 
| 144 | 
            +
            - spec/lib/patriarch/dao_services/tripartite_relationship_builder_spec.rb
         | 
| 171 145 | 
             
            - spec/lib/patriarch/redis_mapper_service_spec.rb
         | 
| 172 146 | 
             
            - spec/lib/patriarch/retriever_service_spec.rb
         | 
| 147 | 
            +
            - spec/lib/patriarch/tool_services/redis_cleaner_service_spec.rb
         | 
| 148 | 
            +
            - spec/lib/patriarch/transaction_spec.rb
         | 
| 149 | 
            +
            - spec/lib/patriarch/transaction_step_spec.rb
         | 
| 173 150 | 
             
            - spec/spec_helper.rb
         | 
| @@ -1,114 +0,0 @@ | |
| 1 | 
            -
            require "rails/generators"
         | 
| 2 | 
            -
            require "redis/objects/sorted_sets"
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            class PatriarchGenerator < Rails::Generators::Base
         | 
| 5 | 
            -
              source_root File.expand_path('../templates', __FILE__)
         | 
| 6 | 
            -
              
         | 
| 7 | 
            -
              desc "Generate files needed to implement the BEHAVIOUR you specified. Don't forget to add declarations into models"
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              argument :behaviour, :type => :string
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              public
         | 
| 12 | 
            -
              def init_directories
         | 
| 13 | 
            -
                empty_directory "lib/patriarch/services/#{behaviour.underscore.downcase}"
         | 
| 14 | 
            -
                empty_directory "lib/patriarch/services/#{Patriarch.undo(behaviour.underscore.downcase)}"
         | 
| 15 | 
            -
                template "empty_behaviour_module.rb", "lib/patriarch/behaviours/#{behaviour.underscore.downcase}.rb"   
         | 
| 16 | 
            -
                template "empty_service_module.rb", "lib/patriarch/services/#{behaviour.underscore.downcase}.rb"         
         | 
| 17 | 
            -
                template "tools_methods.rb", "lib/patriarch/behaviours/#{behaviour.underscore.downcase}/tools_methods.rb"
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              def ensure_autoload
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                puts destination_root
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                # Copy empty declaration if it does not exists so we can insert autoload declaration
         | 
| 25 | 
            -
                unless File.exists? [File.expand_path(destination_root),"lib/patriarch/behaviours.rb"].join('/')
         | 
| 26 | 
            -
                  copy_file "empty_behaviours_declaration.rb", "lib/patriarch/behaviours.rb"
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                unless File.exists? "lib/patriarch/services.rb"    
         | 
| 30 | 
            -
                  copy_file "empty_services_declaration.rb", "lib/patriarch/services.rb" 
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                # Autoload declaration insertion
         | 
| 34 | 
            -
                insert_into_file "lib/patriarch/services.rb", :after => "  module Services\n" do
         | 
| 35 | 
            -
                  "    autoload :#{class_name}, 'patriarch/services/#{behaviour.underscore.downcase}.rb'\n"
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                insert_into_file "lib/patriarch/services.rb", :after => "  module Services\n" do
         | 
| 39 | 
            -
                  "    autoload :#{undo_class_name}, 'patriarch/services/#{behaviour.underscore.downcase}.rb'\n"
         | 
| 40 | 
            -
                end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                # Autoload declaration insertion
         | 
| 43 | 
            -
                insert_into_file "lib/patriarch/behaviours.rb", :after => "  module Behaviours\n" do
         | 
| 44 | 
            -
                  "    autoload :#{class_name}, 'patriarch/behaviours/#{behaviour.underscore.downcase}.rb'\n"
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                insert_into_file "lib/patriarch/behaviours.rb", :after => "  module Behaviours\n" do
         | 
| 48 | 
            -
                  "    autoload :#{undo_class_name}, 'patriarch/behaviours/#{Patriarch.undo(behaviour.underscore.downcase)}.rb'\n"
         | 
| 49 | 
            -
                end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                # load File.expand_path('lib/patriarch/behaviours.rb', __FILE__)
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
              def build_initializer
         | 
| 55 | 
            -
                unless File.exists? "config/initializers/patriarch.rb" 
         | 
| 56 | 
            -
                  create_file "config/initializers/patriarch.rb" do 
         | 
| 57 | 
            -
                    "require 'patriarch'\n\n"+
         | 
| 58 | 
            -
                    "load File.expand_path('../../../lib/patriarch/behaviours.rb', __FILE__)\n" + 
         | 
| 59 | 
            -
                    "load File.expand_path('../../../lib/patriarch/services.rb', __FILE__)"
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
                end
         | 
| 62 | 
            -
              end
         | 
| 63 | 
            -
             | 
| 64 | 
            -
              def generate_services
         | 
| 65 | 
            -
                create_services(behaviour)
         | 
| 66 | 
            -
                # implémenter un switch ici, plus zoli ...
         | 
| 67 | 
            -
                self.class.send(:define_method,:class_name) do
         | 
| 68 | 
            -
                  Patriarch.undo(behaviour).classify
         | 
| 69 | 
            -
                end
         | 
| 70 | 
            -
                create_undo_services(behaviour)
         | 
| 71 | 
            -
              end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
              private
         | 
| 74 | 
            -
                def class_name
         | 
| 75 | 
            -
                  behaviour.classify
         | 
| 76 | 
            -
                end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                def undo_class_name
         | 
| 79 | 
            -
                  Patriarch.undo(behaviour).classify
         | 
| 80 | 
            -
                end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                def create_services(behaviour)
         | 
| 83 | 
            -
                  behaviour_str = behaviour.underscore.downcase
         | 
| 84 | 
            -
                  template "authorization_service.rb", "lib/patriarch/services/#{behaviour_str}/authorization_service.rb"
         | 
| 85 | 
            -
                  
         | 
| 86 | 
            -
                  template "before_manager_service.rb", "lib/patriarch/services/#{behaviour_str}/before_manager_service.rb"
         | 
| 87 | 
            -
                  template "before_service.rb", "lib/patriarch/services/#{behaviour_str}/before_service.rb"
         | 
| 88 | 
            -
             | 
| 89 | 
            -
                  template "manager_service.rb", "lib/patriarch/services/#{behaviour_str}/manager_service.rb"
         | 
| 90 | 
            -
                            
         | 
| 91 | 
            -
                  template "service.rb", "lib/patriarch/services/#{behaviour_str}/service.rb"    
         | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
                  template "after_manager_service.rb", "lib/patriarch/services/#{behaviour_str}/after_manager_service.rb"
         | 
| 95 | 
            -
                  template "after_service.rb", "lib/patriarch/services/#{behaviour_str}/after_service.rb"
         | 
| 96 | 
            -
                end
         | 
| 97 | 
            -
             | 
| 98 | 
            -
                def create_undo_services(behaviour)
         | 
| 99 | 
            -
                  undo_behaviour_str = Patriarch.undo(behaviour).underscore.downcase
         | 
| 100 | 
            -
             | 
| 101 | 
            -
                  template "authorization_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/authorization_service.rb"
         | 
| 102 | 
            -
                  
         | 
| 103 | 
            -
                  template "before_manager_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/before_manager_service.rb"
         | 
| 104 | 
            -
                  template "before_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/before_service.rb"
         | 
| 105 | 
            -
             | 
| 106 | 
            -
                  template "manager_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/manager_service.rb"
         | 
| 107 | 
            -
                            
         | 
| 108 | 
            -
                  template "undo_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/service.rb"    
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                  template "after_manager_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/after_manager_service.rb"
         | 
| 111 | 
            -
                  template "after_service.rb", "lib/patriarch/services/#{undo_behaviour_str}/after_service.rb"
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
            end # PatriarchGenerator
         | 
| Binary file | 
| @@ -1,47 +0,0 @@ | |
| 1 | 
            -
            class Patriarch::ToolServices::RedisExtractorService < Patriarch::Service
         | 
| 2 | 
            -
              def clean_reclip_id(reclip_id)
         | 
| 3 | 
            -
                # Go get the hash of this reclip to clean depencies
         | 
| 4 | 
            -
                reclip_hash = Redis::HashKey.new("reclip:#{reclip_id}")
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                # Clean dependencies on the recliped_on entity, the recliper entity and the reclipped item
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                recliped_on_sorted_set =     Redis::SortedSet.new("#{reclip_hash['recliped_on_type'].downcase}:#{reclip_hash['recliped_on_id']}:redis_reclipeds_on_me")
         | 
| 9 | 
            -
                recliper_sorted_set    =     Redis::SortedSet.new("#{reclip_hash['recliper_type'].downcase}:#{reclip_hash['recliper_id']}:redis_reclipeds_by_me")
         | 
| 10 | 
            -
                item_reclip_ids_sorted_set = Redis::SortedSet.new("item:#{reclip_hash['recliped_item_id']}:redis_reclips_of_me")
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                $redis.multi do 
         | 
| 13 | 
            -
                  recliped_on_sorted_set.delete reclip_id              # recliped_on is cleaned
         | 
| 14 | 
            -
                  recliper_sorted_set.delete reclip_id                 # recliper is cleaned
         | 
| 15 | 
            -
                  reclip_hash.del                                      # hash is deleted properly
         | 
| 16 | 
            -
                  item_reclip_ids_sorted_set.delete reclip_id                     # item_key is cleaned from this reclip_id
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              def clean_reclip_for_item_before_delete(item)
         | 
| 21 | 
            -
                item_reclip_ids = Redis::SortedSet.new("item:#{item.id}:redis_reclips_of_me")
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                # For each reclip involving our item
         | 
| 24 | 
            -
                item_reclip_ids.members.each do |reclip_id|
         | 
| 25 | 
            -
                  clean_reclip_id(reclip_id)
         | 
| 26 | 
            -
                end          
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              def clean_reclip_for_group_before_delete(group)
         | 
| 30 | 
            -
                # Goal here is to clean reclipeds_on_me dependencies and reclipeds_by_me before the group dies
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                # reclipeds_on_me
         | 
| 33 | 
            -
                reclipeds_on_me_sorted_set = group.redis_reclipeds_on_me
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                reclipeds_on_me_sorted_set.members.each do |reclip_id|
         | 
| 36 | 
            -
                  clean_reclip_id(reclip_id)
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
                # reclipeds_by_me
         | 
| 41 | 
            -
                reclipeds_by_me_sorted_set = group.redis_reclipeds_by_me
         | 
| 42 | 
            -
                
         | 
| 43 | 
            -
                reclipeds_by_me_sorted_set.members.each do |reclip_id|
         | 
| 44 | 
            -
                  clean_reclip_id(reclip_id)
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
            end  
         | 
| @@ -1,59 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe Patriarch::Behaviours do
         | 
| 4 | 
            -
              
         | 
| 5 | 
            -
              Monster.add_behaviour       :like, :on => [:fallenAngel]
         | 
| 6 | 
            -
              FallenAngel.add_behaviour   :like, :by => [:monster]
         | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
              context "when adding a behaviour" do
         | 
| 10 | 
            -
                before(:all) do
         | 
| 11 | 
            -
                  @monster        = new_monster
         | 
| 12 | 
            -
                  @fallen_angel   = new_fallen_angel
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                it "should implement basic tool methods" do
         | 
| 16 | 
            -
                  progressive_like = (Verbs::Conjugator.conjugate :like, :aspect => :progressive).split(/ /).last
         | 
| 17 | 
            -
                  @monster.should         respond_to("#{"fallen_angel".pluralize}_i_like")
         | 
| 18 | 
            -
                  @monster.should         respond_to("#{"fallen_angel".pluralize}_i_like_ids")
         | 
| 19 | 
            -
                  @fallen_angel.should    respond_to("#{"monster".pluralize}_#{progressive_like}_me")
         | 
| 20 | 
            -
                  @fallen_angel.should    respond_to("#{"monster".pluralize}_#{progressive_like}_me_ids")
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                it "should implement actions only on model being added behaviours with ':on' options" do
         | 
| 24 | 
            -
                  @monster.should           respond_to(:like)
         | 
| 25 | 
            -
                  @monster.should           respond_to(:undo_like)
         | 
| 26 | 
            -
                  @fallen_angel.should_not  respond_to(:like)
         | 
| 27 | 
            -
                  @fallen_angel.should_not  respond_to(:undo_like)
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end # context "when adding a behaviour"
         | 
| 30 | 
            -
             | 
| 31 | 
            -
              context "when using an added behaviour" do
         | 
| 32 | 
            -
                before(:all) do
         | 
| 33 | 
            -
                  @monster = new_monster
         | 
| 34 | 
            -
                  @fallen_angel   = new_fallen_angel
         | 
| 35 | 
            -
                  @monster.like @fallen_angel         
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                it "shall play the transaction nicely" do 
         | 
| 39 | 
            -
                  @monster.fallen_angels_i_like.should == [@fallen_angel]
         | 
| 40 | 
            -
                  @fallen_angel.monsters_liking_me.should == [@monster]
         | 
| 41 | 
            -
                  
         | 
| 42 | 
            -
                  @monster.fallen_angels_i_like_ids.should == [@fallen_angel.id]
         | 
| 43 | 
            -
                  @fallen_angel.monsters_liking_me_ids.should == [@monster.id]
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                it "shall play reverse transaction nicely" do
         | 
| 47 | 
            -
                  @monster.undo_like @fallen_angel
         | 
| 48 | 
            -
                  @monster.fallen_angels_i_like.include?(@fallen_angel).should be_false
         | 
| 49 | 
            -
                  @fallen_angel.monsters_liking_me.include?(@monster).should be_false
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                  @monster.fallen_angels_i_like_ids.should be_empty
         | 
| 52 | 
            -
                  @fallen_angel.monsters_liking_me_ids.should be_empty
         | 
| 53 | 
            -
                end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                after(:all) do
         | 
| 56 | 
            -
                  @monster.undo_like @fallen_angel   
         | 
| 57 | 
            -
                end 
         | 
| 58 | 
            -
              end # context "when using an added behaviour"
         | 
| 59 | 
            -
            end # describe
         | 
| @@ -1,19 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe Patriarch::Services do
         | 
| 4 | 
            -
              before (:each) do
         | 
| 5 | 
            -
                @monster        = new_monster
         | 
| 6 | 
            -
                @fallen_angel   = new_fallen_angel
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              context "LikeService" do
         | 
| 10 | 
            -
                it "should register like informations properly" do
         | 
| 11 | 
            -
                  # Wrong way of doing tests, test should not know about what's inside ...
         | 
| 12 | 
            -
                  pending "redo this test ffs"
         | 
| 13 | 
            -
                  # Patriarch::Services::Like::ManagerService.instance.resolve(@mc,@mk)
         | 
| 14 | 
            -
                  # Redis::SortedSet.new("mc:#{@mc.id}:redis_likes").members.include?(@mk.id.to_s).should be_true
         | 
| 15 | 
            -
                  # Redis::SortedSet.new("mk:#{@mk.id}:redis_liker_mcs").members.include?(@mc.id.to_s).should be_true    
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            end
         |