Module: Promiscuous::Publisher::MockGenerator
- Defined in:
- lib/promiscuous/publisher/mock_generator.rb
Class Method Summary collapse
- .attributes_for(klass, parent = nil) ⇒ Object
- .generate ⇒ Object
- .modules ⇒ Object
- .publishers ⇒ Object
Class Method Details
.attributes_for(klass, parent = nil) ⇒ Object
47 48 49 50 51 |
# File 'lib/promiscuous/publisher/mock_generator.rb', line 47 def self.attributes_for(klass, parent=nil) attrs = klass.published_attrs attrs -= parent.published_attrs if parent attrs end |
.generate ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/promiscuous/publisher/mock_generator.rb', line 4 def self.generate ERB.new(<<-ERB.gsub(/^\s+<%/, '<%').gsub(/^ {6}/, ''), nil, '-').result(binding) # --------------------------------- # Auto-generated file. Do not edit. # --------------------------------- module <%= Promiscuous::Config.app.camelize %>::Publishers <% modules.each do |mod| -%> <%- if mod.constantize.is_a?(Class) -%> class <%= mod %>; end <%- else -%> module <%= mod %>; end <% end -%> <% end -%> <% publishers.each do |publisher| -%> <% %> # ------------------------------------------------------------------ class <%= publisher.publish_as %> include Promiscuous::Publisher::Model::Mock mock :from => '<%= Promiscuous::Config.app %>' <% if defined?(Mongoid::Document) && publisher.include?(Mongoid::Document) -%> mock :id => :bson <% end -%> <% %> <% attributes_for(publisher).each do |attr| -%> publish :<%= attr %> <% end -%> end <% publisher.descendants.each do |subclass| -%> class <%= subclass.publish_as %> < <%= subclass.superclass.publish_as %> <% attributes_for(subclass, subclass.superclass).each do |attr| -%> publish :<%= attr %> <% end -%> end <% end -%> <% end -%> end ERB end |
.modules ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/promiscuous/publisher/mock_generator.rb', line 53 def self.modules publishers .map { |publisher| [publisher.name, *publisher.descendants.map(&:name)] } .flatten .select { |name| name =~ /::/ } .map { |name| name.gsub(/::[^:]+$/, '') } .uniq .sort end |
.publishers ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/promiscuous/publisher/mock_generator.rb', line 63 def self.publishers Promiscuous::Publisher::Model.publishers.values .reject { |publisher| publisher.ancestors.include?(Promiscuous::Publisher::Model::Mock) } .reject { |publisher| publisher.publish_as =~ /^Promiscuous::/ } .map { |publisher| [publisher, publisher.descendants] } .flatten .reject { |publisher| publisher.superclass.respond_to?(:publish_as) && publisher.superclass.publish_as } end |