Sha256: 04636f6edfeb4638b05a88fab2707227b98a927370441695dbddca6d9feb5adc

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'rails'

module Resty
  class RestyRailtie < Rails::Railtie

    config.generators do
      require 'rails/generators'      
      require 'rails/generators/rails/controller/controller_generator'
      #require 'rails/generators/erb/scaffold/scaffold_generator'
      Rails::Generators::ControllerGenerator.hook_for :resty, :type => :boolean, :default => true do |controller|
        invoke controller, [ class_name, actions ]
      end
      #Erb::Generators::ScaffoldGenerator.source_paths.insert(0, File.expand_path('../../generators/ixtlan/templates', __FILE__))
    end

    config.after_initialize do
      ActiveRecord::Base.include_root_in_json = false
      # TODO there migt be a way to tell ALL ActiveModel:
      #ActiveModel::Base.include_root_in_json = false

      # get the time/date format right ;-) and match it with resty
      class DateTime
        def as_json(options = nil)
          strftime('%Y-%m-%dT%H:%M:%S.%s%z')
        end
      end
      class ActiveSupport::TimeWithZone
        def as_json(options = nil)
          strftime('%Y-%m-%dT%H:%M:%S.%s%z')
        end
      end
      class Date
        def as_json(options = nil)
          strftime('%Y-%m-%dT%H:%M:%S.%s%z')
        end
      end
      class Time
        def as_json(options = nil)
          strftime('%Y-%m-%dT%H:%M:%S.%s%z')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
resty-generators-0.2.0 lib/resty/resty_railtie.rb
resty-generators-0.1.0 lib/resty/resty_railtie.rb