Class: Contentful::Bootstrap::Commands::GenerateJson
- Inherits:
-
Object
- Object
- Contentful::Bootstrap::Commands::GenerateJson
- Defined in:
- lib/contentful/bootstrap/commands/generate_json.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#space_id ⇒ Object
readonly
Returns the value of attribute space_id.
Instance Method Summary collapse
-
#initialize(space_id, access_token, filename = nil) ⇒ GenerateJson
constructor
A new instance of GenerateJson.
- #run ⇒ Object
- #write(json) ⇒ Object
Constructor Details
#initialize(space_id, access_token, filename = nil) ⇒ GenerateJson
Returns a new instance of GenerateJson.
9 10 11 12 13 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 9 def initialize(space_id, access_token, filename = nil) @space_id = space_id @access_token = access_token @filename = filename end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def access_token @access_token end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def filename @filename end |
#space_id ⇒ Object (readonly)
Returns the value of attribute space_id.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def space_id @space_id end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 15 def run if access_token.nil? puts 'Access Token not specified' puts 'Exiting!' exit end puts "Generating JSON Template '#{filename}' for Space: '#{space_id}'" json = Contentful::Bootstrap::Generator.new(space_id, access_token).generate_json puts write(json) end |
#write(json) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 30 def write(json) if filename.nil? puts "#{json}\n" else puts "Saving JSON template to '#{filename}'" ::File.write(filename, json) end end |