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.
-
#content_types_only ⇒ Object
readonly
Returns the value of attribute content_types_only.
-
#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, content_types_only = false) ⇒ GenerateJson
constructor
A new instance of GenerateJson.
- #run ⇒ Object
- #write(json) ⇒ Object
Constructor Details
#initialize(space_id, access_token, filename = nil, content_types_only = false) ⇒ GenerateJson
Returns a new instance of GenerateJson.
9 10 11 12 13 14 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 9 def initialize(space_id, access_token, filename = nil, content_types_only = false) @space_id = space_id @access_token = access_token @filename = filename @content_types_only = content_types_only 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 |
#content_types_only ⇒ Object (readonly)
Returns the value of attribute content_types_only.
8 9 10 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 8 def content_types_only @content_types_only 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 16 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, content_types_only).generate_json puts write(json) end |
#write(json) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/contentful/bootstrap/commands/generate_json.rb', line 31 def write(json) if filename.nil? puts "#{json}\n" else puts "Saving JSON template to '#{filename}'" ::File.write(filename, json) end end |