yodeler 0.0.10 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +33 -0
  3. data/.gitignore +9 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +16 -0
  8. data/README.md +158 -67
  9. data/Rakefile +4 -21
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/yodeler/adapter_not_registered_error.rb +14 -0
  13. data/lib/yodeler/adapters/http_adapter.rb +51 -0
  14. data/lib/yodeler/adapters/memory_adapter.rb +23 -0
  15. data/lib/yodeler/adapters/void_adapter.rb +10 -0
  16. data/lib/yodeler/client.rb +166 -0
  17. data/lib/yodeler/duplicate_endpoint_name_error.rb +9 -0
  18. data/lib/yodeler/endpoint.rb +35 -0
  19. data/lib/yodeler/metric.rb +36 -0
  20. data/lib/yodeler/version.rb +1 -1
  21. data/lib/yodeler.rb +41 -106
  22. data/yodeler.gemspec +29 -0
  23. metadata +44 -102
  24. data/MIT-LICENSE +0 -20
  25. data/app/assets/javascripts/yodeler/application.js +0 -13
  26. data/app/assets/stylesheets/yodeler/application.css +0 -13
  27. data/app/controllers/yodeler/application_controller.rb +0 -4
  28. data/app/helpers/yodeler/application_helper.rb +0 -4
  29. data/app/views/layouts/yodeler/application.html.erb +0 -14
  30. data/config/routes.rb +0 -2
  31. data/lib/generators/yodeler/USAGE +0 -2
  32. data/lib/generators/yodeler/install_generator.rb +0 -23
  33. data/lib/generators/yodeler/templates/initializer.rb +0 -7
  34. data/lib/generators/yodeler/templates/migration.rb +0 -50
  35. data/lib/tasks/yodeler_tasks.rake +0 -4
  36. data/lib/yodeler/configuration.rb +0 -12
  37. data/lib/yodeler/engine.rb +0 -10
  38. data/lib/yodeler/listens_to_yodeler.rb +0 -32
  39. data/lib/yodeler/models/event.rb +0 -17
  40. data/lib/yodeler/models/event_type.rb +0 -6
  41. data/lib/yodeler/models/event_types/base.rb +0 -59
  42. data/lib/yodeler/models/event_types/noop_event_type.rb +0 -12
  43. data/lib/yodeler/models/notification.rb +0 -30
  44. data/lib/yodeler/models/subscription.rb +0 -9
