network_executive 0.0.1.alpha.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +15 -1
  3. data/README.md +9 -41
  4. data/Rakefile +38 -1
  5. data/app/assets/javascripts/application.js +13 -0
  6. data/app/assets/javascripts/network_executive/osd.js +46 -0
  7. data/app/assets/javascripts/network_executive/set_top_box.js +44 -0
  8. data/app/assets/stylesheets/network_executive/application.css +16 -0
  9. data/app/assets/stylesheets/network_executive/gui_components.css +17 -0
  10. data/app/assets/stylesheets/network_executive/normalize.css +500 -0
  11. data/app/assets/stylesheets/network_executive/osd.css +33 -0
  12. data/app/assets/stylesheets/network_executive/smpte.css +164 -0
  13. data/app/controllers/network_executive/application_controller.rb +4 -0
  14. data/app/controllers/network_executive/network_controller.rb +9 -0
  15. data/app/helpers/network_executive/network_helper.rb +7 -0
  16. data/app/models/network_executive/channel.rb +46 -0
  17. data/app/models/network_executive/channel_schedule.rb +13 -0
  18. data/app/models/network_executive/lineup.rb +66 -0
  19. data/app/models/network_executive/lineup_range.rb +34 -0
  20. data/app/models/network_executive/network.rb +10 -0
  21. data/app/models/network_executive/program.rb +39 -0
  22. data/app/models/network_executive/program_schedule.rb +148 -0
  23. data/app/models/network_executive/viewer.rb +76 -0
  24. data/app/views/network_executive/network/index.html.erb +39 -0
  25. data/config/routes.rb +7 -0
  26. data/lib/generators/network_executive/install_generator.rb +96 -0
  27. data/lib/generators/network_executive/templates/initializer.erb +5 -0
  28. data/lib/generators/network_executive/uninstall_generator.rb +20 -0
  29. data/lib/network_executive/configuration.rb +26 -0
  30. data/lib/network_executive/engine.rb +28 -0
  31. data/lib/network_executive/producer.rb +36 -0
  32. data/lib/network_executive/scheduling.rb +44 -0
  33. data/lib/network_executive/station/local_affiliate.rb +21 -0
  34. data/lib/network_executive/station.rb +11 -0
  35. data/lib/network_executive/version.rb +1 -1
  36. data/lib/network_executive.rb +18 -3
  37. data/network_executive.gemspec +9 -8
  38. data/spec/dummy/README.rdoc +261 -0
  39. data/spec/dummy/Rakefile +7 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/{lib/network_executive/templates/config/lineup.rb → spec/dummy/app/mailers/.gitkeep} +0 -0
  45. data/spec/dummy/app/models/.gitkeep +0 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/spec/dummy/config/application.rb +47 -0
  48. data/spec/dummy/config/boot.rb +10 -0
  49. data/spec/dummy/config/database.yml +25 -0
  50. data/spec/dummy/config/environment.rb +5 -0
  51. data/spec/dummy/config/environments/development.rb +37 -0
  52. data/spec/dummy/config/environments/production.rb +67 -0
  53. data/spec/dummy/config/environments/test.rb +37 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/inflections.rb +15 -0
  56. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  57. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  58. data/spec/dummy/config/initializers/session_store.rb +8 -0
  59. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/spec/dummy/config/locales/en.yml +5 -0
  61. data/spec/dummy/config/routes.rb +3 -0
  62. data/spec/dummy/config.ru +4 -0
  63. data/spec/dummy/lib/assets/.gitkeep +0 -0
  64. data/spec/dummy/log/.gitkeep +0 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +25 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/generators/install_generator_spec.rb +129 -0
  71. data/spec/generators/uninstall_generator_spec.rb +39 -0
  72. data/spec/helpers/network_helper_spec.rb +7 -0
  73. data/spec/models/channel_schedule_spec.rb +29 -0
  74. data/spec/models/channel_spec.rb +55 -0
  75. data/spec/models/lineup_range_spec.rb +65 -0
  76. data/spec/models/lineup_spec.rb +95 -0
  77. data/spec/models/network_spec.rb +11 -0
  78. data/spec/models/program_schedule_spec.rb +399 -0
  79. data/spec/models/program_spec.rb +37 -0
  80. data/spec/models/viewer_spec.rb +210 -0
  81. data/spec/network_executive_spec.rb +15 -0
  82. data/spec/spec_helper.rb +27 -1
  83. data/spec/unit/configuration_spec.rb +3 -0
  84. data/spec/unit/producer_spec.rb +60 -0
  85. data/spec/unit/scheduling_spec.rb +106 -0
  86. data/spec/unit/station/local_affiliate_spec.rb +41 -0
  87. data/tasks/network_executive_tasks.rake +4 -0
  88. metadata +177 -40
  89. data/lib/network_executive/behaviors/file_system.rb +0 -73
  90. data/lib/network_executive/behaviors/terminal_output.rb +0 -84
  91. data/lib/network_executive/cli.rb +0 -29
  92. data/lib/network_executive/commands/application.rb +0 -64
  93. data/lib/network_executive/commands/server.rb +0 -48
  94. data/lib/network_executive/network.rb +0 -5
  95. data/lib/network_executive/templates/app/channels/.gitkeep +0 -1
  96. data/lib/network_executive/templates/config/my_network.rb +0 -5
  97. data/lib/network_executive/templates/my_network.ru +0 -4
  98. data/lib/network_executive/templates/public/.gitkeep +0 -1
  99. data/spec/commands/application_spec.rb +0 -58
  100. data/spec/commands/server_spec.rb +0 -15
@@ -0,0 +1,46 @@
1
+ require 'network_executive/network'
2
+ require 'network_executive/scheduling'
3
+
4
+ module NetworkExecutive
5
+ class Channel < EventMachine::Channel
6
+ include Scheduling
7
+
8
+ # Example
9
+ # every :monday, play:'morning_show'
10
+ # every :day, play:'stoplight', for_the_first:'15mins', of:'each hour', ending_at:'11am'
11
+ # every :day, play:'tweets', for_the_last: '15mins', of:'every hour'
12
+ # every :day, play:'sales', for_the_first:'15mins', of:'each hour', between:'2pm and 5pm'
13
+ # every :friday, play:'lunch_menu', between:'11am and 13pm', commercial_free:true
14
+
15
+ def name
16
+ self.class.name.demodulize.underscore
17
+ end
18
+
19
+ def display_name
20
+ name.gsub %r{_}, ' '
21
+ end
22
+ alias_method :to_s, :display_name
23
+
24
+ def show( scheduled_program )
25
+ program = Program.find_by_name scheduled_program.program_name
26
+
27
+ raise ProgramNotFoundError.new("#{scheduled_program.program_name} is not a registered channel") unless program
28
+
29
+ push program.play
30
+ end
31
+
32
+ class << self
33
+ def inherited( klass )
34
+ Network.channels << klass.new
35
+ end
36
+
37
+ # TODO: Is this the right place for this?
38
+ def find_by_name( name )
39
+ Network.channels.find do |c|
40
+ c.name == name
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ module NetworkExecutive
2
+ class ChannelSchedule < Array
3
+
4
+ def add( program )
5
+ unshift program
6
+ end
7
+
8
+ def find_by_showtime( time )
9
+ find{ |p| p.include? time }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,66 @@
1
+ # Represents a channel's programming line up for a given time span.
2
+ module NetworkExecutive
3
+ # TODO: Why does this subclass Hash?
4
+ class Lineup < Hash
5
+
6
+ Interval = 15 # In minutes.
7
+ Range = 1.5 # In hours.
8
+
9
+ def initialize( start = Time.now, stop = nil )
10
+ self.start_time = start || Time.now
11
+ self.stop_time = stop || Time.now + Range.hours
12
+
13
+ self[:channels] = generate
14
+ end
15
+
16
+ def generate
17
+ with_each_channel do |channel, lineup|
18
+ lineup << {
19
+ name: channel.display_name,
20
+ schedule: whats_on?( channel ) do |show|
21
+ show.program_name.titleize
22
+ end
23
+ }
24
+ end
25
+ end
26
+
27
+ def start_time=( time )
28
+ @start_time = floor time
29
+ end
30
+
31
+ def start_time
32
+ @start_time
33
+ end
34
+
35
+ def stop_time=( time )
36
+ @stop_time = floor time
37
+ end
38
+
39
+ def stop_time
40
+ @stop_time
41
+ end
42
+
43
+ private
44
+
45
+ # Rounds the specific time to the nearest interval
46
+ def floor( time, nearest = nil )
47
+ nearest ||= Interval.minutes
48
+
49
+ Time.at((time.to_f / nearest.to_i).floor * nearest.to_i)
50
+ end
51
+
52
+ # TODO: Decouple
53
+ def with_each_channel
54
+ Network.channels.each_with_object([]) do |channel, lu|
55
+ yield channel, lu
56
+ end
57
+ end
58
+
59
+ # TODO: Decouple
60
+ def whats_on?( channel )
61
+ channel.whats_on?( start_time, stop_time, interval:Interval ) do |show|
62
+ yield show
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,34 @@
1
+ module NetworkExecutive
2
+ class LineupRange
3
+
4
+ def initialize( start, stop, options = {} )
5
+ @start, @stop, @options = start, stop, options
6
+
7
+ @options[:interval] ||= 15
8
+ end
9
+
10
+ def each
11
+ showtime = @start.dup
12
+
13
+ while showtime < @stop
14
+ yield showtime
15
+
16
+ showtime += @options[:interval].minutes
17
+ end
18
+ end
19
+
20
+ def each_with_object( obj )
21
+ each do |showtime|
22
+ yield showtime, obj
23
+ end
24
+
25
+ obj
26
+ end
27
+
28
+ # Divides a time span into segments specified by the 'interval' option
29
+ def segments
30
+ ( ( (@stop - @start) / 1.hour ) / @options[:interval] ).minutes.to_i
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ module NetworkExecutive
2
+ class Network
3
+
4
+ cattr_accessor :channels, :programming
5
+
6
+ end
7
+
8
+ Network.channels = []
9
+ Network.programming = []
10
+ end
@@ -0,0 +1,39 @@
1
+ require 'multi_json'
2
+
3
+ module NetworkExecutive
4
+ class Program
5
+
6
+ def name
7
+ self.class.name.demodulize.underscore
8
+ end
9
+
10
+ def url
11
+ ''
12
+ end
13
+
14
+ def as_json
15
+ {
16
+ name: name,
17
+ url: url
18
+ }
19
+ end
20
+
21
+ def play
22
+ MultiJson.encode( as_json )
23
+ end
24
+
25
+ class << self
26
+ def inherited( klass )
27
+ Network.programming << klass.new
28
+ end
29
+
30
+ # TODO: Is this the right place for this?
31
+ def find_by_name( name )
32
+ Network.programming.find do |p|
33
+ p.name == name
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,148 @@
1
+ # Example
2
+ # every :monday, play:'morning_show'
3
+ # every :day, play:'stoplight', for_the_first:'15mins', of:'each hour'
4
+ # every :day, play:'stoplight', for_the_first:'15mins', of:'each hour', starting_at:'11am'
5
+ # every :day, play:'stoplight', for_the_first:'15mins', of:'each hour', ending_at:'11am'
6
+ # every :day, play:'stoplight', for_the_first:'15mins', of:'each hour', starting_at:'10am', ending_at:'11am'
7
+ # every :day, play:'tweets', for_the_last: '15mins', of:'every hour'
8
+ # every :day, play:'sales', for_the_first:'15mins', of:'each hour', between:'2pm and 5pm'
9
+ # every :friday, play:'lunch_menu', between:'11am and 13pm', commercial_free:true
10
+
11
+ module NetworkExecutive
12
+
13
+ class ProgramSchedule
14
+ attr_accessor :day, :program_name
15
+
16
+ Weekdays = %w{sunday monday tuesday wednesday thursday friday saturday}
17
+ BaseDate = { month:2, day:15, year:1978 }
18
+
19
+ def initialize( day, options = {} )
20
+ options.symbolize_keys!
21
+
22
+ raise ProgramNameError unless options[:play]
23
+
24
+ if options[:starting_at] || options[:ending_at]
25
+ range = []
26
+ range << ( options[:starting_at] || '12am' )
27
+ range << ( options[:ending_at] || '11:59pm' )
28
+ options[:between] = range.join ' and '
29
+ end
30
+
31
+ self.day = day
32
+ self.program_name = options[:play]
33
+ @between = options[:between]
34
+ @for_the_first = options[:for_the_first]
35
+ @for_the_last = options[:for_the_last]
36
+ @period = options[:of]
37
+ @commercial_free = options[:commercial_free]
38
+ end
39
+
40
+ def day=( new_day )
41
+ new_day = :any if new_day == :day
42
+
43
+ @day = new_day
44
+ end
45
+
46
+ def include?( date )
47
+ day_matches? date \
48
+ and time_matches? date
49
+ end
50
+
51
+ def commercials?
52
+ @commercial_free.nil? ? true : !@commercial_free
53
+ end
54
+
55
+ def to_s
56
+ inspect
57
+ end
58
+
59
+ def inspect
60
+ range = @between || '12am and 11:59pm'
61
+
62
+ %Q{<#{self.class} program_name="#{program_name}" day="#{@day}" between="#{range}" for_the_first="#{@for_the_first || 'nil'}" for_the_last="#{@for_the_last || 'nil'}" commercial_free=#{!commercials?}>}
63
+ end
64
+
65
+ private
66
+
67
+ def day_matches?( date )
68
+ if day == :any
69
+ true
70
+ elsif day.to_s == Weekdays[date.wday]
71
+ true
72
+ end
73
+ end
74
+
75
+ def time_matches?( date )
76
+ comparator = date.dup.change BaseDate
77
+
78
+ validations = []
79
+
80
+ validations << time_span.cover?( comparator ) if time_span?
81
+
82
+ validations << pattern.cover?( comparator ) if repeating?
83
+
84
+ validations.none? { |v| v == false }
85
+ end
86
+
87
+ def time_span?
88
+ @between
89
+ end
90
+
91
+ def time_span
92
+ if matches = @between.match( %r{(?<start>\d+:?\w*)\s*\S+\s*(?<stop>\d+:?\w*)} )
93
+ # Normalize the range to an arbitrary date since we only care about Time.
94
+ start = Time.parse( matches[:start] ).change BaseDate
95
+ stop = Time.parse( matches[:stop] ).change BaseDate
96
+
97
+ start...stop
98
+ end
99
+ end
100
+
101
+ def repeating?
102
+ @for_the_first || @for_the_last
103
+ end
104
+
105
+ def pattern
106
+ return TimePattern.new @period, first:@for_the_first if @for_the_first
107
+ return TimePattern.new @period, last:@for_the_last if @for_the_last
108
+
109
+ raise StandardError, 'No parsable time pattern'
110
+ end
111
+
112
+ end
113
+
114
+ class TimePattern
115
+ # TODO: Add support for :period
116
+ def initialize( period, pattern )
117
+ @period = period
118
+ @boundary = pattern.keys.first
119
+ @pattern = parse pattern
120
+ end
121
+
122
+ def cover?( date )
123
+ range = if @boundary == :first
124
+ 0...@pattern[:value]
125
+ elsif @boundary == :last
126
+ (60 - @pattern[:value])..59
127
+ else
128
+ raise ArgumentError, 'Missing a valid pattern boundary'
129
+ end
130
+
131
+ range.include? date.send( @pattern[:unit] )
132
+ end
133
+
134
+ private
135
+
136
+ def parse( p )
137
+ value, unit = p[@boundary].split( %r{(\d+)\s*(\w+)} )[1..-1]
138
+
139
+ unit = case unit[0]
140
+ when 'm' then :min
141
+ end
142
+
143
+ { value:value.to_i, unit:unit }
144
+ end
145
+
146
+ end
147
+
148
+ end
@@ -0,0 +1,76 @@
1
+ module NetworkExecutive
2
+ class Viewer
3
+
4
+ attr_accessor :id, :heartbeat
5
+
6
+ def initialize( env )
7
+ @env = env
8
+ end
9
+
10
+ def ip
11
+ @ip ||= begin
12
+ if addr = @env['HTTP_X_FORWARDED_FOR']
13
+ (addr.split(',').grep(/\d\./).first || @env['REMOTE_ADDR']).to_s.strip
14
+ else
15
+ @env['REMOTE_ADDR']
16
+ end
17
+ end
18
+ end
19
+
20
+ def channel
21
+ Channel.find_by_name( channel_name ).tap do |ch|
22
+ raise ChannelNotFoundError unless ch
23
+ end
24
+ end
25
+
26
+ def stream
27
+ @stream ||= Faye::EventSource.new @env
28
+ end
29
+
30
+ def tune_in
31
+ Rails.logger.debug "Tuning in to the #{channel} channel for #{ip} at #{Time.now}"
32
+
33
+ self.id = channel.subscribe { |msg| stream.send msg }
34
+
35
+ stream.onclose = method(:tune_out).to_proc
36
+ end
37
+
38
+ def tune_out( event )
39
+ Rails.logger.debug "Tuning out of the #{channel} channel for #{ip} at #{Time.now}"
40
+
41
+ channel.unsubscribe id
42
+
43
+ heartbeat.cancel
44
+
45
+ @stream = nil
46
+ end
47
+
48
+ def response
49
+ stream.rack_response
50
+ end
51
+
52
+ def channel_name
53
+ @env['PATH_INFO'].split('/').last
54
+ end
55
+
56
+ def keep_alive!
57
+ self.heartbeat = EM.add_periodic_timer( 30 ) do
58
+ stream.ping
59
+
60
+ Rails.logger.debug "Completed PING for #{ip} on the #{channel} channel at #{Time.now}"
61
+ end
62
+ end
63
+
64
+ class << self
65
+ def change_channel( env )
66
+ viewer = Viewer.new( env )
67
+
68
+ viewer.tune_in
69
+ viewer.keep_alive!
70
+
71
+ viewer.response
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width">
6
+ <title>Network Executive: <%= network_name %></title>
7
+ <link href='//fonts.googleapis.com/css?family=Lekton:400,700|Quicksand:300,400,700' rel='stylesheet' type='text/css'>
8
+ <%= stylesheet_link_tag 'network_executive/application', media:'all' %>
9
+ </head>
10
+ <body>
11
+ <iframe id="program" class="gui-comp"></iframe>
12
+ <div id="smpte">
13
+ <h1 id="smpte_message" class="msg"></h1>
14
+ <aside class="network-name"><%= network_name %></aside>
15
+ </div>
16
+ <div id="osd" class="gui-comp">
17
+ <header>
18
+ <h1 class="network-name">
19
+ <%= network_name %>
20
+ <aside class="osd-now">
21
+ <time class="osd-now-time">
22
+ <%= Time.now.strftime( '%l:%M%P') %>
23
+ </time>
24
+ <small class="osd-now-date">
25
+ <%= Time.now.strftime( '%B %e, %Y' ) %>
26
+ </small>
27
+ </aside>
28
+ </h1>
29
+ </header>
30
+ <article>
31
+ <% @channels.each do |channel| %>
32
+ <a href="/channels/<%= channel.name %>" class="channel"><%= channel.display_name %></a>
33
+ <% end %>
34
+ </article>
35
+ </div>
36
+
37
+ <%= javascript_include_tag 'application' %>
38
+ </body>
39
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ NetworkExecutive::Engine.routes.draw do
2
+ mount NetworkExecutive::Station => '/tune_in', as:'station'
3
+
4
+ match 'channels/:channel_name' => 'network#index'
5
+
6
+ root to:'network#index'
7
+ end
@@ -0,0 +1,96 @@
1
+ require 'rails/generators'
2
+
3
+ # http://guides.rubyonrails.org/generators.html
4
+ # http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
5
+
6
+ module NetworkExecutive
7
+ class InstallGenerator < Rails::Generators::Base
8
+ desc 'NetworkExecutive installation generator'
9
+
10
+ source_root File.expand_path( '../templates', __FILE__ )
11
+
12
+ def install
13
+ say 'Installing NetworkExecutive...', :magenta
14
+
15
+ create_initializer
16
+ mount_engine
17
+ add_channels_folder
18
+ add_programs_folder
19
+
20
+ say 'Done!', :green
21
+ end
22
+
23
+ private
24
+
25
+ def create_initializer
26
+ if initializer
27
+ say "You already have an initializer so I'm generating a new one at 'network_executive.rb.example' that you can review", :yellow
28
+
29
+ @network_name = NetworkExecutive.config.name
30
+
31
+ template 'initializer.erb', 'config/initializers/network_executive.rb.example', force:true
32
+ else
33
+ say 'What would you like to name your network?', :yellow
34
+
35
+ @network_name = ask(" Press <enter> for [#{default_network_name}] >").presence || default_network_name
36
+
37
+ NetworkExecutive.config.name = @network_name
38
+
39
+ template 'initializer.erb', 'config/initializers/network_executive.rb'
40
+ end
41
+ end
42
+
43
+ def mount_engine
44
+ if mounted?
45
+ say 'NetworkExecutive is already mounted, skipping routes update', :yellow
46
+ else
47
+ say 'Where do you want to mount NetworkExecutive?', :yellow
48
+
49
+ mount_at = ask(" Press <enter> for [/#{default_mount_location}] >").presence || default_mount_location
50
+
51
+ mount_at = sanitize mount_at
52
+
53
+ route "mount NetworkExecutive::Engine => '/#{mount_at}', as:'network_executive'"
54
+ end
55
+ end
56
+
57
+ # TODO: Uninstall steps
58
+ def add_channels_folder
59
+ create_file 'app/channels/.gitkeep'
60
+ end
61
+
62
+ # TODO: Uninstall steps
63
+ def add_programs_folder
64
+ create_file 'app/programs/.gitkeep'
65
+ end
66
+
67
+ def mounted?
68
+ routes =~ %r{mount NetworkExecutive::Engine}
69
+ end
70
+
71
+ def sanitize( path )
72
+ if path == '/'
73
+ ''
74
+ else
75
+ path.gsub %r{\A/}, ''
76
+ end
77
+ end
78
+
79
+ def routes
80
+ File.open(Rails.root.join('config/routes.rb')).try :read
81
+ end
82
+
83
+ def initializer
84
+ (File.open(Rails.root.join('config/initializers/network_executive.rb')) rescue nil).try :read
85
+ end
86
+
87
+ def default_network_name
88
+ NetworkExecutive.config.defaults['name']
89
+ end
90
+
91
+ def default_mount_location
92
+ NetworkExecutive.config.name.gsub(' ','').underscore
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,5 @@
1
+ # NetworkExecutive config file. Generated on <%= DateTime.now.to_s(:long) %>
2
+
3
+ NetworkExecutive.configure do |config|
4
+ config.name = '<%= @network_name %>'
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/generators'
2
+
3
+ module NetworkExecutive
4
+ class UninstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path( '../templates', __FILE__ )
6
+
7
+ desc 'NetworkExecutive uninstall'
8
+
9
+ def uninstall
10
+ say 'Uninstalling NetworkExecutive...', :magenta
11
+
12
+ remove_file 'config/initializers/network_executive.rb'
13
+ remove_file 'config/initializers/network_executive.rb.example'
14
+
15
+ gsub_file 'config/routes.rb', /mount NetworkExecutive::Engine => \'\/.+\', as:\S*\'network_executive\'/, ''
16
+
17
+ say 'Done!', :green
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'active_support/core_ext/hash'
2
+
3
+ module NetworkExecutive
4
+ class Configuration
5
+ attr_accessor :name
6
+
7
+ @@defaults = HashWithIndifferentAccess.new(
8
+ name: 'My Network'
9
+ )
10
+
11
+ def initialize
12
+ @@defaults.dup.each_pair { |k, v| self.send "#{k}=", v }
13
+ end
14
+
15
+ def defaults
16
+ @@defaults
17
+ end
18
+
19
+ def attributes
20
+ self.class.defaults.keys.each_with_object(HashWithIndifferentAccess.new) do |k, hash|
21
+ hash[k] = self.send k
22
+ end
23
+ end
24
+ alias_method :to_hash, :attributes
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # TODO: Only load when needed (enables asset pipeline)
2
+ require 'sass-rails'
3
+
4
+ module NetworkExecutive
5
+
6
+ class Engine < Rails::Engine
7
+ engine_name :network_executive
8
+
9
+ isolate_namespace NetworkExecutive
10
+
11
+ initializer 'network_executive.eager_load_channels' do |app|
12
+ eager_load_models_in 'channels', app
13
+ end
14
+
15
+ initializer 'network_executive.eager_load_programs' do |app|
16
+ eager_load_models_in 'programs', app
17
+ end
18
+
19
+ private
20
+
21
+ def eager_load_models_in( sub_path, app )
22
+ Dir[ File.join(app.root, 'app', sub_path, '*') ].each do |c|
23
+ require c
24
+ end
25
+ end
26
+
27
+ end
28
+ end