@@ -1,50 +0,0 @@
1
- class CreateYodelerTables < ActiveRecord::Migration
2
- def change
3
- create_table :yodeler_event_types do |t|
4
- t.string :name, null: false # Maps to registered name in DSL
5
- t.string :type #STI
6
- t.datetime :created_at
7
- end
8
-
9
- create_table :yodeler_events do |t|
10
- t.integer :yodeler_event_type_id, null: false
11
- t.datetime :started_at
12
- t.datetime :finished_at
13
- t.text :payload
14
- t.datetime :created_at, null: false
15
- end
16
-
17
- create_table :yodeler_subscriptions do |t|
18
- t.integer :yodeler_event_type_id, null: false
19
-
20
- # polymorphic, support for whatever type of class is owning the subscription
21
- t.string :subscriber_type, null: false
22
- t.integer :subscriber_id, null: false
23
-
24
- t.datetime :created_at
25
- t.datetime :updated_at
26
- end
27
-
28
- create_table :yodeler_notifications do |t|
29
- t.integer :yodeler_event_id, null: false
30
- t.integer :yodeler_subscription_id, null: false
31
- t.integer :state
32
- t.datetime :created_at, null: false
33
- t.datetime :updated_at, null: false
34
- end
35
-
36
- # sqlite3 has an index name length limitation of 62(?!) characters
37
- unless Rails.env.test?
38
- add_index :yodeler_event_types, :name, unique: true
39
-
40
- add_index :yodeler_events, :yodeler_event_type_id
41
-
42
- add_index :yodeler_subscriptions, :yodeler_event_type_id
43
- add_index :yodeler_subscriptions, [:subscriber_id, :subscriber_type]
44
-
45
- add_index :yodeler_notifications, :yodeler_event_id
46
- add_index :yodeler_notifications, :yodeler_subscription_id
47
- add_index :yodeler_notifications, :state
48
- end
49
- end
50
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :yodeler do
3
- # # Task goes here
4
- # end
@@ -1,12 +0,0 @@
1
- module Yodeler
2
- class Configuration
3
- include ActiveSupport::Configurable
4
- config_accessor(:test) { false }
5
- config_accessor(:default_states){
6
- {
7
- unread: 0,
8
- read: 1
9
- }
10
- }
11
- end
12
- end
@@ -1,10 +0,0 @@
1
- module Yodeler
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Yodeler
4
-
5
- config.generators do |g|
6
- g.test_framework :rspec
7
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
8
- end
9
- end
10
- end
@@ -1,32 +0,0 @@
1
- module Yodeler
2
- module ListensToYodeler
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- end
7
-
8
- module ClassMethods
9
- def listens_to_yodeler(subscriptions_assocation_name = :yodeler_subscriptions, notifications_association_name = :yodeler_notifications)
10
- cattr_accessor :yodeler_subscriptions_name
11
- cattr_accessor :yodeler_notifications_name
12
- self.yodeler_subscriptions_name = subscriptions_assocation_name
13
- self.yodeler_notifications_name = notifications_association_name
14
-
15
- has_many self.yodeler_subscriptions_name,
16
- dependent: :delete_all,
17
- class_name: "Yodeler::Subscription",
18
- foreign_key: :subscriber_id
19
-
20
- has_many self.yodeler_notifications_name,
21
- through: self.yodeler_subscriptions_name,
22
- foreign_key: :subscriber_id
23
-
24
- include Yodeler::ListensToYodeler::LocalInstanceMethods
25
- end
26
- end
27
-
28
- module LocalInstanceMethods;end;
29
- end
30
- end
31
-
32
- ActiveRecord::Base.send :include, Yodeler::ListensToYodeler
@@ -1,17 +0,0 @@
1
- module Yodeler
2
- class Event < ActiveRecord::Base
3
- serialize :payload, Hash
4
-
5
- validates_presence_of :event_type
6
-
7
- belongs_to :event_type, class_name: "Yodeler::EventType::Base", foreign_key: :yodeler_event_type_id
8
- has_many :notifications, class_name: "Yodeler::Notification", foreign_key: :yodeler_event_id
9
-
10
- delegate :subscriptions, to: :event_type
11
- delegate :name, to: :event_type
12
-
13
- def duration
14
- finished_at - started_at if finished_at.present? && started_at.present?
15
- end
16
- end
17
- end
@@ -1,6 +0,0 @@
1
- module Yodeler
2
- module EventType
3
- autoload :Base, "yodeler/models/event_types/base"
4
- autoload :NoopEventType, "yodeler/models/event_types/noop_event_type"
5
- end
6
- end
@@ -1,59 +0,0 @@
1
- module Yodeler
2
- module EventType
3
- class Base < ActiveRecord::Base
4
- self.table_name= "yodeler_event_types"
5
-
6
- class Configuration
7
- include ActiveSupport::Configurable
8
- config_accessor(:states) do
9
- Yodeler.configuration.default_states
10
- end
11
- end
12
-
13
- def self.configuration
14
- @configuration ||= Configuration.new
15
- end
16
-
17
- validates_presence_of :name
18
- validates_uniqueness_of :name
19
-
20
- has_many :events,
21
- dependent: :delete_all,
22
- class_name: "Yodeler::Event",
23
- foreign_key: :yodeler_event_type_id
24
-
25
- has_many :subscriptions,
26
- dependent: :delete_all,
27
- class_name: "Yodeler::Subscription",
28
- foreign_key: :yodeler_event_type_id
29
-
30
-
31
- # Logs the occurrence of a {Yodeler::Event} and dispatches notifications
32
- #
33
- # @param [Hash] params additional params to log
34
- # @option params [String] :started_at Benchmark started at time
35
- # @option params [String] :finished_at Benchmark finished at time
36
- #
37
- # @param [Hash] payload Serialized hash, anything you want
38
- #
39
- # @return [~Yodeler::EventType::Base] the logged event
40
- def self.yodel!(params)
41
- # Add the event type to the yodeler_event_types table
42
- current_event_type = self.first_or_create name: Yodeler.registrations.key(self)
43
-
44
- #current_event_type = self.first
45
- current_event = current_event_type.events.create(params)
46
-
47
- current_event_type.subscriptions.each do |subscriber|
48
- subscriber.notifications.create({
49
- yodeler_event_id: current_event.id,
50
- # get the integer out of the default state (first state)
51
- state: self.configuration.states.first.last
52
- })
53
- end
54
-
55
- current_event
56
- end
57
- end
58
- end
59
- end
@@ -1,12 +0,0 @@
1
- module Yodeler
2
- module EventType
3
- # The event that is dispatch if an Yodeler.dispatch is called on an event type that
4
- # does not exist
5
- #
6
- # @example
7
- # Yodeler.dispatch :i_dont_exist, my_payload
8
- # # => Yodeler.dispatch :noop, my_payload
9
- class NoopEventType < Yodeler::EventType::Base
10
- end
11
- end
12
- end
@@ -1,30 +0,0 @@
1
- module Yodeler
2
- class Notification < ActiveRecord::Base
3
- validates_presence_of :subscription
4
- validates_presence_of :event
5
-
6
- belongs_to :event, class_name: "Yodeler::Event", foreign_key: :yodeler_event_id
7
- belongs_to :subscription, class_name: "Yodeler::Subscription", foreign_key: :yodeler_subscription_id
8
-
9
- delegate :event_type, to: :event
10
- delegate :subscriber, to: :subscription
11
-
12
- def message
13
- I18n.t("yodeler.event_types.#{event_type_key}.message", event.payload)
14
- end
15
-
16
- def name
17
- I18n.t("yodeler.event_types.#{event_type_key}.name", event.payload)
18
- end
19
-
20
- def state
21
- state_enum_value = read_attribute :state
22
- event_type.class.configuration.states.key(state_enum_value)
23
- end
24
-
25
- protected
26
- def event_type_key
27
- event_type.name.to_sym
28
- end
29
- end
30
- end
@@ -1,9 +0,0 @@
1
- module Yodeler
2
- class Subscription < ActiveRecord::Base
3
- validates_presence_of :subscriber, :event_type
4
- belongs_to :event_type, class_name: "Yodeler::EventType::Base", foreign_key: :yodeler_event_type_id
5
- belongs_to :subscriber, polymorphic: true
6
-
7
- has_many :notifications, class_name: "Yodeler::Notification", foreign_key: :yodeler_subscription_id
8
- end
9
- end